[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 127/473: Move category out of applications page.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:54:57 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 e2a3c159570a7382837cf1956371794388a55b2c
Author: Graeme Gott <graeme at gottcode.org>
Date:   Fri Jul 19 11:03:48 2013 -0400

    Move category out of applications page.
---
 src/CMakeLists.txt        |    1 +
 src/applications_page.cpp |   78 +++++++++------------------------------------
 src/applications_page.hpp |   23 ++-----------
 src/category.cpp          |   52 ++++++++++++++++++++++++++++++
 src/category.hpp          |   67 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 137 insertions(+), 84 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 00f78c7..dade67d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -63,6 +63,7 @@ endif()
 
 add_library(whiskermenu SHARED
     applications_page.cpp
+    category.cpp
     configuration_dialog.cpp
     favorites_page.cpp
     filter_page.cpp
diff --git a/src/applications_page.cpp b/src/applications_page.cpp
index 51b12c6..09fdcdc 100644
--- a/src/applications_page.cpp
+++ b/src/applications_page.cpp
@@ -16,15 +16,13 @@
 
 #include "applications_page.hpp"
 
+#include "category.hpp"
 #include "launcher.hpp"
 #include "launcher_model.hpp"
 #include "launcher_view.hpp"
 #include "menu.hpp"
 #include "section_button.hpp"
 
-#include <algorithm>
-#include <map>
-
 extern "C"
 {
 #include <libxfce4util/libxfce4util.h>
@@ -34,25 +32,6 @@ using namespace WhiskerMenu;
 
 //-----------------------------------------------------------------------------
 
-ApplicationsPage::Category::Category(GarconMenuDirectory* directory)
-{
-	// Fetch icon
-	const gchar* icon = garcon_menu_directory_get_icon_name(directory);
-	if (G_LIKELY(icon))
-	{
-		m_icon.assign(icon);
-	}
-
-	// Fetch text
-	const gchar* text = garcon_menu_directory_get_name(directory);
-	if (G_LIKELY(text))
-	{
-		m_text.assign(text);
-	}
-}
-
-//-----------------------------------------------------------------------------
-
 ApplicationsPage::ApplicationsPage(Menu* menu) :
 	FilterPage(menu),
 	m_garcon_menu(NULL),
@@ -98,21 +77,17 @@ void ApplicationsPage::apply_filter(GtkToggleButton* togglebutton)
 	}
 
 	// Find category matching button
-	std::map<SectionButton*, Category*>::const_iterator i, end = m_category_buttons.end();
-	for (i = m_category_buttons.begin(); i != end; ++i)
+	m_current_category = NULL;
+	for (std::vector<Category*>::const_iterator i = m_categories.begin(), end = m_categories.end(); i != end; ++i)
 	{
-		if (GTK_TOGGLE_BUTTON(i->first->get_button()) == togglebutton)
+		if (GTK_TOGGLE_BUTTON((*i)->get_button()->get_button()) == togglebutton)
 		{
+			m_current_category = *i;
 			break;
 		}
 	}
-	if (i == end)
-	{
-		return;
-	}
 
 	// Apply filter
-	m_current_category = i->second;
 	refilter();
 	m_current_category = NULL;
 }
@@ -133,8 +108,7 @@ bool ApplicationsPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
 		return false;
 	}
 
-	const std::vector<Launcher*>& category = m_categories[m_current_category];
-	return std::find(category.begin(), category.end(), launcher) != category.end();
+	return m_current_category->contains(launcher);
 }
 
 //-----------------------------------------------------------------------------
@@ -198,15 +172,9 @@ void ApplicationsPage::load_applications()
 void ApplicationsPage::clear_applications()
 {
 	// Free categories
-	for (std::map<SectionButton*, Category*>::iterator i = m_category_buttons.begin(), end = m_category_buttons.end(); i != end; ++i)
-	{
-		delete i->first;
-	}
-	m_category_buttons.clear();
-
-	for (std::map<Category*, std::vector<Launcher*> >::iterator i = m_categories.begin(), end = m_categories.end(); i != end; ++i)
+	for (std::vector<Category*>::iterator i = m_categories.begin(), end = m_categories.end(); i != end; ++i)
 	{
-		delete i->first;
+		delete *i;
 	}
 	m_categories.clear();
 
@@ -251,6 +219,7 @@ void ApplicationsPage::load_menu(GarconMenu* menu)
 	if (first_level)
 	{
 		m_current_category = new Category(directory);
+		m_categories.push_back(m_current_category);
 	}
 	if (directory)
 	{
@@ -276,15 +245,9 @@ void ApplicationsPage::load_menu(GarconMenu* menu)
 	if (first_level)
 	{
 		// Free unused categories
-		std::map<Category*, std::vector<Launcher*> >::iterator i = m_categories.find(m_current_category);
-		if (i == m_categories.end())
-		{
-			delete m_current_category;
-		}
-		// Do not track empty categories
-		else if (i->second.empty())
+		if (m_current_category->empty())
 		{
-			m_categories.erase(i);
+			m_categories.erase(std::find(m_categories.begin(), m_categories.end(), m_current_category));
 			delete m_current_category;
 		}
 		m_current_category = NULL;
@@ -315,7 +278,7 @@ void ApplicationsPage::load_menu_item(const gchar* desktop_id, GarconMenuItem* m
 	// Add menu item to current category
 	if (page->m_current_category)
 	{
-		page->m_categories[page->m_current_category].push_back(iter->second);
+		page->m_current_category->push_back(iter->second);
 	}
 
 	// Listen for menu changes
@@ -331,24 +294,13 @@ void ApplicationsPage::load_categories()
 	// Add button for all applications
 	SectionButton* all_button = new SectionButton("applications-other", _("All"));
 	g_signal_connect(all_button->get_button(), "toggled", G_CALLBACK(ApplicationsPage::apply_filter_slot), this);
-	m_category_buttons[all_button] = NULL;
 	category_buttons.push_back(all_button);
 
-	// Create sorted list of categories
-	std::map<std::string, Category*> sorted_categories;
-	for (std::map<Category*, std::vector<Launcher*> >::const_iterator i = m_categories.begin(), end = m_categories.end(); i != end; ++i)
-	{
-		gchar* collation_key = g_utf8_collate_key(i->first->get_text(), -1);
-		sorted_categories[collation_key] = i->first;
-		g_free(collation_key);
-	}
-
-	// Add buttons for sorted categories
-	for (std::map<std::string, Category*>::const_iterator i = sorted_categories.begin(), end = sorted_categories.end(); i != end; ++i)
+	// Add buttons for categories
+	for (std::vector<Category*>::const_iterator i = m_categories.begin(), end = m_categories.end(); i != end; ++i)
 	{
-		SectionButton* category_button = new SectionButton(i->second->get_icon(), i->second->get_text());
+		SectionButton* category_button = (*i)->get_button();
 		g_signal_connect(category_button->get_button(), "toggled", G_CALLBACK(ApplicationsPage::apply_filter_slot), this);
-		m_category_buttons[category_button] = i->second;
 		category_buttons.push_back(category_button);
 	}
 
diff --git a/src/applications_page.hpp b/src/applications_page.hpp
index e8a05b5..ded1d83 100644
--- a/src/applications_page.hpp
+++ b/src/applications_page.hpp
@@ -31,6 +31,7 @@ extern "C"
 namespace WhiskerMenu
 {
 
+class Category;
 class Launcher;
 class LauncherView;
 class Menu;
@@ -38,25 +39,6 @@ class SectionButton;
 
 class ApplicationsPage : public FilterPage
 {
-	class Category
-	{
-	public:
-		explicit Category(GarconMenuDirectory* directory);
-
-		const gchar* get_icon() const
-		{
-			return m_icon.c_str();
-		}
-
-		const gchar* get_text() const
-		{
-			return m_text.c_str();
-		}
-
-	private:
-		std::string m_icon;
-		std::string m_text;
-	};
 
 public:
 	explicit ApplicationsPage(Menu* menu);
@@ -78,8 +60,7 @@ private:
 private:
 	GarconMenu* m_garcon_menu;
 	Category* m_current_category;
-	std::map<SectionButton*, Category*> m_category_buttons;
-	std::map<Category*, std::vector<Launcher*> > m_categories;
+	std::vector<Category*> m_categories;
 	std::map<std::string, Launcher*> m_items;
 	bool m_loaded;
 
diff --git a/src/category.cpp b/src/category.cpp
new file mode 100644
index 0000000..b326a3e
--- /dev/null
+++ b/src/category.cpp
@@ -0,0 +1,52 @@
+// Copyright (C) 2013 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
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library.  If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "category.hpp"
+
+#include "section_button.hpp"
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+Category::Category(GarconMenuDirectory* directory)
+{
+	// Fetch icon
+	const gchar* icon = garcon_menu_directory_get_icon_name(directory);
+	if (G_UNLIKELY(!icon))
+	{
+		icon = "";
+	}
+
+	// Fetch text
+	const gchar* text = garcon_menu_directory_get_name(directory);
+	if (G_UNLIKELY(!text))
+	{
+		text = "";
+	}
+
+	// Create button
+	m_button = new SectionButton(icon, text);
+}
+
+//-----------------------------------------------------------------------------
+
+Category::~Category()
+{
+	delete m_button;
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/category.hpp b/src/category.hpp
new file mode 100644
index 0000000..341daa6
--- /dev/null
+++ b/src/category.hpp
@@ -0,0 +1,67 @@
+// Copyright (C) 2013 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
+// the Free Software Foundation, either version 2 of the License, or
+// at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library.  If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef WHISKERMENU_CATEGORY_HPP
+#define WHISKERMENU_CATEGORY_HPP
+
+#include <algorithm>
+#include <vector>
+
+extern "C"
+{
+#include <garcon/garcon.h>
+}
+
+namespace WhiskerMenu
+{
+
+class Launcher;
+class SectionButton;
+
+class Category
+{
+public:
+	explicit Category(GarconMenuDirectory* directory);
+	~Category();
+
+	SectionButton* get_button() const
+	{
+		return m_button;
+	}
+
+	bool contains(Launcher* launcher) const
+	{
+		return std::find(m_items.begin(), m_items.end(), launcher) != m_items.end();
+	}
+
+	bool empty() const
+	{
+		return m_items.empty();
+	}
+
+	void push_back(Launcher* launcher)
+	{
+		m_items.push_back(launcher);
+	}
+
+private:
+	std::vector<Launcher*> m_items;
+	SectionButton* m_button;
+};
+
+}
+
+#endif // WHISKERMENU_CATEGORY_HPP

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


More information about the Xfce4-commits mailing list