Skip to content

Commit

Permalink
add separate keys to move sel. before/after cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
yogan committed Jul 14, 2010
1 parent 883d1a6 commit 890cbb2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions doc/keys
Expand Up @@ -146,6 +146,10 @@
#
#key_move_to = 'M'
#
#key_move_before = 0
#
#key_move_after = 0
#
#key_add = 'a'
#
#key_save_playlist = 'S'
Expand Down
2 changes: 2 additions & 0 deletions src/help.cpp
Expand Up @@ -231,6 +231,8 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.MvSongUp) << "Move item(s) up\n";
*w << DisplayKeys(Key.MvSongDown) << "Move item(s) down\n";
*w << DisplayKeys(Key.MoveTo) << "Move selected item(s) to cursor position\n";
*w << DisplayKeys(Key.MoveBefore) << "Move selected item(s) before cursor position\n";
*w << DisplayKeys(Key.MoveAfter) << "Move selected item(s) after cursor position\n";
*w << DisplayKeys(Key.Add) << "Add url/file/directory to playlist\n";
# ifdef HAVE_TAGLIB_H
*w << DisplayKeys(Key.EditTags) << "Edit song's tags\n";
Expand Down
14 changes: 10 additions & 4 deletions src/ncmpcpp.cpp
Expand Up @@ -1137,7 +1137,8 @@ int main(int argc, char *argv[])
wFooter->SetTimeout(ncmpcpp_window_timeout);
}
}
else if (Keypressed(input, Key.MoveTo) && myScreen == myPlaylist)
else if ((Keypressed(input, Key.MoveTo) || Keypressed(input, Key.MoveBefore)
|| Keypressed(input, Key.MoveAfter)) && myScreen == myPlaylist)
{
CHECK_PLAYLIST_FOR_FILTERING;
if (!myPlaylist->Items->hasSelected())
Expand All @@ -1147,13 +1148,18 @@ int main(int argc, char *argv[])
}
Playlist::BlockUpdate = 1;
size_t pos = myPlaylist->Items->Choice();
// if cursor is at the last item, break convention and move at the end of playlist
if (pos == myPlaylist->Items->Size()-1)
pos++;
std::vector<size_t> list;
myPlaylist->Items->GetSelected(list);
if (pos >= list.front() && pos <= list.back())
continue;
if (Keypressed(input, Key.MoveTo))
{
// if cursor is at the last item, break convention and move at the end of playlist
if (pos == myPlaylist->Items->Size()-1)
pos++;
}
else if (Keypressed(input, Key.MoveAfter))
pos++;
int diff = pos-list.front();
Mpd.StartCommandsList();
if (diff > 0)
Expand Down
8 changes: 8 additions & 0 deletions src/settings.cpp
Expand Up @@ -220,6 +220,8 @@ void NcmpcppKeys::SetDefaults()
MvSongUp[0] = 'm';
MvSongDown[0] = 'n';
MoveTo[0] = 'M';
MoveBefore[0] = NullKey;
MoveAfter[0] = NullKey;
Add[0] = 'a';
SavePlaylist[0] = 'S';
GoToNowPlaying[0] = 'o';
Expand Down Expand Up @@ -302,6 +304,8 @@ void NcmpcppKeys::SetDefaults()
MvSongUp[1] = NullKey;
MvSongDown[1] = NullKey;
MoveTo[1] = NullKey;
MoveBefore[1] = NullKey;
MoveAfter[1] = NullKey;
Add[1] = NullKey;
SavePlaylist[1] = NullKey;
GoToNowPlaying[1] = NullKey;
Expand Down Expand Up @@ -571,6 +575,10 @@ void NcmpcppKeys::Read()
GetKeys(key, MvSongDown);
else if (key.find("key_move_to ") != std::string::npos)
GetKeys(key, MoveTo);
else if (key.find("key_move_before ") != std::string::npos)
GetKeys(key, MoveBefore);
else if (key.find("key_move_after ") != std::string::npos)
GetKeys(key, MoveAfter);
else if (key.find("key_add ") != std::string::npos)
GetKeys(key, Add);
else if (key.find("key_save_playlist ") != std::string::npos)
Expand Down
2 changes: 2 additions & 0 deletions src/settings.h
Expand Up @@ -125,6 +125,8 @@ struct NcmpcppKeys
int MvSongUp[2];
int MvSongDown[2];
int MoveTo[2];
int MoveBefore[2];
int MoveAfter[2];
int Add[2];
int SavePlaylist[2];
int GoToNowPlaying[2];
Expand Down

0 comments on commit 890cbb2

Please sign in to comment.