From 6a5f46a4589ddbe43ba00feeb95f10f8b467dbe2 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 6 Nov 2014 23:22:55 +0100 Subject: [PATCH] actions: make find forward/backward incremental --- NEWS | 2 ++ src/actions.cpp | 57 ++++++++++++---------------------- src/actions.h | 2 +- src/browser.cpp | 27 ++++++---------- src/browser.h | 6 ++-- src/enums.cpp | 27 ++++++++++++++++ src/enums.h | 4 +++ src/helpers.h | 54 +++++++++++++++++++++----------- src/interfaces.h | 7 +++-- src/media_library.cpp | 68 +++++++++++++++++------------------------ src/media_library.h | 6 ++-- src/playlist.cpp | 25 +++++---------- src/playlist.h | 6 ++-- src/playlist_editor.cpp | 48 ++++++++++++----------------- src/playlist_editor.h | 6 ++-- src/search_engine.cpp | 27 ++++++---------- src/search_engine.h | 6 ++-- src/statusbar.cpp | 18 +++++++++++ src/statusbar.h | 15 +++++++++ src/tag_editor.cpp | 48 ++++++++++++----------------- src/tag_editor.h | 6 ++-- 21 files changed, 236 insertions(+), 229 deletions(-) diff --git a/NEWS b/NEWS index 323d8bee..edd23190 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ ncmpcpp-0.7 (????-??-??) * Directories and playlists in browser can now be sorted by modification time. * ~ is now expanded to home directory in mpd_host configuration variable. * It is now possible to define startup slave screen using -S/--slave-screen command line option or startup_slave_screen configuration variable. +* List filtering has been removed due to the major part of its functionality overlapping with find forward/backward. +* Find backward/forward function is now incremental. ncmpcpp-0.6.1 (2014-11-06) diff --git a/src/actions.cpp b/src/actions.cpp index 8d780eb6..1b5a0fa5 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -72,23 +72,6 @@ using Global::myScreen; namespace { -enum class Find { Forward, Backward }; - -std::string findToString(Find find) -{ - std::string result; - switch (find) - { - case Find::Forward: - result = "forward"; - break; - case Find::Backward: - result = "backward"; - break; - } - return result; -} - boost::array< Actions::BaseAction *, static_cast(Actions::Type::_numberOfActions) > AvailableActions; @@ -96,7 +79,7 @@ boost::array< void populateActions(); void seek(); -void findItem(const Find direction); +void findItem(const SearchDirection direction); void listsChangeFinisher(); } @@ -1860,7 +1843,7 @@ bool FindItemBackward::canBeRun() const void FindItemForward::run() { - findItem(::Find::Forward); + findItem(SearchDirection::Forward); listsChangeFinisher(); } @@ -1872,7 +1855,7 @@ bool FindItemForward::canBeRun() const void FindItemBackward::run() { - findItem(::Find::Backward); + findItem(SearchDirection::Backward); listsChangeFinisher(); } @@ -1885,7 +1868,7 @@ void NextFoundItem::run() { Searchable *w = dynamic_cast(myScreen); assert(w != nullptr); - w->findForward(Config.wrapped_search); + w->find(SearchDirection::Forward, Config.wrapped_search, true); listsChangeFinisher(); } @@ -1898,7 +1881,7 @@ void PreviousFoundItem::run() { Searchable *w = dynamic_cast(myScreen); assert(w != nullptr); - w->findBackward(Config.wrapped_search); + w->find(SearchDirection::Backward, Config.wrapped_search, true); listsChangeFinisher(); } @@ -2710,7 +2693,7 @@ void seek() wFooter->setTimeout(old_timeout); } -void findItem(const Find direction) +void findItem(const SearchDirection direction) { using Global::wFooter; @@ -2721,32 +2704,30 @@ void findItem(const Find direction) std::string constraint; { Statusbar::ScopedLock slock; - Statusbar::put() << "Find " << findToString(direction) << ": "; + NC::Window::ScopedPromptHook prompt_hook(*wFooter, + Statusbar::Helpers::FindImmediately(w, direction) + ); + Statusbar::put() << (boost::format("Find %1%: ") % direction).str(); constraint = wFooter->prompt(); } try { - bool success = w->setSearchConstraint(constraint); - if (success) - Statusbar::printf("Using constraint \"%1%\"", constraint); - else + if (constraint.empty()) + { Statusbar::printf("Constraint unset"); + w->clearConstraint(); + } + else + { + w->setSearchConstraint(constraint); + Statusbar::printf("Using constraint \"%1%\"", constraint); + } } catch (boost::bad_expression &e) { Statusbar::printf("%1%", e.what()); } - - switch (direction) - { - case Find::Forward: - w->findForward(Config.wrapped_search); - break; - case Find::Backward: - w->findBackward(Config.wrapped_search); - break; - } } void listsChangeFinisher() diff --git a/src/actions.h b/src/actions.h index d36b12d1..bf3f25f4 100644 --- a/src/actions.h +++ b/src/actions.h @@ -26,7 +26,7 @@ #include #include "window.h" -namespace Actions {// +namespace Actions { enum class Type { diff --git a/src/browser.cpp b/src/browser.cpp index 551bdc02..a009a8a2 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -248,31 +248,22 @@ bool Browser::allowsSearching() return true; } -bool Browser::setSearchConstraint(const std::string &constraint) +void Browser::setSearchConstraint(const std::string &constraint) { - if (constraint.empty()) - { - m_search_predicate.clear(); - return false; - } - else - { - m_search_predicate = RegexFilter( - boost::regex(constraint, Config.regex_type), - boost::bind(browserEntryMatcher, _1, _2, false) - ); - return true; - } + m_search_predicate = RegexFilter( + boost::regex(constraint, Config.regex_type), + boost::bind(browserEntryMatcher, _1, _2, false) + ); } -void Browser::findForward(bool wrap) +void Browser::clearConstraint() { - searchForward(w, m_search_predicate, wrap); + m_search_predicate.clear(); } -void Browser::findBackward(bool wrap) +bool Browser::find(SearchDirection direction, bool wrap, bool skip_current) { - searchBackward(w, m_search_predicate, wrap); + return search(w, m_search_predicate, direction, wrap, skip_current); } /***********************************************************************/ diff --git a/src/browser.h b/src/browser.h index dbe0f77e..2ab55ace 100644 --- a/src/browser.h +++ b/src/browser.h @@ -47,9 +47,9 @@ struct Browser: Screen>, HasSongs, Searchable, Tabbable // Searchable implementation virtual bool allowsSearching() OVERRIDE; - virtual bool setSearchConstraint(const std::string &constraint) OVERRIDE; - virtual void findForward(bool wrap) OVERRIDE; - virtual void findBackward(bool wrap) OVERRIDE; + virtual void setSearchConstraint(const std::string &constraint) OVERRIDE; + virtual void clearConstraint() OVERRIDE; + virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; // HasSongs implementation virtual ProxySongList proxySongList() OVERRIDE; diff --git a/src/enums.cpp b/src/enums.cpp index 4b14f334..ea61b182 100644 --- a/src/enums.cpp +++ b/src/enums.cpp @@ -20,6 +20,33 @@ #include "enums.h" +std::ostream &operator<<(std::ostream &os, SearchDirection sd) +{ + switch (sd) + { + case SearchDirection::Backward: + os << "backward"; + break; + case SearchDirection::Forward: + os << "forward"; + break; + } + return os; +} + +std::istream &operator>>(std::istream &is, SearchDirection &sd) +{ + std::string ssd; + is >> ssd; + if (ssd == "backward") + sd = SearchDirection::Backward; + else if (ssd == "forward") + sd = SearchDirection::Forward; + else + is.setstate(std::ios::failbit); + return is; +} + std::ostream &operator<<(std::ostream &os, SpaceAddMode sam) { switch (sam) diff --git a/src/enums.h b/src/enums.h index 131a931a..1184d600 100644 --- a/src/enums.h +++ b/src/enums.h @@ -24,6 +24,10 @@ #include "config.h" #include +enum class SearchDirection { Backward, Forward }; +std::ostream &operator<<(std::ostream &os, SearchDirection sd); +std::istream &operator>>(std::istream &is, SearchDirection &sd); + enum class SpaceAddMode { AddRemove, AlwaysAdd }; std::ostream &operator<<(std::ostream &os, SpaceAddMode sam); std::istream &operator>>(std::istream &is, SpaceAddMode &sam); diff --git a/src/helpers.h b/src/helpers.h index 98db9510..10925c15 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -31,9 +31,10 @@ template Iterator wrappedSearch(Iterator begin, Iterator current, Iterator end, - const PredicateT &pred, bool wrap) + const PredicateT &pred, bool wrap, bool skip_current) { - ++current; + if (skip_current) + ++current; auto it = std::find_if(current, end, pred); if (it == end && wrap) { @@ -45,23 +46,40 @@ Iterator wrappedSearch(Iterator begin, Iterator current, Iterator end, } template -void searchForward(NC::Menu &m, const PredicateT &pred, bool wrap) +bool search(NC::Menu &m, const PredicateT &pred, + SearchDirection direction, bool wrap, bool skip_current) { -if (!pred.defined()) - return; - auto it = wrappedSearch(m.begin(), m.current(), m.end(), pred, wrap); - if (it != m.end()) - m.highlight(it-m.begin()); -} - -template -void searchBackward(NC::Menu &m, const PredicateT &pred, bool wrap) -{ - if (!pred.defined()) - return; - auto it = wrappedSearch(m.rbegin(), m.rcurrent(), m.rend(), pred, wrap); - if (it != m.rend()) - m.highlight(it.base()-m.begin()-1); + bool result = false; + if (pred.defined()) + { + switch (direction) + { + case SearchDirection::Backward: + { + auto it = wrappedSearch(m.rbegin(), m.rcurrent(), m.rend(), + pred, wrap, skip_current + ); + if (it != m.rend()) + { + m.highlight(it.base()-m.begin()-1); + result = true; + } + break; + } + case SearchDirection::Forward: + { + auto it = wrappedSearch(m.begin(), m.current(), m.end(), + pred, wrap, skip_current + ); + if (it != m.end()) + { + m.highlight(it-m.begin()); + result = true; + } + } + } + } + return result; } inline HasColumns *hasColumns(BaseScreen *screen) diff --git a/src/interfaces.h b/src/interfaces.h index 52ee0fc1..d374fca0 100644 --- a/src/interfaces.h +++ b/src/interfaces.h @@ -22,6 +22,7 @@ #define NCMPCPP_INTERFACES_H #include +#include "enums.h" #include "gcc.h" #include "screen.h" #include "song.h" @@ -30,9 +31,9 @@ struct Searchable { virtual bool allowsSearching() = 0; - virtual bool setSearchConstraint(const std::string &constraint) = 0; - virtual void findForward(bool wrap) = 0; - virtual void findBackward(bool wrap) = 0; + virtual void setSearchConstraint(const std::string &constraint) = 0; + virtual void clearConstraint() = 0; + virtual bool find(SearchDirection direction, bool wrap, bool skip_current) = 0; }; struct HasSongs diff --git a/src/media_library.cpp b/src/media_library.cpp index 0f3bc987..baebbd62 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -574,63 +574,51 @@ bool MediaLibrary::allowsSearching() return true; } -bool MediaLibrary::setSearchConstraint(const std::string &constraint) +void MediaLibrary::setSearchConstraint(const std::string &constraint) { - if (constraint.empty()) + if (isActiveWindow(Tags)) { - if (isActiveWindow(Tags)) - m_tags_search_predicate.clear(); - else if (isActiveWindow(Albums)) - m_albums_search_predicate.clear(); - else if (isActiveWindow(Songs)) - m_songs_search_predicate.clear(); - return false; + m_tags_search_predicate = RegexFilter( + boost::regex(constraint, Config.regex_type), + TagEntryMatcher + ); } - else + else if (isActiveWindow(Albums)) { - if (isActiveWindow(Tags)) - { - m_tags_search_predicate = RegexFilter( - boost::regex(constraint, Config.regex_type), - TagEntryMatcher - ); - } - else if (isActiveWindow(Albums)) - { - m_albums_search_predicate = RegexItemFilter( - boost::regex(constraint, Config.regex_type), - boost::bind(AlbumEntryMatcher, _1, _2, false) - ); - } - else if (isActiveWindow(Songs)) - { - m_songs_search_predicate = RegexFilter( - boost::regex(constraint, Config.regex_type), - SongEntryMatcher - ); - } - return true; + m_albums_search_predicate = RegexItemFilter( + boost::regex(constraint, Config.regex_type), + boost::bind(AlbumEntryMatcher, _1, _2, false) + ); + } + else if (isActiveWindow(Songs)) + { + m_songs_search_predicate = RegexFilter( + boost::regex(constraint, Config.regex_type), + SongEntryMatcher + ); } } -void MediaLibrary::findForward(bool wrap) +void MediaLibrary::clearConstraint() { if (isActiveWindow(Tags)) - searchForward(Tags, m_tags_search_predicate, wrap); + m_tags_search_predicate.clear(); else if (isActiveWindow(Albums)) - searchForward(Albums, m_albums_search_predicate, wrap); + m_albums_search_predicate.clear(); else if (isActiveWindow(Songs)) - searchForward(Songs, m_songs_search_predicate, wrap); + m_songs_search_predicate.clear(); } -void MediaLibrary::findBackward(bool wrap) +bool MediaLibrary::find(SearchDirection direction, bool wrap, bool skip_current) { + bool result = false; if (isActiveWindow(Tags)) - searchBackward(Tags, m_tags_search_predicate, wrap); + result = search(Tags, m_tags_search_predicate, direction, wrap, skip_current); else if (isActiveWindow(Albums)) - searchBackward(Albums, m_albums_search_predicate, wrap); + result = search(Albums, m_albums_search_predicate, direction, wrap, skip_current); else if (isActiveWindow(Songs)) - searchBackward(Songs, m_songs_search_predicate, wrap); + result = search(Songs, m_songs_search_predicate, direction, wrap, skip_current); + return result; } /***********************************************************************/ diff --git a/src/media_library.h b/src/media_library.h index d9855dd2..32ae0d99 100644 --- a/src/media_library.h +++ b/src/media_library.h @@ -50,9 +50,9 @@ struct MediaLibrary: Screen, HasColumns, HasSongs, Searchable, Tab // Searchable implementation virtual bool allowsSearching() OVERRIDE; - virtual bool setSearchConstraint(const std::string &constraint) OVERRIDE; - virtual void findForward(bool wrap) OVERRIDE; - virtual void findBackward(bool wrap) OVERRIDE; + virtual void setSearchConstraint(const std::string &constraint) OVERRIDE; + virtual void clearConstraint() OVERRIDE; + virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; // HasSongs implementation virtual ProxySongList proxySongList() OVERRIDE; diff --git a/src/playlist.cpp b/src/playlist.cpp index 9204e30c..bdb99ea4 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -155,30 +155,21 @@ bool Playlist::allowsSearching() return true; } -bool Playlist::setSearchConstraint(const std::string &constraint) +void Playlist::setSearchConstraint(const std::string &constraint) { - if (constraint.empty()) - { - m_search_predicate.clear(); - return false; - } - else - { - m_search_predicate = RegexFilter( - boost::regex(constraint, Config.regex_type), playlistEntryMatcher - ); - return true; - } + m_search_predicate = RegexFilter( + boost::regex(constraint, Config.regex_type), playlistEntryMatcher + ); } -void Playlist::findForward(bool wrap) +void Playlist::clearConstraint() { - searchForward(w, m_search_predicate, wrap); + m_search_predicate.clear(); } -void Playlist::findBackward(bool wrap) +bool Playlist::find(SearchDirection direction, bool wrap, bool skip_current) { - searchBackward(w, m_search_predicate, wrap); + return search(w, m_search_predicate, direction, wrap, skip_current); } /***********************************************************************/ diff --git a/src/playlist.h b/src/playlist.h index 1cee39cd..6d8500d8 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -50,9 +50,9 @@ struct Playlist: Screen>, HasSongs, Searchable, Tabbable // Searchable implementation virtual bool allowsSearching(); - virtual bool setSearchConstraint(const std::string &constraint) OVERRIDE; - virtual void findForward(bool wrap) OVERRIDE; - virtual void findBackward(bool wrap) OVERRIDE; + virtual void setSearchConstraint(const std::string &constraint) OVERRIDE; + virtual void clearConstraint() OVERRIDE; + virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; // HasSongs implementation virtual ProxySongList proxySongList() OVERRIDE; diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 7b341625..9d77e202 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -328,50 +328,40 @@ bool PlaylistEditor::allowsSearching() return true; } -bool PlaylistEditor::setSearchConstraint(const std::string &constraint) +void PlaylistEditor::setSearchConstraint(const std::string &constraint) { - if (constraint.empty()) + if (isActiveWindow(Playlists)) { - if (isActiveWindow(Playlists)) - m_playlists_search_predicate.clear(); - else if (isActiveWindow(Content)) - m_content_search_predicate.clear(); - return false; + m_playlists_search_predicate = RegexFilter( + boost::regex(constraint, Config.regex_type), + PlaylistEntryMatcher + ); } - else + else if (isActiveWindow(Content)) { - if (isActiveWindow(Playlists)) - { - m_playlists_search_predicate = RegexFilter( - boost::regex(constraint, Config.regex_type), - PlaylistEntryMatcher - ); - } - else if (isActiveWindow(Content)) - { - m_content_search_predicate = RegexFilter( - boost::regex(constraint, Config.regex_type), - SongEntryMatcher - ); - } - return true; + m_content_search_predicate = RegexFilter( + boost::regex(constraint, Config.regex_type), + SongEntryMatcher + ); } } -void PlaylistEditor::findForward(bool wrap) +void PlaylistEditor::clearConstraint() { if (isActiveWindow(Playlists)) - searchForward(Playlists, m_playlists_search_predicate, wrap); + m_playlists_search_predicate.clear(); else if (isActiveWindow(Content)) - searchForward(Content, m_content_search_predicate, wrap); + m_content_search_predicate.clear(); } -void PlaylistEditor::findBackward(bool wrap) +bool PlaylistEditor::find(SearchDirection direction, bool wrap, bool skip_current) { + bool result = false; if (isActiveWindow(Playlists)) - searchBackward(Playlists, m_playlists_search_predicate, wrap); + result = search(Playlists, m_playlists_search_predicate, direction, wrap, skip_current); else if (isActiveWindow(Content)) - searchBackward(Content, m_content_search_predicate, wrap); + result = search(Content, m_content_search_predicate, direction, wrap, skip_current); + return result; } /***********************************************************************/ diff --git a/src/playlist_editor.h b/src/playlist_editor.h index 255f9c04..d874fbbb 100644 --- a/src/playlist_editor.h +++ b/src/playlist_editor.h @@ -50,9 +50,9 @@ struct PlaylistEditor: Screen, HasColumns, HasSongs, Searchable, T // Searchable implementation virtual bool allowsSearching() OVERRIDE; - virtual bool setSearchConstraint(const std::string &constraint) OVERRIDE; - virtual void findForward(bool wrap) OVERRIDE; - virtual void findBackward(bool wrap) OVERRIDE; + virtual void setSearchConstraint(const std::string &constraint) OVERRIDE; + virtual void clearConstraint() OVERRIDE; + virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; // HasSongs implementation virtual ProxySongList proxySongList() OVERRIDE; diff --git a/src/search_engine.cpp b/src/search_engine.cpp index f7302768..1286e4bc 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -260,31 +260,22 @@ bool SearchEngine::allowsSearching() return w.rbegin()->value().isSong(); } -bool SearchEngine::setSearchConstraint(const std::string &constraint) +void SearchEngine::setSearchConstraint(const std::string &constraint) { - if (constraint.empty()) - { - m_search_predicate.clear(); - return false; - } - else - { - m_search_predicate = RegexItemFilter( - boost::regex(constraint, Config.regex_type), - boost::bind(SEItemEntryMatcher, _1, _2, false) - ); - return true; - } + m_search_predicate = RegexItemFilter( + boost::regex(constraint, Config.regex_type), + boost::bind(SEItemEntryMatcher, _1, _2, false) + ); } -void SearchEngine::findForward(bool wrap) +void SearchEngine::clearConstraint() { - searchForward(w, m_search_predicate, wrap); + m_search_predicate.clear(); } -void SearchEngine::findBackward(bool wrap) +bool SearchEngine::find(SearchDirection direction, bool wrap, bool skip_current) { - searchBackward(w, m_search_predicate, wrap); + return search(w, m_search_predicate, direction, wrap, skip_current); } /***********************************************************************/ diff --git a/src/search_engine.h b/src/search_engine.h index f05fee66..e448ff11 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -95,9 +95,9 @@ struct SearchEngine: Screen>, HasSongs, Searchable, Tabbable // Searchable implementation virtual bool allowsSearching() OVERRIDE; - virtual bool setSearchConstraint(const std::string &constraint) OVERRIDE; - virtual void findForward(bool wrap) OVERRIDE; - virtual void findBackward(bool wrap) OVERRIDE; + virtual void setSearchConstraint(const std::string &constraint) OVERRIDE; + virtual void clearConstraint() OVERRIDE; + virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; // HasSongs implementation virtual ProxySongList proxySongList() OVERRIDE; diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 0f7b99b0..851d4ed5 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -220,6 +220,24 @@ bool Statusbar::Helpers::ImmediatelyReturnOneOf::operator()(const char *s) const return !isOneOf(s); } +bool Statusbar::Helpers::FindImmediately::operator()(const char *s) +{ + using Global::myScreen; + Status::trace(); + try { + if (m_w->allowsSearching() && m_s != s) + { + m_w->setSearchConstraint(s); + m_found = m_w->find(m_direction, Config.wrapped_search, false); + if (myScreen == myPlaylist) + myPlaylist->EnableHighlighting(); + myScreen->refreshWindow(); + m_s = s; + } + } catch (boost::bad_expression &) { } + return true; +} + bool Statusbar::Helpers::TryExecuteImmediateCommand::operator()(const char *s) { bool continue_ = true; diff --git a/src/statusbar.h b/src/statusbar.h index 71bc13b8..1340b69b 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -89,6 +89,21 @@ private: std::vector m_values; }; +struct FindImmediately +{ + FindImmediately(Searchable *w, SearchDirection direction) + : m_w(w), m_direction(direction), m_found(true) + { } + + bool operator()(const char *s); + +private: + Searchable *m_w; + const SearchDirection m_direction; + std::string m_s; + bool m_found; +}; + struct TryExecuteImmediateCommand { bool operator()(const char *s); diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 630d3fba..e64fb922 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -721,50 +721,40 @@ bool TagEditor::allowsSearching() return w == Dirs || w == Tags; } -bool TagEditor::setSearchConstraint(const std::string &constraint) +void TagEditor::setSearchConstraint(const std::string &constraint) { - if (constraint.empty()) + if (w == Dirs) { - if (w == Dirs) - m_directories_search_predicate.clear(); - else if (w == Tags) - m_songs_search_predicate.clear(); - return false; + m_directories_search_predicate = RegexFilter>( + boost::regex(constraint, Config.regex_type), + boost::bind(DirEntryMatcher, _1, _2, false) + ); } - else + else if (w == Tags) { - if (w == Dirs) - { - m_directories_search_predicate = RegexFilter>( - boost::regex(constraint, Config.regex_type), - boost::bind(DirEntryMatcher, _1, _2, false) - ); - } - else if (w == Tags) - { - m_songs_search_predicate = RegexFilter( - boost::regex(constraint, Config.regex_type), - SongEntryMatcher - ); - } - return true; + m_songs_search_predicate = RegexFilter( + boost::regex(constraint, Config.regex_type), + SongEntryMatcher + ); } } -void TagEditor::findForward(bool wrap) +void TagEditor::clearConstraint() { if (w == Dirs) - searchForward(*Dirs, m_directories_search_predicate, wrap); + m_directories_search_predicate.clear(); else if (w == Tags) - searchForward(*Tags, m_songs_search_predicate, wrap); + m_songs_search_predicate.clear(); } -void TagEditor::findBackward(bool wrap) +bool TagEditor::find(SearchDirection direction, bool wrap, bool skip_current) { + bool result = false; if (w == Dirs) - searchBackward(*Dirs, m_directories_search_predicate, wrap); + result = search(*Dirs, m_directories_search_predicate, direction, wrap, skip_current); else if (w == Tags) - searchBackward(*Tags, m_songs_search_predicate, wrap); + result = search(*Tags, m_songs_search_predicate, direction, wrap, skip_current); + return result; } /***********************************************************************/ diff --git a/src/tag_editor.h b/src/tag_editor.h index 44004751..5e83990b 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -53,9 +53,9 @@ struct TagEditor: Screen, HasColumns, HasSongs, Searchable, Tabbab // Searchable implementation virtual bool allowsSearching() OVERRIDE; - virtual bool setSearchConstraint(const std::string &constraint) OVERRIDE; - virtual void findForward(bool wrap) OVERRIDE; - virtual void findBackward(bool wrap) OVERRIDE; + virtual void setSearchConstraint(const std::string &constraint) OVERRIDE; + virtual void clearConstraint() OVERRIDE; + virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE; // HasSongs implementation virtual ProxySongList proxySongList() OVERRIDE;