[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 150/473: Add support for separators.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:55:20 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 ffa1d1d906fd8dc8603eaa186fd47ab75a6360d7
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Jul 29 12:03:50 2013 -0400

    Add support for separators.
---
 src/applications_page.cpp |   11 ++++++++++-
 src/category.cpp          |   15 ++++++++++++++-
 src/category.hpp          |   12 ++++++++++--
 src/launcher_model.cpp    |   21 +++++++++++++++------
 src/launcher_view.cpp     |   15 +++++++++++++++
 src/launcher_view.hpp     |    1 +
 6 files changed, 65 insertions(+), 10 deletions(-)

diff --git a/src/applications_page.cpp b/src/applications_page.cpp
index 724aeae..4232983 100644
--- a/src/applications_page.cpp
+++ b/src/applications_page.cpp
@@ -94,10 +94,14 @@ void ApplicationsPage::apply_filter(GtkToggleButton* togglebutton)
 	// Apply filter
 	if (category)
 	{
+		get_view()->unset_model();
+		get_view()->set_fixed_height_mode(!category->has_separators());
 		get_view()->set_model(category->get_model());
 	}
 	else
 	{
+		get_view()->unset_model();
+		get_view()->set_fixed_height_mode(true);
 		get_view()->set_model(m_model);
 	}
 }
@@ -154,6 +158,7 @@ void ApplicationsPage::load_applications()
 	}
 	m_model = model.get_model();
 	g_object_ref(m_model);
+	get_view()->set_fixed_height_mode(true);
 	get_view()->set_model(m_model);
 
 	// Update filters
@@ -239,6 +244,10 @@ void ApplicationsPage::load_menu(GarconMenu* menu)
 		{
 			load_menu(GARCON_MENU(li->data));
 		}
+		else if (GARCON_IS_MENU_SEPARATOR(li->data) && m_current_category)
+		{
+			m_current_category->append_separator();
+		}
 	}
 	g_list_free(elements);
 
@@ -279,7 +288,7 @@ void ApplicationsPage::load_menu_item(GarconMenuItem* menu_item)
 	// Add menu item to current category
 	if (m_current_category)
 	{
-		m_current_category->push_back(iter->second);
+		m_current_category->append_item(iter->second);
 	}
 
 	// Listen for menu changes
diff --git a/src/category.cpp b/src/category.cpp
index e0337c3..298360c 100644
--- a/src/category.cpp
+++ b/src/category.cpp
@@ -28,7 +28,8 @@ using namespace WhiskerMenu;
 
 Category::Category(GarconMenuDirectory* directory) :
 	m_button(NULL),
-	m_model(NULL)
+	m_model(NULL),
+	m_has_separators(false)
 {
 	// Fetch icon
 	const gchar* icon = garcon_menu_directory_get_icon_name(directory);
@@ -88,6 +89,18 @@ GtkTreeModel* Category::get_model()
 
 //-----------------------------------------------------------------------------
 
+void Category::append_separator()
+{
+	if (!m_items.empty() && m_items.back())
+	{
+		unset_model();
+		m_items.push_back(NULL);
+		m_has_separators = true;
+	}
+}
+
+//-----------------------------------------------------------------------------
+
 void Category::sort()
 {
 	unset_model();
diff --git a/src/category.hpp b/src/category.hpp
index 614d107..6768af8 100644
--- a/src/category.hpp
+++ b/src/category.hpp
@@ -56,12 +56,19 @@ public:
 		return m_items.empty();
 	}
 
-	void push_back(Launcher* launcher)
+	bool has_separators() const
+	{
+		return m_has_separators;
+	}
+
+	void append_item(Launcher* launcher)
 	{
-		m_items.push_back(launcher);
 		unset_model();
+		m_items.push_back(launcher);
 	}
 
+	void append_separator();
+
 	void sort();
 
 private:
@@ -71,6 +78,7 @@ private:
 	SectionButton* m_button;
 	std::vector<Launcher*> m_items;
 	GtkTreeModel* m_model;
+	bool m_has_separators;
 };
 
 }
diff --git a/src/launcher_model.cpp b/src/launcher_model.cpp
index d308436..7bb0da0 100644
--- a/src/launcher_model.cpp
+++ b/src/launcher_model.cpp
@@ -56,12 +56,21 @@ LauncherModel::~LauncherModel()
 
 void LauncherModel::insert_item(Launcher* launcher, int position)
 {
-	gtk_list_store_insert_with_values(
-			m_model, NULL, position,
-			COLUMN_ICON, launcher->get_icon(),
-			COLUMN_TEXT, launcher->get_text(),
-			COLUMN_LAUNCHER, launcher,
-			-1);
+	if (launcher)
+	{
+		gtk_list_store_insert_with_values(
+				m_model, NULL, position,
+				COLUMN_ICON, launcher->get_icon(),
+				COLUMN_TEXT, launcher->get_text(),
+				COLUMN_LAUNCHER, launcher,
+				-1);
+	}
+	else
+	{
+		gtk_list_store_insert_with_values(
+				m_model, NULL, position,
+				-1);
+	}
 }
 
 //-----------------------------------------------------------------------------
diff --git a/src/launcher_view.cpp b/src/launcher_view.cpp
index 53cdfd3..5eb4f85 100644
--- a/src/launcher_view.cpp
+++ b/src/launcher_view.cpp
@@ -33,6 +33,13 @@ using namespace WhiskerMenu;
 
 static IconSize f_icon_size(IconSize::Small);
 
+static gboolean is_separator(GtkTreeModel* model, GtkTreeIter* iter, gpointer)
+{
+	const gchar* text;
+	gtk_tree_model_get(model, iter, LauncherModel::COLUMN_TEXT, &text, -1);
+	return exo_str_is_empty(text);
+}
+
 //-----------------------------------------------------------------------------
 
 LauncherView::LauncherView() :
@@ -46,6 +53,7 @@ LauncherView::LauncherView() :
 	gtk_tree_view_set_hover_selection(m_view, true);
 	gtk_tree_view_set_enable_search(m_view, false);
 	gtk_tree_view_set_fixed_height_mode(m_view, true);
+	gtk_tree_view_set_row_separator_func(m_view, &is_separator, NULL, NULL);
 	create_column();
 	g_signal_connect(m_view, "key-press-event", G_CALLBACK(LauncherView::on_key_press_event_slot), this);
 	g_signal_connect(m_view, "key-release-event", G_CALLBACK(LauncherView::on_key_release_event_slot), this);
@@ -115,6 +123,13 @@ void LauncherView::set_cursor(GtkTreePath* path)
 
 //-----------------------------------------------------------------------------
 
+void LauncherView::set_fixed_height_mode(bool fixed_height)
+{
+	gtk_tree_view_set_fixed_height_mode(m_view, fixed_height);
+}
+
+//-----------------------------------------------------------------------------
+
 void LauncherView::set_reorderable(bool reorderable)
 {
 	gtk_tree_view_set_reorderable(m_view, reorderable);
diff --git a/src/launcher_view.hpp b/src/launcher_view.hpp
index 587dab0..b4ac8c1 100644
--- a/src/launcher_view.hpp
+++ b/src/launcher_view.hpp
@@ -45,6 +45,7 @@ public:
 	void select_path(GtkTreePath* path);
 	void set_cursor(GtkTreePath* path);
 
+	void set_fixed_height_mode(bool fixed_height);
 	void set_reorderable(bool reorderable);
 	void set_selection_mode(GtkSelectionMode mode);
 

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


More information about the Xfce4-commits mailing list