diff options
-rw-r--r-- | src/actions.cpp | 3 | ||||
-rw-r--r-- | src/browser.cpp | 28 | ||||
-rw-r--r-- | src/browser.h | 5 | ||||
-rw-r--r-- | src/helpers.cpp | 11 | ||||
-rw-r--r-- | src/helpers.h | 18 | ||||
-rw-r--r-- | src/menu_impl.h | 6 | ||||
-rw-r--r-- | src/playlist.h | 2 | ||||
-rw-r--r-- | src/search_engine.cpp | 22 | ||||
-rw-r--r-- | src/search_engine.h | 3 | ||||
-rw-r--r-- | src/song_list.h | 2 |
10 files changed, 79 insertions, 21 deletions
diff --git a/src/actions.cpp b/src/actions.cpp index 950c314d..26c634b0 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -1947,8 +1947,7 @@ void ReversePlaylist::run() bool ApplyFilter::canBeRun() { m_searchable = dynamic_cast<Searchable *>(myScreen); - return m_searchable != nullptr - && myScreen == myPlaylist; + return m_searchable != nullptr; } void ApplyFilter::run() diff --git a/src/browser.cpp b/src/browser.cpp index 416ed8a0..85f60e53 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -267,6 +267,28 @@ bool Browser::search(SearchDirection direction, bool wrap, bool skip_current) return ::search(w, m_search_predicate, direction, wrap, skip_current); } +std::string Browser::currentFilter() +{ + std::string result; + if (auto pred = w.filterPredicate<Regex::Filter<MPD::Item>>()) + result = pred->constraint(); + return result; +} + +void Browser::applyFilter(const std::string &constraint) +{ + if (!constraint.empty()) + { + w.applyFilter(Regex::Filter<MPD::Item>( + constraint, + Config.regex_type, + std::bind(browserEntryMatcher, ph::_1, ph::_2, true))); + } + else + w.clearFilter(); +} + + /***********************************************************************/ bool Browser::itemAvailable() @@ -399,7 +421,9 @@ void Browser::locateSong(const MPD::Song &s) if (myScreen != this) switchTo(); - + + w.clearFilter(); + // change to relevant directory if (m_current_directory != s.getDirectory()) { @@ -432,6 +456,8 @@ bool Browser::enterDirectory() void Browser::getDirectory(std::string directory) { + ScopedUnfilteredMenu<MPD::Item, ReapplyFilter::Yes> sunfilter(w); + m_scroll_beginning = 0; w.clear(); diff --git a/src/browser.h b/src/browser.h index f5b912d3..3c575722 100644 --- a/src/browser.h +++ b/src/browser.h @@ -67,7 +67,10 @@ struct Browser: Screen<BrowserWindow>, HasSongs, Searchable, Tabbable virtual void setSearchConstraint(const std::string &constraint) OVERRIDE; virtual void clearSearchConstraint() OVERRIDE; virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; - + + virtual std::string currentFilter() OVERRIDE; + virtual void applyFilter(const std::string &filter) OVERRIDE; + // HasSongs implementation virtual bool itemAvailable() OVERRIDE; virtual bool addItemToPlaylist(bool play) OVERRIDE; diff --git a/src/helpers.cpp b/src/helpers.cpp index 3b93bbe4..450eb268 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -172,17 +172,6 @@ std::string Timestamp(time_t t) return result; } -void markSongsInPlaylist(SongList &list) -{ - MPD::Song *s; - for (auto &p : list) - { - s = p.get<Bit::Song>(); - if (s != nullptr) - p.get<Bit::Properties>().setBold(myPlaylist->checkForSong(*s)); - } -} - std::wstring Scroller(const std::wstring &str, size_t &pos, size_t width) { std::wstring s(str); diff --git a/src/helpers.h b/src/helpers.h index a9801cb7..46c5d791 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -23,6 +23,7 @@ #include "interfaces.h" #include "mpdpp.h" +#include "playlist.h" #include "screen.h" #include "settings.h" #include "song_list.h" @@ -371,6 +372,21 @@ template <typename Iterator> std::string getSharedDirectory(Iterator first, Iter return result; } +template <typename ListT> +void markSongsInPlaylist(ListT &list) +{ + ScopedUnfilteredMenu< + typename ListT::Item::Type, + ReapplyFilter::No> sunfilter(list); + MPD::Song *s; + for (auto &p : static_cast<SongList &>(list)) + { + s = p.get<Bit::Song>(); + if (s != nullptr) + p.get<Bit::Properties>().setBold(myPlaylist->checkForSong(*s)); + } +} + template <typename T> void ShowTime(T &buf, size_t length, bool short_names) { const unsigned MINUTE = 60; @@ -442,8 +458,6 @@ std::string timeFormat(const char *format, time_t t); std::string Timestamp(time_t t); -void markSongsInPlaylist(SongList &list); - std::wstring Scroller(const std::wstring &str, size_t &pos, size_t width); void writeCyclicBuffer(const NC::WBuffer &buf, NC::Window &w, size_t &start_pos, size_t width, const std::wstring &separator); diff --git a/src/menu_impl.h b/src/menu_impl.h index 1d562f92..bec25230 100644 --- a/src/menu_impl.h +++ b/src/menu_impl.h @@ -336,8 +336,10 @@ void Menu<ItemT>::reset() template <typename ItemT> void Menu<ItemT>::clear() { - clearFilter(); - m_items->clear(); + // Don't clear the filter here. + m_all_items.clear(); + m_filtered_items.clear(); + m_items = &m_all_items; } template <typename ItemT> diff --git a/src/playlist.h b/src/playlist.h index dcf398d2..585e6441 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -72,7 +72,7 @@ struct Playlist: Screen<SongMenu>, HasSongs, Searchable, Tabbable void enableHighlighting(); void setSelectedItemsPriority(int prio); - + bool checkForSong(const MPD::Song &s); void registerSong(const MPD::Song &s); void unregisterSong(const MPD::Song &s); diff --git a/src/search_engine.cpp b/src/search_engine.cpp index ee8ad186..2acd41a0 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -269,6 +269,27 @@ bool SearchEngine::search(SearchDirection direction, bool wrap, bool skip_curren return ::search(w, m_search_predicate, direction, wrap, skip_current); } +std::string SearchEngine::currentFilter() +{ + std::string result; + if (auto pred = w.filterPredicate<Regex::ItemFilter<SEItem>>()) + result = pred->constraint(); + return result; +} + +void SearchEngine::applyFilter(const std::string &constraint) +{ + if (!constraint.empty()) + { + w.applyFilter(Regex::ItemFilter<SEItem>( + constraint, + Config.regex_type, + std::bind(SEItemEntryMatcher, ph::_1, ph::_2, true))); + } + else + w.clearFilter(); +} + /***********************************************************************/ bool SearchEngine::actionRunnable() @@ -306,6 +327,7 @@ void SearchEngine::runAction() } else if (option == SearchButton) { + w.clearFilter(); Statusbar::print("Searching..."); if (w.size() > StaticOptions) Prepare(); diff --git a/src/search_engine.h b/src/search_engine.h index c90484cd..b3e7b8b7 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -116,6 +116,9 @@ struct SearchEngine: Screen<SearchEngineWindow>, HasActions, HasSongs, Searchabl virtual void clearSearchConstraint() OVERRIDE; virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; + virtual std::string currentFilter() OVERRIDE; + virtual void applyFilter(const std::string &filter) OVERRIDE; + // HasActions implementation virtual bool actionRunnable() OVERRIDE; virtual void runAction() OVERRIDE; diff --git a/src/song_list.h b/src/song_list.h index 17c67dec..42cb144f 100644 --- a/src/song_list.h +++ b/src/song_list.h @@ -75,4 +75,4 @@ struct SongMenu: NC::Menu<MPD::Song>, SongList virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE; }; -#endif // NCMPCPP_SONG_LIST_H
\ No newline at end of file +#endif // NCMPCPP_SONG_LIST_H |