move selected items to actual cursor position, not to given one

this is much better as no position couting is needed.
This commit is contained in:
Andrzej Rybczak
2009-03-11 21:31:41 +01:00
parent fd7ac3b3f5
commit c0d227a0c8
2 changed files with 29 additions and 46 deletions

View File

@@ -197,7 +197,7 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.Crop) << "Clear playlist but hold currently playing/selected items\n"; *w << DisplayKeys(Key.Crop) << "Clear playlist but hold currently playing/selected items\n";
*w << DisplayKeys(Key.MvSongUp) << "Move item(s) up\n"; *w << DisplayKeys(Key.MvSongUp) << "Move item(s) up\n";
*w << DisplayKeys(Key.MvSongDown) << "Move item(s) down\n"; *w << DisplayKeys(Key.MvSongDown) << "Move item(s) down\n";
*w << DisplayKeys(Key.MoveTo) << "Move item(s) to given position\n"; *w << DisplayKeys(Key.MoveTo) << "Move selected item(s) to cursor position\n";
*w << DisplayKeys(Key.Add) << "Add url/file/directory to playlist\n"; *w << DisplayKeys(Key.Add) << "Add url/file/directory to playlist\n";
*w << DisplayKeys(Key.SavePlaylist) << "Save playlist\n"; *w << DisplayKeys(Key.SavePlaylist) << "Save playlist\n";
*w << DisplayKeys(Key.SortPlaylist) << "Sort playlist\n"; *w << DisplayKeys(Key.SortPlaylist) << "Sort playlist\n";

View File

@@ -835,57 +835,40 @@ int main(int argc, char *argv[])
ShowMessage("%s", MPD::Message::FunctionDisabledFilteringEnabled); ShowMessage("%s", MPD::Message::FunctionDisabledFilteringEnabled);
continue; continue;
} }
if (!myPlaylist->Main()->hasSelected())
LockStatusbar(); {
Statusbar() << "Move item(s) to given position: "; ShowMessage("No selected items to move!");
string strpos = wFooter->GetString(10);
UnlockStatusbar();
if (strpos.empty())
continue; continue;
}
int pos = StrToInt(strpos);
if (pos < 0)
continue;
Playlist::BlockUpdate = 1; Playlist::BlockUpdate = 1;
if (myPlaylist->Main()->hasSelected()) size_t pos = myPlaylist->Main()->Choice();
// if cursor is at the last item, break convention and move at the end of playlist
if (pos == myPlaylist->Main()->Size()-1)
pos++;
vector<size_t> list;
myPlaylist->Main()->GetSelected(list);
if (pos >= list.front() && pos <= list.back())
continue;
int diff = pos-list.front();
if (diff > 0)
{ {
vector<size_t> list; diff -= list.size();
myPlaylist->Main()->GetSelected(list); for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
if (pos+list.back()-list.front() > myPlaylist->Main()->Size())
pos = myPlaylist->Main()->Size()+list.front()-list.back()-1;
int diff = pos-list.front();
if (diff > 0)
{ {
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++) Mpd->QueueMove(*it, *it+diff);
{ myPlaylist->Main()->Move(*it, *it+diff);
Mpd->QueueMove(*it, *it+diff);
myPlaylist->Main()->Move(*it, *it+diff);
}
}
else if (diff < 0)
{
for (vector<size_t>::const_iterator it = list.begin(); it != list.end(); it++)
{
Mpd->QueueMove(*it, *it+diff);
myPlaylist->Main()->Move(*it, *it+diff);
}
}
myPlaylist->Main()->Highlight(list.front()+diff);
Mpd->CommitQueue();
}
else
{
int current_pos = myPlaylist->Main()->Choice();
int diff = pos-current_pos;
if (diff)
{
Mpd->Move(current_pos, current_pos+diff);
myPlaylist->Main()->Highlight(current_pos+diff);
} }
} }
else if (diff < 0)
{
for (vector<size_t>::const_iterator it = list.begin(); it != list.end(); it++)
{
Mpd->QueueMove(*it, *it+diff);
myPlaylist->Main()->Move(*it, *it+diff);
}
}
myPlaylist->Main()->Highlight(list.front()+diff);
Mpd->CommitQueue();
myPlaylist->FixPositions(); myPlaylist->FixPositions();
} }
else if (Keypressed(input, Key.Add)) else if (Keypressed(input, Key.Add))