selected items adder: implement Searchable instance
This commit is contained in:
@@ -42,6 +42,14 @@ void DisplayComponent(SelectedItemsAdder::Component &menu)
|
||||
menu << Charset::utf8ToLocale(menu.drawn()->value().item());
|
||||
}
|
||||
|
||||
bool EntryMatcher(const Regex::Regex &rx, const NC::Menu<SelectedItemsAdder::Entry>::Item &item)
|
||||
{
|
||||
if (!item.isSeparator())
|
||||
return Regex::search(item.value().item(), rx);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SelectedItemsAdder::SelectedItemsAdder()
|
||||
@@ -180,6 +188,32 @@ void SelectedItemsAdder::mouseButtonPressed(MEVENT me)
|
||||
Screen<WindowType>::mouseButtonPressed(me);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
bool SelectedItemsAdder::allowsSearching()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void SelectedItemsAdder::setSearchConstraint(const std::string &constraint)
|
||||
{
|
||||
m_search_predicate = Regex::ItemFilter<Entry>(
|
||||
Regex::make(constraint, Config.regex_type), EntryMatcher
|
||||
);
|
||||
}
|
||||
|
||||
void SelectedItemsAdder::clearConstraint()
|
||||
{
|
||||
m_search_predicate.clear();
|
||||
}
|
||||
|
||||
bool SelectedItemsAdder::find(SearchDirection direction, bool wrap, bool skip_current)
|
||||
{
|
||||
return search(*w, m_search_predicate, direction, wrap, skip_current);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void SelectedItemsAdder::populatePlaylistSelector(BaseScreen *old_screen)
|
||||
{
|
||||
// stored playlists don't support songs from outside of mpd database
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
|
||||
#include "runnable_item.h"
|
||||
#include "interfaces.h"
|
||||
#include "regex_filter.h"
|
||||
#include "screen.h"
|
||||
#include "song.h"
|
||||
|
||||
struct SelectedItemsAdder: Screen<NC::Menu<RunnableItem<std::string, void()>> *>, Tabbable
|
||||
struct SelectedItemsAdder: Screen<NC::Menu<RunnableItem<std::string, void()>> *>, Searchable, Tabbable
|
||||
{
|
||||
typedef SelectedItemsAdder Self;
|
||||
typedef typename std::remove_pointer<WindowType>::type Component;
|
||||
@@ -49,6 +50,12 @@ struct SelectedItemsAdder: Screen<NC::Menu<RunnableItem<std::string, void()>> *>
|
||||
virtual bool isLockable() OVERRIDE { return false; }
|
||||
virtual bool isMergable() OVERRIDE { return false; }
|
||||
|
||||
// Searchable implementation
|
||||
virtual bool allowsSearching() OVERRIDE;
|
||||
virtual void setSearchConstraint(const std::string &constraint) OVERRIDE;
|
||||
virtual void clearConstraint() OVERRIDE;
|
||||
virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
|
||||
|
||||
private:
|
||||
void populatePlaylistSelector(BaseScreen *screen);
|
||||
|
||||
@@ -75,6 +82,8 @@ private:
|
||||
Component m_position_selector;
|
||||
|
||||
std::vector<MPD::Song> m_selected_items;
|
||||
|
||||
Regex::ItemFilter<Entry> m_search_predicate;
|
||||
};
|
||||
|
||||
extern SelectedItemsAdder *mySelectedItemsAdder;
|
||||
|
||||
Reference in New Issue
Block a user