[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 92/473: Add menu actions to sort favorites alphabetically.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:54: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 179355f5ba9720555ed3d16aac6f0968a6339b1b
Author: Graeme Gott <graeme at gottcode.org>
Date:   Fri Jul 12 14:34:10 2013 -0400

    Add menu actions to sort favorites alphabetically.
---
 src/favorites_page.cpp |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/favorites_page.hpp |   10 ++++++++
 src/list_page.cpp      |    8 ++++++
 src/list_page.hpp      |    8 ++++++
 4 files changed, 90 insertions(+)

diff --git a/src/favorites_page.cpp b/src/favorites_page.cpp
index 99f3138..416ae76 100644
--- a/src/favorites_page.cpp
+++ b/src/favorites_page.cpp
@@ -16,9 +16,11 @@
 
 #include "favorites_page.hpp"
 
+#include "applications_page.hpp"
 #include "launcher.hpp"
 #include "launcher_model.hpp"
 #include "launcher_view.hpp"
+#include "menu.hpp"
 
 #include <algorithm>
 
@@ -62,3 +64,65 @@ void FavoritesPage::add(Launcher* launcher)
 }
 
 //-----------------------------------------------------------------------------
+
+void FavoritesPage::extend_context_menu(GtkWidget* menu)
+{
+	GtkWidget* menuitem = gtk_separator_menu_item_new();
+	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
+	menuitem = gtk_menu_item_new_with_label(_("Sort Alphabetically A-Z"));
+	g_signal_connect(menuitem, "activate", SLOT_CALLBACK(FavoritesPage::sort_ascending), this);
+	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
+	menuitem = gtk_menu_item_new_with_label(_("Sort Alphabetically Z-A"));
+	g_signal_connect(menuitem, "activate", SLOT_CALLBACK(FavoritesPage::sort_descending), this);
+	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+}
+
+//-----------------------------------------------------------------------------
+
+void FavoritesPage::sort(std::map<std::string, Launcher*>& items) const
+{
+	const std::vector<std::string>& desktop_ids = get_desktop_ids();
+	for (std::vector<std::string>::const_iterator i = desktop_ids.begin(), end = desktop_ids.end(); i != end; ++i)
+	{
+		Launcher* launcher = get_menu()->get_applications()->get_application(*i);
+		if (!launcher)
+		{
+			continue;
+		}
+		gchar* collation_key = g_utf8_collate_key(launcher->get_text(), -1);
+		items[collation_key] = launcher;
+		g_free(collation_key);
+	}
+}
+
+//-----------------------------------------------------------------------------
+
+void FavoritesPage::sort_ascending(GtkMenuItem*)
+{
+	std::vector<std::string> desktop_ids;
+	std::map<std::string, Launcher*> items;
+	sort(items);
+	for (std::map<std::string, Launcher*>::const_iterator i = items.begin(), end = items.end(); i != end; ++i)
+	{
+		desktop_ids.push_back(i->second->get_desktop_id());
+	}
+	set_desktop_ids(desktop_ids);
+}
+
+//-----------------------------------------------------------------------------
+
+void FavoritesPage::sort_descending(GtkMenuItem*)
+{
+	std::vector<std::string> desktop_ids;
+	std::map<std::string, Launcher*> items;
+	sort(items);
+	for (std::map<std::string, Launcher*>::const_reverse_iterator i = items.rbegin(), end = items.rend(); i != end; ++i)
+	{
+		desktop_ids.push_back(i->second->get_desktop_id());
+	}
+	set_desktop_ids(desktop_ids);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/favorites_page.hpp b/src/favorites_page.hpp
index 298be13..de0f8cf 100644
--- a/src/favorites_page.hpp
+++ b/src/favorites_page.hpp
@@ -19,6 +19,8 @@
 
 #include "list_page.hpp"
 
+#include "slot.hpp"
+
 namespace WhiskerMenu
 {
 
@@ -30,6 +32,14 @@ public:
 	FavoritesPage(XfceRc* settings, Menu* menu);
 
 	void add(Launcher* launcher);
+
+private:
+	void extend_context_menu(GtkWidget* menu);
+	void sort(std::map<std::string, Launcher*>& items) const;
+
+private:
+	SLOT_1(void, FavoritesPage, sort_ascending, GtkMenuItem*);
+	SLOT_1(void, FavoritesPage, sort_descending, GtkMenuItem*);
 };
 
 }
diff --git a/src/list_page.cpp b/src/list_page.cpp
index c5a2353..5f93535 100644
--- a/src/list_page.cpp
+++ b/src/list_page.cpp
@@ -143,6 +143,14 @@ void ListPage::unset_menu_items()
 
 //-----------------------------------------------------------------------------
 
+void ListPage::set_desktop_ids(const std::vector<std::string>& desktop_ids)
+{
+	m_desktop_ids = desktop_ids;
+	set_menu_items();
+}
+
+//-----------------------------------------------------------------------------
+
 void ListPage::on_row_changed(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter)
 {
 	size_t pos = gtk_tree_path_get_indices(path)[0];
diff --git a/src/list_page.hpp b/src/list_page.hpp
index 3f721f0..a2c6a2f 100644
--- a/src/list_page.hpp
+++ b/src/list_page.hpp
@@ -53,6 +53,14 @@ public:
 	void set_menu_items();
 	void unset_menu_items();
 
+protected:
+	const std::vector<std::string>& get_desktop_ids() const
+	{
+		return m_desktop_ids;
+	}
+
+	void set_desktop_ids(const std::vector<std::string>& desktop_ids);
+
 private:
 	SLOT_3(void, ListPage, on_row_changed, GtkTreeModel*, GtkTreePath*, GtkTreeIter*);
 	SLOT_3(void, ListPage, on_row_inserted, GtkTreeModel*, GtkTreePath*, GtkTreeIter*);

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


More information about the Xfce4-commits mailing list