[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 49/473: Move search logic into launcher.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:53:39 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 14411b14b4a26b092ecbfe7bd876a37a9e20bf7b
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Jul 1 07:28:43 2013 -0400

    Move search logic into launcher.
---
 src/launcher.cpp    |  111 ++++++++++++++++++++++++++++++---------------------
 src/launcher.hpp    |    8 +++-
 src/search_page.cpp |    6 +--
 3 files changed, 75 insertions(+), 50 deletions(-)

diff --git a/src/launcher.cpp b/src/launcher.cpp
index dd6b65d..b0a09ae 100644
--- a/src/launcher.cpp
+++ b/src/launcher.cpp
@@ -158,51 +158,6 @@ Launcher::~Launcher()
 
 //-----------------------------------------------------------------------------
 
-const gchar* Launcher::get_search_text()
-{
-	if (!m_search_text.empty())
-	{
-		return m_search_text.c_str();
-	}
-
-	// Combine name, comment, and generic name into single casefolded string
-	const gchar* name = garcon_menu_item_get_name(m_item);
-	if (name)
-	{
-		gchar* normalized = g_utf8_normalize(name, -1, G_NORMALIZE_DEFAULT);
-		gchar* utf8 = g_utf8_casefold(normalized, -1);
-		m_search_text += utf8;
-		g_free(utf8);
-		g_free(normalized);
-		m_search_text += '\n';
-	}
-
-	const gchar* generic_name = garcon_menu_item_get_generic_name(m_item);
-	if (generic_name)
-	{
-		gchar* normalized = g_utf8_normalize(generic_name, -1, G_NORMALIZE_DEFAULT);
-		gchar* utf8 = g_utf8_casefold(normalized, -1);
-		m_search_text += utf8;
-		g_free(utf8);
-		g_free(normalized);
-		m_search_text += '\n';
-	}
-
-	const gchar* comment = garcon_menu_item_get_comment(m_item);
-	if (comment)
-	{
-		gchar* normalized = g_utf8_normalize(comment, -1, G_NORMALIZE_DEFAULT);
-		gchar* utf8 = g_utf8_casefold(normalized, -1);
-		m_search_text += utf8;
-		g_free(utf8);
-		g_free(normalized);
-	}
-
-	return m_search_text.c_str();
-}
-
-//-----------------------------------------------------------------------------
-
 void Launcher::run(GdkScreen* screen) const
 {
 	const gchar* string = garcon_menu_item_get_command(m_item);
@@ -286,6 +241,27 @@ void Launcher::run(GdkScreen* screen) const
 
 //-----------------------------------------------------------------------------
 
+unsigned int Launcher::search(const std::string& filter_string)
+{
+	std::map<std::string, unsigned int>::const_iterator i = m_searches.find(filter_string);
+	if (i != m_searches.end())
+	{
+		return i->second;
+	}
+
+	unsigned int index = UINT_MAX;
+	gchar* result = g_strstr_len(get_search_text(), -1, filter_string.c_str());
+	if (result != NULL)
+	{
+		index = result - get_search_text();
+	}
+
+	m_searches.insert(std::make_pair(filter_string, index));
+	return index;
+}
+
+//-----------------------------------------------------------------------------
+
 bool Launcher::get_show_name()
 {
 	return f_show_name;
@@ -313,3 +289,48 @@ void Launcher::set_show_description(bool show)
 }
 
 //-----------------------------------------------------------------------------
+
+const gchar* Launcher::get_search_text()
+{
+	if (!m_search_text.empty())
+	{
+		return m_search_text.c_str();
+	}
+
+	// Combine name, comment, and generic name into single casefolded string
+	const gchar* name = garcon_menu_item_get_name(m_item);
+	if (name)
+	{
+		gchar* normalized = g_utf8_normalize(name, -1, G_NORMALIZE_DEFAULT);
+		gchar* utf8 = g_utf8_casefold(normalized, -1);
+		m_search_text += utf8;
+		g_free(utf8);
+		g_free(normalized);
+		m_search_text += '\n';
+	}
+
+	const gchar* generic_name = garcon_menu_item_get_generic_name(m_item);
+	if (generic_name)
+	{
+		gchar* normalized = g_utf8_normalize(generic_name, -1, G_NORMALIZE_DEFAULT);
+		gchar* utf8 = g_utf8_casefold(normalized, -1);
+		m_search_text += utf8;
+		g_free(utf8);
+		g_free(normalized);
+		m_search_text += '\n';
+	}
+
+	const gchar* comment = garcon_menu_item_get_comment(m_item);
+	if (comment)
+	{
+		gchar* normalized = g_utf8_normalize(comment, -1, G_NORMALIZE_DEFAULT);
+		gchar* utf8 = g_utf8_casefold(normalized, -1);
+		m_search_text += utf8;
+		g_free(utf8);
+		g_free(normalized);
+	}
+
+	return m_search_text.c_str();
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/launcher.hpp b/src/launcher.hpp
index b27a633..71776d5 100644
--- a/src/launcher.hpp
+++ b/src/launcher.hpp
@@ -17,6 +17,7 @@
 #ifndef WHISKERMENU_LAUNCHER_HPP
 #define WHISKERMENU_LAUNCHER_HPP
 
+#include <map>
 #include <string>
 
 extern "C"
@@ -44,8 +45,6 @@ public:
 		return m_text;
 	}
 
-	const gchar* get_search_text();
-
 	GarconMenuItem* get_item() const
 	{
 		return m_item;
@@ -53,6 +52,8 @@ public:
 
 	void run(GdkScreen* screen) const;
 
+	unsigned int search(const std::string& filter_string);
+
 	static bool get_show_name();
 	static bool get_show_description();
 	static void set_show_name(bool show);
@@ -62,11 +63,14 @@ private:
 	Launcher(const Launcher& launcher);
 	Launcher& operator=(const Launcher& launcher);
 
+	const gchar* get_search_text();
+
 private:
 	GarconMenuItem* m_item;
 	gchar* m_icon;
 	gchar* m_text;
 	std::string m_search_text;
+	std::map<std::string, unsigned int> m_searches;
 };
 
 }
diff --git a/src/search_page.cpp b/src/search_page.cpp
index facf0b7..b748032 100644
--- a/src/search_page.cpp
+++ b/src/search_page.cpp
@@ -124,15 +124,15 @@ bool SearchPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
 	// Check if launcher search string contains text
 	Launcher* launcher = NULL;
 	gtk_tree_model_get(model, iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
-	gchar* result = g_strstr_len(launcher->get_search_text(), -1, m_filter_string.c_str());
+	unsigned int index = launcher->search(m_filter_string);
 
 	// Check if launcher search string starts with text
-	if (!m_filter_matching_path && (result == launcher->get_search_text()))
+	if (!m_filter_matching_path && (index == 0))
 	{
 		m_filter_matching_path = gtk_tree_model_get_path(model, iter);
 	}
 
-	return result != NULL;
+	return index != UINT_MAX;
 }
 
 //-----------------------------------------------------------------------------

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list