[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 05/05: Prioritize favorites and recent in search results.

noreply at xfce.org noreply at xfce.org
Mon Sep 21 17:42:39 CEST 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 3ed8b3e748b4fa5b03fed5e07a2b6f37c6a18d2e
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Sep 21 10:35:46 2015 -0400

    Prioritize favorites and recent in search results.
---
 panel-plugin/favorites-page.cpp |   18 +++++++++++++++++-
 panel-plugin/launcher.cpp       |   28 +++++++++++++++++++++++-----
 panel-plugin/launcher.h         |    8 ++++++++
 panel-plugin/recent-page.cpp    |   27 ++++++++++++++++++++++++++-
 panel-plugin/recent-page.h      |    3 ++-
 5 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/panel-plugin/favorites-page.cpp b/panel-plugin/favorites-page.cpp
index a682c9a..b94dba4 100644
--- a/panel-plugin/favorites-page.cpp
+++ b/panel-plugin/favorites-page.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2015 Graeme Gott <graeme at gottcode.org>
  *
  * This library is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -67,6 +67,8 @@ void FavoritesPage::add(Launcher* launcher)
 		return;
 	}
 
+	launcher->set_flag(Launcher::FavoriteFlag, true);
+
 	// Append to list of items
 	GtkListStore* store = GTK_LIST_STORE(get_view()->get_model());
 	gtk_list_store_insert_with_values(
@@ -81,6 +83,11 @@ void FavoritesPage::add(Launcher* launcher)
 
 void FavoritesPage::remove(Launcher* launcher)
 {
+	if (launcher)
+	{
+		launcher->set_flag(Launcher::FavoriteFlag, false);
+	}
+
 	GtkTreeModel* model = GTK_TREE_MODEL(get_view()->get_model());
 	GtkListStore* store = GTK_LIST_STORE(model);
 	GtkTreeIter iter;
@@ -109,6 +116,15 @@ void FavoritesPage::set_menu_items()
 	g_signal_connect_slot(model, "row-inserted", &FavoritesPage::on_row_inserted, this);
 	g_signal_connect_slot(model, "row-deleted", &FavoritesPage::on_row_deleted, this);
 	g_object_unref(model);
+
+	for (std::vector<std::string>::size_type i = 0, end = wm_settings->favorites.size(); i < end; ++i)
+	{
+		Launcher* launcher = get_window()->get_applications()->get_application(wm_settings->favorites[i]);
+		if (launcher)
+		{
+			launcher->set_flag(Launcher::FavoriteFlag, true);
+		}
+	}
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/launcher.cpp b/panel-plugin/launcher.cpp
index f35978a..197fd75 100644
--- a/panel-plugin/launcher.cpp
+++ b/panel-plugin/launcher.cpp
@@ -100,7 +100,8 @@ static void replace_with_quoted_string(std::string& command, size_t& index, gcha
 //-----------------------------------------------------------------------------
 
 Launcher::Launcher(GarconMenuItem* item) :
-	m_item(item)
+	m_item(item),
+	m_search_flags(0)
 {
 	// Fetch icon
 	const gchar* icon = garcon_menu_item_get_icon_name(m_item);
@@ -278,34 +279,51 @@ void Launcher::run(GdkScreen* screen) const
 
 guint Launcher::search(const Query& query)
 {
+	// Prioritize matches in favorites and recent, then favories, and then recent
+	const guint flags = 3 - m_search_flags;
+
 	// Sort matches in names first
 	guint match = query.match(m_search_name);
 	if (match != G_MAXUINT)
 	{
-		return match | 0x400;
+		return match | flags | 0x400;
 	}
 
 	match = query.match(m_search_generic_name);
 	if (match != G_MAXUINT)
 	{
-		return match | 0x800;
+		return match | flags | 0x800;
 	}
 
 	// Sort matches in comments next
 	match = query.match(m_search_comment);
 	if (match != G_MAXUINT)
 	{
-		return match | 0x1000;
+		return match | flags | 0x1000;
 	}
 
 	// Sort matches in executables last
 	match = query.match(m_search_command);
 	if (match != G_MAXUINT)
 	{
-		return match | 0x2000;
+		return match | flags | 0x2000;
 	}
 
 	return G_MAXUINT;
 }
 
 //-----------------------------------------------------------------------------
+
+void Launcher::set_flag(SearchFlag flag, bool enabled)
+{
+	if (enabled)
+	{
+		m_search_flags |= flag;
+	}
+	else
+	{
+		m_search_flags &= ~flag;
+	}
+}
+
+//-----------------------------------------------------------------------------
diff --git a/panel-plugin/launcher.h b/panel-plugin/launcher.h
index 75f6b67..d13733d 100644
--- a/panel-plugin/launcher.h
+++ b/panel-plugin/launcher.h
@@ -66,6 +66,13 @@ public:
 
 	guint search(const Query& query);
 
+	enum SearchFlag
+	{
+		RecentFlag = 0x1,
+		FavoriteFlag = 0x2
+	};
+	void set_flag(SearchFlag flag, bool enabled);
+
 private:
 	GarconMenuItem* m_item;
 	const gchar* m_display_name;
@@ -73,6 +80,7 @@ private:
 	std::string m_search_generic_name;
 	std::string m_search_comment;
 	std::string m_search_command;
+	guint m_search_flags;
 };
 
 }
diff --git a/panel-plugin/recent-page.cpp b/panel-plugin/recent-page.cpp
index 196d1f6..eb9b7b9 100644
--- a/panel-plugin/recent-page.cpp
+++ b/panel-plugin/recent-page.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2015 Graeme Gott <graeme at gottcode.org>
  *
  * This library is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -58,6 +58,7 @@ void RecentPage::add(Launcher* launcher)
 	{
 		return;
 	}
+	launcher->set_flag(Launcher::RecentFlag, true);
 
 	std::string desktop_id = launcher->get_desktop_id();
 	if (!wm_settings->recent.empty())
@@ -110,6 +111,12 @@ void RecentPage::enforce_item_count()
 	GtkListStore* store = GTK_LIST_STORE(get_view()->get_model());
 	for (size_t i = wm_settings->recent.size() - 1, end = wm_settings->recent_items_max; i >= end; --i)
 	{
+		Launcher* launcher = get_window()->get_applications()->get_application(wm_settings->recent[i]);
+		if (launcher)
+		{
+			launcher->set_flag(Launcher::RecentFlag, false);
+		}
+
 		GtkTreeIter iter;
 		if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, i))
 		{
@@ -123,11 +130,27 @@ void RecentPage::enforce_item_count()
 
 //-----------------------------------------------------------------------------
 
+void RecentPage::flag_items(bool enabled)
+{
+	for (std::vector<std::string>::size_type i = 0, end = wm_settings->recent.size(); i < end; ++i)
+	{
+		Launcher* launcher = get_window()->get_applications()->get_application(wm_settings->recent[i]);
+		if (launcher)
+		{
+			launcher->set_flag(Launcher::RecentFlag, enabled);
+		}
+	}
+}
+
+//-----------------------------------------------------------------------------
+
 void RecentPage::set_menu_items()
 {
 	GtkTreeModel* model = get_window()->get_applications()->create_launcher_model(wm_settings->recent);
 	get_view()->set_model(model);
 	g_object_unref(model);
+
+	flag_items(true);
 }
 
 //-----------------------------------------------------------------------------
@@ -156,6 +179,8 @@ void RecentPage::extend_context_menu(GtkWidget* menu)
 
 void RecentPage::clear_menu()
 {
+	flag_items(false);
+
 	gtk_list_store_clear(GTK_LIST_STORE(get_view()->get_model()));
 	wm_settings->recent.clear();
 	wm_settings->set_modified();
diff --git a/panel-plugin/recent-page.h b/panel-plugin/recent-page.h
index d0c079d..17521ab 100644
--- a/panel-plugin/recent-page.h
+++ b/panel-plugin/recent-page.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2015 Graeme Gott <graeme at gottcode.org>
  *
  * This library is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@ public:
 
 	void add(Launcher* launcher);
 	void enforce_item_count();
+	void flag_items(bool enabled);
 	void set_menu_items();
 	void unset_menu_items();
 

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


More information about the Xfce4-commits mailing list