[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 272/473: Unify interface for searching elements.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:57:22 CET 2015
This is an automated email from the git hooks/post-receive script.
gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.
commit b80908eb0a70e461b0a522e73b6d8ecd21038fee
Author: Graeme Gott <graeme at gottcode.org>
Date: Thu Dec 5 15:58:47 2013 -0500
Unify interface for searching elements.
---
panel-plugin/element.h | 7 +++++++
panel-plugin/launcher.cpp | 26 +++++++++++++++-----------
panel-plugin/launcher.h | 4 +---
panel-plugin/search-action.cpp | 9 +++++----
panel-plugin/search-action.h | 2 +-
panel-plugin/search-page.cpp | 12 ++++++------
panel-plugin/search-page.h | 14 +++++++-------
7 files changed, 42 insertions(+), 32 deletions(-)
diff --git a/panel-plugin/element.h b/panel-plugin/element.h
index a64fc8a..8749817 100644
--- a/panel-plugin/element.h
+++ b/panel-plugin/element.h
@@ -23,6 +23,8 @@
namespace WhiskerMenu
{
+class Query;
+
class Element
{
public:
@@ -56,6 +58,11 @@ public:
{
}
+ virtual int search(const Query&)
+ {
+ return G_MAXINT;
+ }
+
static bool less_than(const Element* lhs, const Element* rhs)
{
return g_strcmp0(lhs->m_sort_key, rhs->m_sort_key) < 0;
diff --git a/panel-plugin/launcher.cpp b/panel-plugin/launcher.cpp
index d97aff0..a9a6a8f 100644
--- a/panel-plugin/launcher.cpp
+++ b/panel-plugin/launcher.cpp
@@ -256,24 +256,28 @@ void Launcher::run(GdkScreen* screen) const
//-----------------------------------------------------------------------------
-int Launcher::search(const Query& query) const
+int Launcher::search(const Query& query)
{
int match = query.match(m_search_name);
- if (match == INT_MAX)
+ if (match != G_MAXINT)
{
- match = query.match(m_search_command);
- if (match != INT_MAX)
- {
- // Sort matches in executables after matches in names
- match += 10;
- }
+ return match;
}
- if ((match == INT_MAX) && wm_settings->launcher_show_description)
+
+ // Sort matches in executables after matches in names
+ match = query.match(m_search_command);
+ if (match != G_MAXINT)
+ {
+ match += 10;
+ return match;
+ }
+
+ // Sort matches in comments after matches in names
+ if (wm_settings->launcher_show_description)
{
match = query.match(m_search_comment);
- if (match != INT_MAX)
+ if (match != G_MAXINT)
{
- // Sort matches in comments after matches in names
match += 20;
}
}
diff --git a/panel-plugin/launcher.h b/panel-plugin/launcher.h
index 3310eca..e18766e 100644
--- a/panel-plugin/launcher.h
+++ b/panel-plugin/launcher.h
@@ -27,8 +27,6 @@
namespace WhiskerMenu
{
-class Query;
-
class Launcher : public Element
{
public:
@@ -61,7 +59,7 @@ public:
void run(GdkScreen* screen) const;
- int search(const Query& query) const;
+ int search(const Query& query);
private:
GarconMenuItem* m_item;
diff --git a/panel-plugin/search-action.cpp b/panel-plugin/search-action.cpp
index 93c72cb..59fd364 100644
--- a/panel-plugin/search-action.cpp
+++ b/panel-plugin/search-action.cpp
@@ -17,9 +17,9 @@
#include "search-action.h"
+#include "query.h"
#include "settings.h"
-#include <exo/exo.h>
#include <libxfce4ui/libxfce4ui.h>
using namespace WhiskerMenu;
@@ -61,15 +61,16 @@ SearchAction::~SearchAction()
//-----------------------------------------------------------------------------
-bool SearchAction::match(const gchar* haystack)
+int SearchAction::search(const Query& query)
{
- if (exo_str_is_empty(haystack) || m_pattern.empty() || m_command.empty())
+ if (m_pattern.empty() || m_command.empty())
{
return false;
}
m_expanded_command.clear();
+ const gchar* haystack = query.query().c_str();
bool found = !m_is_regex ? match_prefix(haystack) : match_regex(haystack);
if (found && (m_show_description != wm_settings->launcher_show_description))
@@ -78,7 +79,7 @@ bool SearchAction::match(const gchar* haystack)
update_text();
}
- return found;
+ return found ? 0 : G_MAXINT;
}
//-----------------------------------------------------------------------------
diff --git a/panel-plugin/search-action.h b/panel-plugin/search-action.h
index a89b58f..0229b35 100644
--- a/panel-plugin/search-action.h
+++ b/panel-plugin/search-action.h
@@ -61,8 +61,8 @@ public:
return m_is_regex;
}
- bool match(const gchar* haystack);
void run(GdkScreen* screen) const;
+ int search(const Query& query);
void set_name(const gchar* name);
void set_pattern(const gchar* pattern);
diff --git a/panel-plugin/search-page.cpp b/panel-plugin/search-page.cpp
index 436ccbc..75c2af3 100644
--- a/panel-plugin/search-page.cpp
+++ b/panel-plugin/search-page.cpp
@@ -96,7 +96,7 @@ void SearchPage::set_filter(const gchar* filter)
for (std::vector<SearchAction*>::size_type i = 0, end = wm_settings->search_actions.size(); i < end; ++i)
{
action = wm_settings->search_actions[i];
- if (action->match(filter))
+ if (action->search(m_query) != G_MAXINT)
{
gtk_list_store_insert_with_values(
store, NULL, G_MAXINT,
@@ -106,15 +106,15 @@ void SearchPage::set_filter(const gchar* filter)
-1);
}
}
- Launcher* launcher;
+ Element* element;
for (std::vector<Match>::size_type i = 0, end = m_matches.size(); i < end; ++i)
{
- launcher = m_matches[i].launcher();
+ element = m_matches[i].element();
gtk_list_store_insert_with_values(
store, NULL, G_MAXINT,
- LauncherView::COLUMN_ICON, launcher->get_icon(),
- LauncherView::COLUMN_TEXT, launcher->get_text(),
- LauncherView::COLUMN_LAUNCHER, launcher,
+ LauncherView::COLUMN_ICON, element->get_icon(),
+ LauncherView::COLUMN_TEXT, element->get_text(),
+ LauncherView::COLUMN_LAUNCHER, element,
-1);
}
get_view()->set_model(GTK_TREE_MODEL(store));
diff --git a/panel-plugin/search-page.h b/panel-plugin/search-page.h
index 7337b5d..5a88bea 100644
--- a/panel-plugin/search-page.h
+++ b/panel-plugin/search-page.h
@@ -49,15 +49,15 @@ private:
class Match
{
public:
- Match(Launcher* launcher = NULL) :
- m_launcher(launcher),
+ Match(Element* element = NULL) :
+ m_element(element),
m_relevancy(G_MAXINT)
{
}
- Launcher* launcher() const
+ Element* element() const
{
- return m_launcher;
+ return m_element;
}
bool operator<(const Match& match) const
@@ -67,8 +67,8 @@ private:
void update(const Query& query)
{
- g_assert(m_launcher != NULL);
- m_relevancy = m_launcher->search(query);
+ g_assert(m_element != NULL);
+ m_relevancy = m_element->search(query);
}
static bool invalid(const Match& match)
@@ -77,7 +77,7 @@ private:
}
private:
- Launcher* m_launcher;
+ Element* m_element;
int m_relevancy;
};
std::vector<Match> m_matches;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list