From 4c944085d62e566fd3c99b053907d8d8b08790b8 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Fri, 31 Aug 2012 23:09:56 +0200 Subject: menu: generalize filtering, introduce interfaces --- src/browser.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/browser.cpp') diff --git a/src/browser.cpp b/src/browser.cpp index 446556b9..fed5c0bd 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -319,9 +319,21 @@ void Browser::GetSelectedSongs(MPD::SongList &v) } } -void Browser::ApplyFilter(const std::string &s) +std::string Browser::currentFilter() { - w->ApplyFilter(s, itsBrowsedDir == "/" ? 0 : 1, REG_ICASE | Config.regex_type); + return RegexFilter::currentFilter(*w); +} + +void Browser::applyFilter(const std::string &filter) +{ + w->ShowAll(); + auto fun = [](const Regex &rx, Menu &menu, const Menu::Item &item) { + if (item.value().type == MPD::itDirectory && item.value().name == "..") + return true; + return rx.match(menu.Stringify(item)); + }; + auto rx = RegexFilter(filter, Config.regex_type, fun); + w->Filter(w->Begin(), w->End(), rx); } bool Browser::hasSupportedExtension(const std::string &file) @@ -485,7 +497,6 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory, MPD::MutableSong *s = new MPD::MutableSong(mpd_song_begin(&file_pair)); new_item.song = std::shared_ptr(s); # ifdef HAVE_TAGLIB_H - // FIXME if (!recursively) TagEditor::ReadTags(*s); # endif // HAVE_TAGLIB_H -- cgit v1.2.3