Move filtering methods to separate interface
This commit is contained in:
@@ -1958,18 +1958,19 @@ void ReversePlaylist::run()
|
|||||||
|
|
||||||
bool ApplyFilter::canBeRun()
|
bool ApplyFilter::canBeRun()
|
||||||
{
|
{
|
||||||
m_searchable = dynamic_cast<Searchable *>(myScreen);
|
m_filterable = dynamic_cast<Filterable *>(myScreen);
|
||||||
return m_searchable != nullptr;
|
return m_filterable != nullptr
|
||||||
|
&& m_filterable->allowsFiltering();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyFilter::run()
|
void ApplyFilter::run()
|
||||||
{
|
{
|
||||||
using Global::wFooter;
|
using Global::wFooter;
|
||||||
|
|
||||||
std::string filter = m_searchable->currentFilter();
|
std::string filter = m_filterable->currentFilter();
|
||||||
if (!filter.empty())
|
if (!filter.empty())
|
||||||
{
|
{
|
||||||
m_searchable->applyFilter(filter);
|
m_filterable->applyFilter(filter);
|
||||||
myScreen->refreshWindow();
|
myScreen->refreshWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1978,13 +1979,13 @@ void ApplyFilter::run()
|
|||||||
Statusbar::ScopedLock slock;
|
Statusbar::ScopedLock slock;
|
||||||
NC::Window::ScopedPromptHook helper(
|
NC::Window::ScopedPromptHook helper(
|
||||||
*wFooter,
|
*wFooter,
|
||||||
Statusbar::Helpers::ApplyFilterImmediately(m_searchable));
|
Statusbar::Helpers::ApplyFilterImmediately(m_filterable));
|
||||||
Statusbar::put() << "Apply filter: ";
|
Statusbar::put() << "Apply filter: ";
|
||||||
filter = wFooter->prompt(filter);
|
filter = wFooter->prompt(filter);
|
||||||
}
|
}
|
||||||
catch (NC::PromptAborted &)
|
catch (NC::PromptAborted &)
|
||||||
{
|
{
|
||||||
m_searchable->applyFilter(filter);
|
m_filterable->applyFilter(filter);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1045,7 +1045,7 @@ private:
|
|||||||
virtual bool canBeRun() OVERRIDE;
|
virtual bool canBeRun() OVERRIDE;
|
||||||
virtual void run() OVERRIDE;
|
virtual void run() OVERRIDE;
|
||||||
|
|
||||||
Searchable *m_searchable;
|
Filterable *m_filterable;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Find: BaseAction
|
struct Find: BaseAction
|
||||||
|
|||||||
@@ -267,6 +267,13 @@ bool Browser::search(SearchDirection direction, bool wrap, bool skip_current)
|
|||||||
return ::search(w, m_search_predicate, direction, wrap, skip_current);
|
return ::search(w, m_search_predicate, direction, wrap, skip_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
|
||||||
|
bool Browser::allowsFiltering()
|
||||||
|
{
|
||||||
|
return allowsSearching();
|
||||||
|
}
|
||||||
|
|
||||||
std::string Browser::currentFilter()
|
std::string Browser::currentFilter()
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ struct BrowserWindow: NC::Menu<MPD::Item>, SongList
|
|||||||
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
|
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Browser: Screen<BrowserWindow>, HasSongs, Searchable, Tabbable
|
struct Browser: Screen<BrowserWindow>, Filterable, HasSongs, Searchable, Tabbable
|
||||||
{
|
{
|
||||||
Browser();
|
Browser();
|
||||||
|
|
||||||
@@ -68,6 +68,8 @@ struct Browser: Screen<BrowserWindow>, HasSongs, Searchable, Tabbable
|
|||||||
virtual void clearSearchConstraint() OVERRIDE;
|
virtual void clearSearchConstraint() OVERRIDE;
|
||||||
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
||||||
|
|
||||||
|
// Filterable implemenetation
|
||||||
|
virtual bool allowsFiltering() OVERRIDE;
|
||||||
virtual std::string currentFilter() OVERRIDE;
|
virtual std::string currentFilter() OVERRIDE;
|
||||||
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,13 @@ struct Searchable
|
|||||||
virtual void setSearchConstraint(const std::string &constraint) = 0;
|
virtual void setSearchConstraint(const std::string &constraint) = 0;
|
||||||
virtual void clearSearchConstraint() = 0;
|
virtual void clearSearchConstraint() = 0;
|
||||||
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) = 0;
|
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
virtual std::string currentFilter() { return ""; }
|
struct Filterable
|
||||||
virtual void applyFilter(const std::string &) { }
|
{
|
||||||
|
virtual bool allowsFiltering() = 0;
|
||||||
|
virtual std::string currentFilter() = 0;
|
||||||
|
virtual void applyFilter(const std::string &constraint) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HasActions
|
struct HasActions
|
||||||
|
|||||||
@@ -604,6 +604,13 @@ bool MediaLibrary::search(SearchDirection direction, bool wrap, bool skip_curren
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
|
||||||
|
bool MediaLibrary::allowsFiltering()
|
||||||
|
{
|
||||||
|
return allowsSearching();
|
||||||
|
}
|
||||||
|
|
||||||
std::string MediaLibrary::currentFilter()
|
std::string MediaLibrary::currentFilter()
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "song_list.h"
|
#include "song_list.h"
|
||||||
|
|
||||||
struct MediaLibrary: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tabbable
|
struct MediaLibrary: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Searchable, Tabbable
|
||||||
{
|
{
|
||||||
MediaLibrary();
|
MediaLibrary();
|
||||||
|
|
||||||
@@ -55,6 +55,8 @@ struct MediaLibrary: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tab
|
|||||||
virtual void clearSearchConstraint() OVERRIDE;
|
virtual void clearSearchConstraint() OVERRIDE;
|
||||||
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
||||||
|
|
||||||
|
// Filterable implementation
|
||||||
|
virtual bool allowsFiltering() OVERRIDE;
|
||||||
virtual std::string currentFilter() OVERRIDE;
|
virtual std::string currentFilter() OVERRIDE;
|
||||||
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,13 @@ bool Playlist::search(SearchDirection direction, bool wrap, bool skip_current)
|
|||||||
return ::search(w, m_search_predicate, direction, wrap, skip_current);
|
return ::search(w, m_search_predicate, direction, wrap, skip_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
|
||||||
|
bool Playlist::allowsFiltering()
|
||||||
|
{
|
||||||
|
return allowsSearching();
|
||||||
|
}
|
||||||
|
|
||||||
std::string Playlist::currentFilter()
|
std::string Playlist::currentFilter()
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "song_list.h"
|
#include "song_list.h"
|
||||||
|
|
||||||
struct Playlist: Screen<SongMenu>, HasSongs, Searchable, Tabbable
|
struct Playlist: Screen<SongMenu>, Filterable, HasSongs, Searchable, Tabbable
|
||||||
{
|
{
|
||||||
Playlist();
|
Playlist();
|
||||||
|
|
||||||
@@ -55,6 +55,8 @@ struct Playlist: Screen<SongMenu>, HasSongs, Searchable, Tabbable
|
|||||||
virtual void clearSearchConstraint() OVERRIDE;
|
virtual void clearSearchConstraint() OVERRIDE;
|
||||||
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
||||||
|
|
||||||
|
// Filterable implementation
|
||||||
|
virtual bool allowsFiltering() OVERRIDE;
|
||||||
virtual std::string currentFilter() OVERRIDE;
|
virtual std::string currentFilter() OVERRIDE;
|
||||||
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
||||||
|
|
||||||
|
|||||||
@@ -318,6 +318,13 @@ bool PlaylistEditor::search(SearchDirection direction, bool wrap, bool skip_curr
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
|
||||||
|
bool PlaylistEditor::allowsFiltering()
|
||||||
|
{
|
||||||
|
return allowsSearching();
|
||||||
|
}
|
||||||
|
|
||||||
std::string PlaylistEditor::currentFilter()
|
std::string PlaylistEditor::currentFilter()
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "song_list.h"
|
#include "song_list.h"
|
||||||
|
|
||||||
struct PlaylistEditor: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tabbable
|
struct PlaylistEditor: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Searchable, Tabbable
|
||||||
{
|
{
|
||||||
PlaylistEditor();
|
PlaylistEditor();
|
||||||
|
|
||||||
@@ -55,6 +55,8 @@ struct PlaylistEditor: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, T
|
|||||||
virtual void clearSearchConstraint() OVERRIDE;
|
virtual void clearSearchConstraint() OVERRIDE;
|
||||||
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
||||||
|
|
||||||
|
// Filterable implementation
|
||||||
|
virtual bool allowsFiltering() OVERRIDE;
|
||||||
virtual std::string currentFilter() OVERRIDE;
|
virtual std::string currentFilter() OVERRIDE;
|
||||||
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
||||||
|
|
||||||
|
|||||||
@@ -269,6 +269,13 @@ bool SearchEngine::search(SearchDirection direction, bool wrap, bool skip_curren
|
|||||||
return ::search(w, m_search_predicate, direction, wrap, skip_current);
|
return ::search(w, m_search_predicate, direction, wrap, skip_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
|
||||||
|
bool SearchEngine::allowsFiltering()
|
||||||
|
{
|
||||||
|
return allowsSearching();
|
||||||
|
}
|
||||||
|
|
||||||
std::string SearchEngine::currentFilter()
|
std::string SearchEngine::currentFilter()
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ struct SearchEngineWindow: NC::Menu<SEItem>, SongList
|
|||||||
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
|
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SearchEngine: Screen<SearchEngineWindow>, HasActions, HasSongs, Searchable, Tabbable
|
struct SearchEngine: Screen<SearchEngineWindow>, Filterable, HasActions, HasSongs, Searchable, Tabbable
|
||||||
{
|
{
|
||||||
SearchEngine();
|
SearchEngine();
|
||||||
|
|
||||||
@@ -116,6 +116,8 @@ struct SearchEngine: Screen<SearchEngineWindow>, HasActions, HasSongs, Searchabl
|
|||||||
virtual void clearSearchConstraint() OVERRIDE;
|
virtual void clearSearchConstraint() OVERRIDE;
|
||||||
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
virtual bool search(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
||||||
|
|
||||||
|
// Filterable implementation
|
||||||
|
virtual bool allowsFiltering() OVERRIDE;
|
||||||
virtual std::string currentFilter() OVERRIDE;
|
virtual std::string currentFilter() OVERRIDE;
|
||||||
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
virtual void applyFilter(const std::string &filter) OVERRIDE;
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ struct SelectedItemsAdder: Screen<NC::Menu<RunnableItem<std::string, void()>> *>
|
|||||||
virtual bool isLockable() OVERRIDE { return false; }
|
virtual bool isLockable() OVERRIDE { return false; }
|
||||||
virtual bool isMergable() OVERRIDE { return false; }
|
virtual bool isMergable() OVERRIDE { return false; }
|
||||||
|
|
||||||
// HasActions implemenetation
|
// HasActions implementation
|
||||||
virtual bool actionRunnable() OVERRIDE;
|
virtual bool actionRunnable() OVERRIDE;
|
||||||
virtual void runAction() OVERRIDE;
|
virtual void runAction() OVERRIDE;
|
||||||
|
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ bool Statusbar::Helpers::ApplyFilterImmediately::operator()(const char *s)
|
|||||||
using Global::myScreen;
|
using Global::myScreen;
|
||||||
Status::trace();
|
Status::trace();
|
||||||
try {
|
try {
|
||||||
if (m_w->allowsSearching() && m_w->currentFilter() != s)
|
if (m_w->allowsFiltering() && m_w->currentFilter() != s)
|
||||||
{
|
{
|
||||||
m_w->applyFilter(s);
|
m_w->applyFilter(s);
|
||||||
if (myScreen == myPlaylist)
|
if (myScreen == myPlaylist)
|
||||||
|
|||||||
@@ -91,14 +91,14 @@ private:
|
|||||||
|
|
||||||
struct ApplyFilterImmediately
|
struct ApplyFilterImmediately
|
||||||
{
|
{
|
||||||
ApplyFilterImmediately(Searchable *w)
|
ApplyFilterImmediately(Filterable *w)
|
||||||
: m_w(w)
|
: m_w(w)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool operator()(const char *s);
|
bool operator()(const char *s);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Searchable *m_w;
|
Filterable *m_w;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FindImmediately
|
struct FindImmediately
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ struct TinyTagEditor: Screen<NC::Menu<NC::Buffer>>, HasActions
|
|||||||
virtual bool isLockable() OVERRIDE { return false; }
|
virtual bool isLockable() OVERRIDE { return false; }
|
||||||
virtual bool isMergable() OVERRIDE { return true; }
|
virtual bool isMergable() OVERRIDE { return true; }
|
||||||
|
|
||||||
// HasActions implemenetation
|
// HasActions implementation
|
||||||
virtual bool actionRunnable() OVERRIDE;
|
virtual bool actionRunnable() OVERRIDE;
|
||||||
virtual void runAction() OVERRIDE;
|
virtual void runAction() OVERRIDE;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user