diff --git a/NEWS b/NEWS index 31294783..142ad742 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,7 @@ ncmpcpp-0.7 (????-??-??) * Monolithic 'press_space' action was split into 'add_item_to_playlist', 'toggle_lyrics_update_on_song_change' and 'toggle_visualization_type'. * Sorting actions were rebound to Ctrl-S. * Support for range selection was added (bound to Ctrl-V by default). In addition, sorting, reversing and shuffling items in playlist now works on ranges. +* Support for selecting found items was added (bound to Ctrl-_ by default). ncmpcpp-0.6.4 (2015-05-02) diff --git a/doc/bindings b/doc/bindings index 2c75e4bc..e540a69c 100644 --- a/doc/bindings +++ b/doc/bindings @@ -364,6 +364,9 @@ #def_key "ctrl_r" # reverse_playlist # +#def_key "ctrl__" +# select_found_items +# #def_key "/" # find # diff --git a/src/actions.cpp b/src/actions.cpp index 6c26f226..7decf335 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -1755,6 +1755,31 @@ void SelectAlbum::run() Statusbar::print("Album around cursor position selected"); } +bool SelectFoundItems::canBeRun() +{ + m_list = dynamic_cast(myScreen->activeWindow()); + if (m_list == nullptr || m_list->empty()) + return false; + m_searchable = dynamic_cast(myScreen); + return m_searchable != nullptr && m_searchable->allowsSearching(); +} + +void SelectFoundItems::run() +{ + auto current_pos = m_list->choice(); + myScreen->activeWindow()->scroll(NC::Scroll::Home); + bool found = m_searchable->find(SearchDirection::Forward, false, false); + if (found) + { + Statusbar::print("Searching for items..."); + m_list->currentP()->setSelected(true); + while (m_searchable->find(SearchDirection::Forward, false, true)) + m_list->currentP()->setSelected(true); + Statusbar::print("Found items selected"); + } + m_list->highlight(current_pos); +} + bool AddSelectedItems::canBeRun() { return myScreen != mySelectedItemsAdder; @@ -2617,6 +2642,7 @@ void populateActions() insert_action(new Actions::ReverseSelection()); insert_action(new Actions::RemoveSelection()); insert_action(new Actions::SelectAlbum()); + insert_action(new Actions::SelectFoundItems()); insert_action(new Actions::AddSelectedItems()); insert_action(new Actions::CropMainPlaylist()); insert_action(new Actions::CropPlaylist()); diff --git a/src/actions.h b/src/actions.h index 262a03f9..581e8feb 100644 --- a/src/actions.h +++ b/src/actions.h @@ -49,9 +49,9 @@ enum class Type SetCrossfade, SetVolume, EditSong, EditLibraryTag, EditLibraryAlbum, EditDirectoryName, EditPlaylistName, EditLyrics, JumpToBrowser, JumpToMediaLibrary, JumpToPlaylistEditor, ToggleScreenLock, JumpToTagEditor, JumpToPositionInSong, - SelectItem, SelectRange, ReverseSelection, RemoveSelection, SelectAlbum, AddSelectedItems, - CropMainPlaylist, CropPlaylist, ClearMainPlaylist, ClearPlaylist, SortPlaylist, - ReversePlaylist, Find, FindItemForward, FindItemBackward, + SelectItem, SelectRange, ReverseSelection, RemoveSelection, SelectAlbum, SelectFoundItems, + AddSelectedItems, CropMainPlaylist, CropPlaylist, ClearMainPlaylist, ClearPlaylist, + SortPlaylist, ReversePlaylist, Find, FindItemForward, FindItemBackward, NextFoundItem, PreviousFoundItem, ToggleFindMode, ToggleReplayGainMode, ToggleAddMode, ToggleMouse, ToggleBitrateVisibility, AddRandomItems, ToggleBrowserSortMode, ToggleLibraryTagType, @@ -827,6 +827,18 @@ private: SongList *m_songs; }; +struct SelectFoundItems: BaseAction +{ + SelectFoundItems(): BaseAction(Type::SelectFoundItems, "select_found_items") { } + +private: + virtual bool canBeRun() OVERRIDE; + virtual void run() OVERRIDE; + + NC::List *m_list; + Searchable *m_searchable; +}; + struct AddSelectedItems: BaseAction { AddSelectedItems(): BaseAction(Type::AddSelectedItems, "add_selected_items") { } diff --git a/src/bindings.cpp b/src/bindings.cpp index 71ee1d42..b5b71f17 100644 --- a/src/bindings.cpp +++ b/src/bindings.cpp @@ -597,6 +597,8 @@ void BindingsConfiguration::generateDefaults() } if (notBound(k = stringToKey("ctrl_r"))) bind(k, Actions::Type::ReversePlaylist); + if (notBound(k = stringToKey("ctrl__"))) + bind(k, Actions::Type::SelectFoundItems); if (notBound(k = stringToKey("/"))) { bind(k, Actions::Type::Find); diff --git a/src/help.cpp b/src/help.cpp index 98e40558..807fc580 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -182,6 +182,7 @@ void write_bindings(NC::Scrollpad &w) key(w, Type::ReverseSelection, "Reverse selection"); key(w, Type::RemoveSelection, "Remove selection"); key(w, Type::SelectItem, "Select current item"); + key(w, Type::SelectFoundItems, "Select found items"); key(w, Type::SelectAlbum, "Select songs of album around the cursor"); key(w, Type::AddSelectedItems, "Add selected items to playlist"); key(w, Type::AddRandomItems, "Add random items to playlist");