[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 55/473: Make fetching search results constant.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:53:45 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 e95b0304c0e62a30165657b339c6ccc520b73ec2
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Jul 1 19:30:38 2013 -0400

    Make fetching search results constant.
---
 src/launcher.cpp    |   13 ++++++++++---
 src/launcher.hpp    |    4 +++-
 src/search_page.cpp |   22 ++++++++++++++++++++--
 src/search_page.hpp |    2 ++
 4 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/launcher.cpp b/src/launcher.cpp
index 79707bb..6e56194 100644
--- a/src/launcher.cpp
+++ b/src/launcher.cpp
@@ -160,6 +160,14 @@ Launcher::~Launcher()
 
 //-----------------------------------------------------------------------------
 
+unsigned int Launcher::get_search_results(const std::string& filter_string) const
+{
+	std::map<std::string, unsigned int>::const_iterator i = m_searches.find(filter_string);
+	return (i != m_searches.end()) ? i->second : UINT_MAX;
+}
+
+//-----------------------------------------------------------------------------
+
 void Launcher::run(GdkScreen* screen) const
 {
 	const gchar* string = garcon_menu_item_get_command(m_item);
@@ -243,13 +251,13 @@ void Launcher::run(GdkScreen* screen) const
 
 //-----------------------------------------------------------------------------
 
-unsigned int Launcher::search(const std::string& filter_string)
+void Launcher::search(const std::string& filter_string)
 {
 	// Check if search has been done before
 	std::map<std::string, unsigned int>::const_iterator i = m_searches.find(filter_string);
 	if (i != m_searches.end())
 	{
-		return i->second;
+		return;
 	}
 
 	// Check if search will fail because a shorter version has failed before
@@ -322,7 +330,6 @@ unsigned int Launcher::search(const std::string& filter_string)
 	}
 
 	m_searches.insert(std::make_pair(filter_string, index));
-	return index;
 }
 
 //-----------------------------------------------------------------------------
diff --git a/src/launcher.hpp b/src/launcher.hpp
index 71776d5..cdbae15 100644
--- a/src/launcher.hpp
+++ b/src/launcher.hpp
@@ -50,9 +50,11 @@ public:
 		return m_item;
 	}
 
+	unsigned int get_search_results(const std::string& filter_string) const;
+
 	void run(GdkScreen* screen) const;
 
-	unsigned int search(const std::string& filter_string);
+	void search(const std::string& filter_string);
 
 	static bool get_show_name();
 	static bool get_show_description();
diff --git a/src/search_page.cpp b/src/search_page.cpp
index 4ddce03..498eee6 100644
--- a/src/search_page.cpp
+++ b/src/search_page.cpp
@@ -66,6 +66,12 @@ void SearchPage::set_filter(const gchar* filter)
 		return;
 	}
 
+	// Create search results
+	for (std::vector<Launcher*>::iterator i = m_launchers.begin(), end = m_launchers.end(); i != end; ++i)
+	{
+		(*i)->search(m_filter_string);
+	}
+
 	// Apply filter
 	GtkTreeModel* filter_model = gtk_tree_model_sort_get_model(m_sort_model);
 	get_view()->unset_model();
@@ -93,6 +99,17 @@ void SearchPage::set_filter(const gchar* filter)
 
 void SearchPage::set_menu_items(GtkTreeModel* model)
 {
+	// loop over every single item in model
+	GtkTreeIter iter;
+	bool valid = gtk_tree_model_get_iter_first(model, &iter);
+	while (valid)
+	{
+		Launcher* launcher = NULL;
+		gtk_tree_model_get(model, &iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+		m_launchers.push_back(launcher);
+		valid = gtk_tree_model_iter_next(model, &iter);
+	}
+
 	unset_search_model();
 	set_model(model);
 	set_search_model(get_view()->get_model());
@@ -102,6 +119,7 @@ void SearchPage::set_menu_items(GtkTreeModel* model)
 
 void SearchPage::unset_menu_items()
 {
+	m_launchers.clear();
 	unset_search_model();
 	unset_model();
 }
@@ -118,7 +136,7 @@ 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);
-	unsigned int index = launcher->search(m_filter_string);
+	unsigned int index = launcher->get_search_results(m_filter_string);
 
 	return index != UINT_MAX;
 }
@@ -133,7 +151,7 @@ gint SearchPage::on_sort(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, Se
 	Launcher* launcher_b = NULL;
 	gtk_tree_model_get(model, b, LauncherModel::COLUMN_LAUNCHER, &launcher_b, -1);
 
-	return launcher_a->search(page->m_filter_string) - launcher_b->search(page->m_filter_string);
+	return launcher_a->get_search_results(page->m_filter_string) - launcher_b->get_search_results(page->m_filter_string);
 }
 
 //-----------------------------------------------------------------------------
diff --git a/src/search_page.hpp b/src/search_page.hpp
index 1c3306f..16f660a 100644
--- a/src/search_page.hpp
+++ b/src/search_page.hpp
@@ -21,6 +21,7 @@
 #include "slot.hpp"
 
 #include <string>
+#include <vector>
 
 namespace WhiskerMenu
 {
@@ -50,6 +51,7 @@ private:
 private:
 	std::string m_filter_string;
 	GtkTreeModelSort* m_sort_model;
+	std::vector<Launcher*> m_launchers;
 };
 
 }

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


More information about the Xfce4-commits mailing list