From 7664f8fd29793be09899cd1c94695a2a3880215f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 24 Oct 2019 19:46:59 +0200 Subject: Require all terms of space-separated plugin search filter string --- gtk2_ardour/plugin_selector.cc | 50 ++++++++++++++++++++++++------------------ gtk2_ardour/plugin_selector.h | 2 -- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/gtk2_ardour/plugin_selector.cc b/gtk2_ardour/plugin_selector.cc index 6013281c23..0384a6281d 100644 --- a/gtk2_ardour/plugin_selector.cc +++ b/gtk2_ardour/plugin_selector.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -352,6 +353,27 @@ PluginSelector::added_row_clicked(GdkEventButton* event) btn_remove_clicked(); } + +static void +setup_search_string (string& searchstr) +{ + transform (searchstr.begin(), searchstr.end(), searchstr.begin(), ::toupper); +} + +static bool +match_search_strings (string const& haystack, string const& needle) +{ + boost::char_separator sep (" "); + typedef boost::tokenizer > tokenizer; + tokenizer t (needle, sep); + for (tokenizer::iterator ti = t.begin(); ti != t.end(); ++ti) { + if (haystack.find (*ti) == string::npos) { + return false; + } + } + return true; +} + bool PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& searchstr) { @@ -361,22 +383,16 @@ PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& if (!searchstr.empty()) { - std::string compstr; - if (_search_name_checkbox->get_active()) { /* name contains */ - compstr = info->name; - transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper); - if (compstr.find (searchstr) != string::npos) { - maybe_show = true; - } + std::string compstr = info->name; + setup_search_string (compstr); + maybe_show |= match_search_strings (compstr, searchstr); } if (_search_tags_checkbox->get_active()) { /* tag contains */ - compstr = manager.get_tags_as_string (info); - transform (compstr.begin(), compstr.end(), compstr.begin(), ::toupper); - if (compstr.find (searchstr) != string::npos) { - maybe_show = true; - } + std::string compstr = manager.get_tags_as_string (info); + setup_search_string (compstr); + maybe_show |= match_search_strings (compstr, searchstr); } if (!maybe_show) { @@ -458,13 +474,6 @@ PluginSelector::show_this_plugin (const PluginInfoPtr& info, const std::string& return true; } -void -PluginSelector::setup_search_string (string& searchstr) -{ - searchstr = search_entry.get_text (); - transform (searchstr.begin(), searchstr.end(), searchstr.begin(), ::toupper); -} - void PluginSelector::set_sensitive_widgets () { @@ -503,8 +512,6 @@ PluginSelector::refill () return; } - std::string searchstr; - in_row_change = true; plugin_display.set_model (Glib::RefPtr(0)); @@ -518,6 +525,7 @@ PluginSelector::refill () plugin_model->clear (); + std::string searchstr = search_entry.get_text (); setup_search_string (searchstr); ladspa_refiller (searchstr); diff --git a/gtk2_ardour/plugin_selector.h b/gtk2_ardour/plugin_selector.h index 4015344882..4deda02aba 100644 --- a/gtk2_ardour/plugin_selector.h +++ b/gtk2_ardour/plugin_selector.h @@ -173,8 +173,6 @@ private: ARDOUR::PluginPtr load_plugin (ARDOUR::PluginInfoPtr); bool show_this_plugin (const ARDOUR::PluginInfoPtr&, const std::string&); - void setup_search_string (std::string&); - void favorite_changed (const std::string& path); void hidden_changed (const std::string& path); bool in_row_change; -- cgit v1.2.3