From 6b5ed187a1d9ef8ab038898bbd0f6289890b85ba Mon Sep 17 00:00:00 2001 From: Frank Blendinger Date: Thu, 4 Mar 2010 15:10:58 +0100 Subject: [PATCH 1/2] add new movement keys: {Up,Down}{Album,Artist} --- doc/keys | 8 +++++ src/help.cpp | 4 +++ src/ncmpcpp.cpp | 45 +++++++++++++++++++++++ src/search_engine.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++ src/search_engine.h | 1 + src/settings.cpp | 16 +++++++++ src/settings.h | 4 +++ 7 files changed, 162 insertions(+) diff --git a/doc/keys b/doc/keys index 9550e6f8..46b283a9 100644 --- a/doc/keys +++ b/doc/keys @@ -16,6 +16,14 @@ # #key_down = 258 'j' # +#key_up_album = '[' +# +#key_down_album = ']' +# +#key_up_artist = '{' +# +#key_down_artist = '}' +# #key_page_up = 339 # #key_page_down = 338 diff --git a/src/help.cpp b/src/help.cpp index 0539a769..d166bd2e 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -133,6 +133,10 @@ void Help::GetKeybindings() *w << " " << fmtBold << "Keys - Movement\n -----------------------------------------\n" << fmtBoldEnd; *w << DisplayKeys(Key.Up) << "Move Cursor up\n"; *w << DisplayKeys(Key.Down) << "Move Cursor down\n"; + *w << DisplayKeys(Key.UpAlbum) << "Move Cursor up one album\n"; + *w << DisplayKeys(Key.DownAlbum) << "Move Cursor down one album\n"; + *w << DisplayKeys(Key.UpArtist) << "Move Cursor up one artist\n"; + *w << DisplayKeys(Key.DownArtist) << "Move Cursor down one artist\n"; *w << DisplayKeys(Key.PageUp) << "Page up\n"; *w << DisplayKeys(Key.PageDown) << "Page down\n"; *w << DisplayKeys(Key.Home) << "Home\n"; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index b21e4914..7ff4b35a 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -439,6 +439,51 @@ int main(int argc, char *argv[]) { myScreen->Scroll(wDown, Key.Down); } + else if (Keypressed(input, Key.UpAlbum) || Keypressed(input, Key.DownAlbum) + || Keypressed(input, Key.UpArtist) || Keypressed(input, Key.DownArtist)) + { + Menu *songs = NULL; + if (myScreen == myPlaylist && !myPlaylist->Items->Empty()) + songs = myPlaylist->Items; + else if (myScreen->ActiveWindow() == myPlaylistEditor->Content) + songs = myPlaylistEditor->Content; + else if (myScreen == mySearcher) + mySearcher->Scroll(input); + + if (songs && !songs->Empty()) + { + size_t pos = songs->Choice(); + if (Keypressed(input, Key.UpAlbum)) + { + std::string album = songs->at(pos).GetAlbum(); + while (pos > 0) + if (songs->at(--pos).GetAlbum() != album) + break; + } + else if (Keypressed(input, Key.DownAlbum)) + { + std::string album = songs->at(pos).GetAlbum(); + while (pos < songs->Size() - 1) + if (songs->at(++pos).GetAlbum() != album) + break; + } + else if (Keypressed(input, Key.UpArtist)) + { + std::string artist = songs->at(pos).GetArtist(); + while (pos > 0) + if (songs->at(--pos).GetArtist() != artist) + break; + } + else if (Keypressed(input, Key.DownArtist)) + { + std::string artist = songs->at(pos).GetArtist(); + while (pos < songs->Size() - 1) + if (songs->at(++pos).GetArtist() != artist) + break; + } + songs->Highlight(pos); + } + } else if (Keypressed(input, Key.PageUp)) { myScreen->Scroll(wPageUp, Key.PageUp); diff --git a/src/search_engine.cpp b/src/search_engine.cpp index fadad454..a409cdbe 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -264,6 +264,90 @@ void SearchEngine::UpdateFoundList() } } +void SearchEngine::Scroll(int input) +{ + size_t pos = w->Choice(); + size_t oldpos = pos; + //w->Goto(pos); + //w->Goto(pos2); + //std::string album = w->at(pos).second->GetAlbum(); + //ShowMessage("pos (choice): %i / pos2 (realchoice): %i / album: %s", pos, pos2, album.c_str()); + //return; + + // above the reset button + if (pos < StaticOptions - 4) + { + if (Keypressed(input, Key.UpAlbum) || + Keypressed(input, Key.UpArtist)) + w->Highlight(0); + else if (Keypressed(input, Key.DownAlbum) || + Keypressed(input, Key.DownArtist)) + w->Highlight(StaticOptions - 4); // reset + return; + } + + // reset button + if (pos == StaticOptions - 4) + { + if (Keypressed(input, Key.UpAlbum) || + Keypressed(input, Key.UpArtist)) + w->Highlight(0); + else if (Keypressed(input, Key.DownAlbum) || + Keypressed(input, Key.DownArtist)) + w->Highlight(StaticOptions); // first search result + return; + } + + // first search result + if (pos == StaticOptions) + { + if (Keypressed(input, Key.UpAlbum)) + { + w->Highlight(StaticOptions - 4); // reset + return; + } + else if (Keypressed(input, Key.UpArtist)) + { + w->Highlight(0); + return; + } + } + + // we are in the search results at this point + if (pos >= StaticOptions) + { + if (Keypressed(input, Key.UpAlbum)) + { + std::string album = w->at(pos).second->GetAlbum(); + while (pos > StaticOptions) + if (w->at(--pos).second->GetAlbum() != album) + break; + } + else if (Keypressed(input, Key.DownAlbum)) + { + std::string album = w->at(pos).second->GetAlbum(); + while (pos < w->Size() - 1) + if (w->at(++pos).second->GetAlbum() != album) + break; + } + else if (Keypressed(input, Key.UpArtist)) + { + std::string artist = w->at(pos).second->GetArtist(); + while (pos > StaticOptions) + if (w->at(--pos).second->GetArtist() != artist) + break; + } + else if (Keypressed(input, Key.DownArtist)) + { + std::string artist = w->at(pos).second->GetArtist(); + while (pos < w->Size() - 1) + if (w->at(++pos).second->GetArtist() != artist) + break; + } + w->Highlight(pos); + } +} + void SearchEngine::Prepare() { for (size_t i = 0; i < w->Size(); ++i) diff --git a/src/search_engine.h b/src/search_engine.h index a40cf373..284b3e5a 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -48,6 +48,7 @@ class SearchEngine : public Screen< Menu< std::pair > > virtual List *GetList() { return w->Size() >= StaticOptions ? w : 0; } void UpdateFoundList(); + void Scroll(int); static size_t StaticOptions; static size_t SearchButton; diff --git a/src/settings.cpp b/src/settings.cpp index 9845b1fd..9a78613c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -150,6 +150,10 @@ void NcmpcppKeys::SetDefaults() { Up[0] = KEY_UP; Down[0] = KEY_DOWN; + UpAlbum[0] = '['; + DownAlbum[0] = ']'; + UpArtist[0] = '{'; + DownArtist[0] = '}'; PageUp[0] = KEY_PPAGE; PageDown[0] = KEY_NPAGE; Home[0] = KEY_HOME; @@ -224,6 +228,10 @@ void NcmpcppKeys::SetDefaults() Up[1] = 'k'; Down[1] = 'j'; + UpAlbum[1] = null_key; + DownAlbum[1] = null_key; + UpArtist[1] = null_key; + DownArtist[1] = null_key; PageUp[1] = null_key; PageDown[1] = null_key; Home[1] = null_key; @@ -418,6 +426,14 @@ void NcmpcppKeys::Read() GetKeys(key, Up); else if (key.find("key_down ") != std::string::npos) GetKeys(key, Down); + else if (key.find("key_up_album ") != std::string::npos) + GetKeys(key, UpAlbum); + else if (key.find("key_down_album ") != std::string::npos) + GetKeys(key, DownAlbum); + else if (key.find("key_up_artist ") != std::string::npos) + GetKeys(key, UpArtist); + else if (key.find("key_down_artist ") != std::string::npos) + GetKeys(key, DownArtist); else if (key.find("key_page_up ") != std::string::npos) GetKeys(key, PageUp); else if (key.find("key_page_down ") != std::string::npos) diff --git a/src/settings.h b/src/settings.h index ac5c96bd..491c298c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -59,6 +59,10 @@ struct NcmpcppKeys int Up[2]; int Down[2]; + int UpAlbum[2]; + int DownAlbum[2]; + int UpArtist[2]; + int DownArtist[2]; int PageUp[2]; int PageDown[2]; int Home[2]; From d139f2d8afc8e032d6646186d1bd27963e33ac7a Mon Sep 17 00:00:00 2001 From: Frank Blendinger Date: Thu, 4 Mar 2010 15:13:11 +0100 Subject: [PATCH 2/2] jump from browser to playlist editor with GoToContainingDir key --- src/help.cpp | 1 + src/ncmpcpp.cpp | 14 +++++++++++--- src/playlist_editor.cpp | 14 ++++++++++++++ src/playlist_editor.h | 2 ++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/help.cpp b/src/help.cpp index d166bd2e..6aeacdff 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -249,6 +249,7 @@ void Help::GetKeybindings() *w << DisplayKeys(Key.GoToNowPlaying) << "Locate currently playing song\n"; *w << DisplayKeys(Key.GoToParentDir) << "Go to parent directory\n"; *w << DisplayKeys(Key.Delete) << "Delete playlist/file/directory\n"; + *w << DisplayKeys(Key.GoToContainingDir) << "Jump to playlist editor (playlists only)\n"; *w << "\n\n " << fmtBold << "Keys - Search engine\n -----------------------------------------\n" << fmtBoldEnd; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 7ff4b35a..8eb1dc4f 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1588,9 +1588,17 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.GoToContainingDir)) { - Song *s = myScreen->CurrentSong(); - if (s) - myBrowser->LocateSong(*s); + if (myScreen == myBrowser && myBrowser->Main()->Current().type == itPlaylist) + { + const std::string pl_name = myBrowser->Main()->Current().name; + myPlaylistEditor->JumpTo(pl_name); + } + else + { + Song *s = myScreen->CurrentSong(); + if (s) + myBrowser->LocateSong(*s); + } } else if (Keypressed(input, Key.GoToMediaLibrary)) { diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 2554cb60..df186486 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -289,6 +289,20 @@ void PlaylistEditor::ApplyFilter(const std::string &s) GetList()->ApplyFilter(s, 0, REG_ICASE | Config.regex_type); } +void PlaylistEditor::JumpTo(const std::string &s) +{ + SwitchTo(); + for (size_t i = 0; i < Playlists->Size(); ++i) + { + if (s == (*Playlists)[i]) + { + Playlists->Highlight(i); + Content->Clear(); + break; + } + } +} + List *PlaylistEditor::GetList() { if (w == Playlists) diff --git a/src/playlist_editor.h b/src/playlist_editor.h index baadecb1..48bd9809 100644 --- a/src/playlist_editor.h +++ b/src/playlist_editor.h @@ -46,6 +46,8 @@ class PlaylistEditor : public Screen virtual void GetSelectedSongs(MPD::SongList &); virtual void ApplyFilter(const std::string &); + + virtual void JumpTo(const std::string &); virtual List *GetList();