From 9b6a080a2970957bb1b5528a0f39505c0c4a575d Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 13 Nov 2016 06:18:39 +0100 Subject: [PATCH] Move filtering methods to separate interface --- src/actions.cpp | 13 +++++++------ src/actions.h | 2 +- src/browser.cpp | 7 +++++++ src/browser.h | 4 +++- src/interfaces.h | 8 ++++++-- src/media_library.cpp | 7 +++++++ src/media_library.h | 4 +++- src/playlist.cpp | 7 +++++++ src/playlist.h | 4 +++- src/playlist_editor.cpp | 7 +++++++ src/playlist_editor.h | 4 +++- src/search_engine.cpp | 7 +++++++ src/search_engine.h | 4 +++- src/sel_items_adder.h | 2 +- src/statusbar.cpp | 2 +- src/statusbar.h | 4 ++-- src/tiny_tag_editor.h | 2 +- 17 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 1e0ca3d0..dea77ad3 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -1958,18 +1958,19 @@ void ReversePlaylist::run() bool ApplyFilter::canBeRun() { - m_searchable = dynamic_cast(myScreen); - return m_searchable != nullptr; + m_filterable = dynamic_cast(myScreen); + return m_filterable != nullptr + && m_filterable->allowsFiltering(); } void ApplyFilter::run() { using Global::wFooter; - std::string filter = m_searchable->currentFilter(); + std::string filter = m_filterable->currentFilter(); if (!filter.empty()) { - m_searchable->applyFilter(filter); + m_filterable->applyFilter(filter); myScreen->refreshWindow(); } @@ -1978,13 +1979,13 @@ void ApplyFilter::run() Statusbar::ScopedLock slock; NC::Window::ScopedPromptHook helper( *wFooter, - Statusbar::Helpers::ApplyFilterImmediately(m_searchable)); + Statusbar::Helpers::ApplyFilterImmediately(m_filterable)); Statusbar::put() << "Apply filter: "; filter = wFooter->prompt(filter); } catch (NC::PromptAborted &) { - m_searchable->applyFilter(filter); + m_filterable->applyFilter(filter); throw; } diff --git a/src/actions.h b/src/actions.h index fb94bdfb..671aa0ee 100644 --- a/src/actions.h +++ b/src/actions.h @@ -1045,7 +1045,7 @@ private: virtual bool canBeRun() OVERRIDE; virtual void run() OVERRIDE; - Searchable *m_searchable; + Filterable *m_filterable; }; struct Find: BaseAction diff --git a/src/browser.cpp b/src/browser.cpp index 9fc3beb4..8dd2aff2 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -267,6 +267,13 @@ bool Browser::search(SearchDirection direction, bool wrap, bool skip_current) return ::search(w, m_search_predicate, direction, wrap, skip_current); } +/***********************************************************************/ + +bool Browser::allowsFiltering() +{ + return allowsSearching(); +} + std::string Browser::currentFilter() { std::string result; diff --git a/src/browser.h b/src/browser.h index 3c575722..62e45fbe 100644 --- a/src/browser.h +++ b/src/browser.h @@ -43,7 +43,7 @@ struct BrowserWindow: NC::Menu, SongList virtual std::vector getSelectedSongs() OVERRIDE; }; -struct Browser: Screen, HasSongs, Searchable, Tabbable +struct Browser: Screen, Filterable, HasSongs, Searchable, Tabbable { Browser(); @@ -68,6 +68,8 @@ struct Browser: Screen, HasSongs, Searchable, Tabbable virtual void clearSearchConstraint() OVERRIDE; virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; + // Filterable implemenetation + virtual bool allowsFiltering() OVERRIDE; virtual std::string currentFilter() OVERRIDE; virtual void applyFilter(const std::string &filter) OVERRIDE; diff --git a/src/interfaces.h b/src/interfaces.h index 6ac27063..6eee13bd 100644 --- a/src/interfaces.h +++ b/src/interfaces.h @@ -37,9 +37,13 @@ struct Searchable virtual void setSearchConstraint(const std::string &constraint) = 0; virtual void clearSearchConstraint() = 0; virtual bool search(SearchDirection direction, bool wrap, bool skip_current) = 0; +}; - virtual std::string currentFilter() { return ""; } - virtual void applyFilter(const std::string &) { } +struct Filterable +{ + virtual bool allowsFiltering() = 0; + virtual std::string currentFilter() = 0; + virtual void applyFilter(const std::string &constraint) = 0; }; struct HasActions diff --git a/src/media_library.cpp b/src/media_library.cpp index 64b811eb..bd82a85d 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -604,6 +604,13 @@ bool MediaLibrary::search(SearchDirection direction, bool wrap, bool skip_curren return result; } +/***********************************************************************/ + +bool MediaLibrary::allowsFiltering() +{ + return allowsSearching(); +} + std::string MediaLibrary::currentFilter() { std::string result; diff --git a/src/media_library.h b/src/media_library.h index 0218488d..da47f127 100644 --- a/src/media_library.h +++ b/src/media_library.h @@ -28,7 +28,7 @@ #include "screen.h" #include "song_list.h" -struct MediaLibrary: Screen, HasColumns, HasSongs, Searchable, Tabbable +struct MediaLibrary: Screen, Filterable, HasColumns, HasSongs, Searchable, Tabbable { MediaLibrary(); @@ -55,6 +55,8 @@ struct MediaLibrary: Screen, HasColumns, HasSongs, Searchable, Tab virtual void clearSearchConstraint() OVERRIDE; virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; + // Filterable implementation + virtual bool allowsFiltering() OVERRIDE; virtual std::string currentFilter() OVERRIDE; virtual void applyFilter(const std::string &filter) OVERRIDE; diff --git a/src/playlist.cpp b/src/playlist.cpp index 1f182c85..f3d7f4b8 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -176,6 +176,13 @@ bool Playlist::search(SearchDirection direction, bool wrap, bool skip_current) return ::search(w, m_search_predicate, direction, wrap, skip_current); } +/***********************************************************************/ + +bool Playlist::allowsFiltering() +{ + return allowsSearching(); +} + std::string Playlist::currentFilter() { std::string result; diff --git a/src/playlist.h b/src/playlist.h index 6810d2f5..329007bd 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -30,7 +30,7 @@ #include "song.h" #include "song_list.h" -struct Playlist: Screen, HasSongs, Searchable, Tabbable +struct Playlist: Screen, Filterable, HasSongs, Searchable, Tabbable { Playlist(); @@ -55,6 +55,8 @@ struct Playlist: Screen, HasSongs, Searchable, Tabbable virtual void clearSearchConstraint() OVERRIDE; virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; + // Filterable implementation + virtual bool allowsFiltering() OVERRIDE; virtual std::string currentFilter() OVERRIDE; virtual void applyFilter(const std::string &filter) OVERRIDE; diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 0008d9c8..611a70cd 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -318,6 +318,13 @@ bool PlaylistEditor::search(SearchDirection direction, bool wrap, bool skip_curr return result; } +/***********************************************************************/ + +bool PlaylistEditor::allowsFiltering() +{ + return allowsSearching(); +} + std::string PlaylistEditor::currentFilter() { std::string result; diff --git a/src/playlist_editor.h b/src/playlist_editor.h index d710a6d0..f9268a65 100644 --- a/src/playlist_editor.h +++ b/src/playlist_editor.h @@ -28,7 +28,7 @@ #include "screen.h" #include "song_list.h" -struct PlaylistEditor: Screen, HasColumns, HasSongs, Searchable, Tabbable +struct PlaylistEditor: Screen, Filterable, HasColumns, HasSongs, Searchable, Tabbable { PlaylistEditor(); @@ -55,6 +55,8 @@ struct PlaylistEditor: Screen, HasColumns, HasSongs, Searchable, T virtual void clearSearchConstraint() OVERRIDE; virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; + // Filterable implementation + virtual bool allowsFiltering() OVERRIDE; virtual std::string currentFilter() OVERRIDE; virtual void applyFilter(const std::string &filter) OVERRIDE; diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 2acd41a0..ed4fd534 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -269,6 +269,13 @@ bool SearchEngine::search(SearchDirection direction, bool wrap, bool skip_curren return ::search(w, m_search_predicate, direction, wrap, skip_current); } +/***********************************************************************/ + +bool SearchEngine::allowsFiltering() +{ + return allowsSearching(); +} + std::string SearchEngine::currentFilter() { std::string result; diff --git a/src/search_engine.h b/src/search_engine.h index b3e7b8b7..b260d826 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -91,7 +91,7 @@ struct SearchEngineWindow: NC::Menu, SongList virtual std::vector getSelectedSongs() OVERRIDE; }; -struct SearchEngine: Screen, HasActions, HasSongs, Searchable, Tabbable +struct SearchEngine: Screen, Filterable, HasActions, HasSongs, Searchable, Tabbable { SearchEngine(); @@ -116,6 +116,8 @@ struct SearchEngine: Screen, HasActions, HasSongs, Searchabl virtual void clearSearchConstraint() OVERRIDE; virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; + // Filterable implementation + virtual bool allowsFiltering() OVERRIDE; virtual std::string currentFilter() OVERRIDE; virtual void applyFilter(const std::string &filter) OVERRIDE; diff --git a/src/sel_items_adder.h b/src/sel_items_adder.h index dc67b097..6dc991b9 100644 --- a/src/sel_items_adder.h +++ b/src/sel_items_adder.h @@ -49,7 +49,7 @@ struct SelectedItemsAdder: Screen> *> virtual bool isLockable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return false; } - // HasActions implemenetation + // HasActions implementation virtual bool actionRunnable() OVERRIDE; virtual void runAction() OVERRIDE; diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 4703d47c..f3b1d01d 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -225,7 +225,7 @@ bool Statusbar::Helpers::ApplyFilterImmediately::operator()(const char *s) using Global::myScreen; Status::trace(); try { - if (m_w->allowsSearching() && m_w->currentFilter() != s) + if (m_w->allowsFiltering() && m_w->currentFilter() != s) { m_w->applyFilter(s); if (myScreen == myPlaylist) diff --git a/src/statusbar.h b/src/statusbar.h index 25801c00..8375e7e7 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -91,14 +91,14 @@ private: struct ApplyFilterImmediately { - ApplyFilterImmediately(Searchable *w) + ApplyFilterImmediately(Filterable *w) : m_w(w) { } bool operator()(const char *s); private: - Searchable *m_w; + Filterable *m_w; }; struct FindImmediately diff --git a/src/tiny_tag_editor.h b/src/tiny_tag_editor.h index 3e85eb70..afed4586 100644 --- a/src/tiny_tag_editor.h +++ b/src/tiny_tag_editor.h @@ -47,7 +47,7 @@ struct TinyTagEditor: Screen>, HasActions virtual bool isLockable() OVERRIDE { return false; } virtual bool isMergable() OVERRIDE { return true; } - // HasActions implemenetation + // HasActions implementation virtual bool actionRunnable() OVERRIDE; virtual void runAction() OVERRIDE;