diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2015-05-24 17:04:21 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2015-05-24 17:04:21 +0200 |
commit | a5867405d212ffbb7c0c1d67f6eaa5d093034d79 (patch) | |
tree | 16426c921c1b0f041f49cbeae52247d222aa59f4 /src | |
parent | 1b6cb65f3a371e40794e92176f013b1a720432e1 (diff) |
actions: add support for selecting found items
Diffstat (limited to 'src')
-rw-r--r-- | src/actions.cpp | 26 | ||||
-rw-r--r-- | src/actions.h | 18 | ||||
-rw-r--r-- | src/bindings.cpp | 2 | ||||
-rw-r--r-- | src/help.cpp | 1 |
4 files changed, 44 insertions, 3 deletions
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<NC::List *>(myScreen->activeWindow()); + if (m_list == nullptr || m_list->empty()) + return false; + m_searchable = dynamic_cast<Searchable *>(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"); |