[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 38/473: Fix excessive menu reloading when apps are installed.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:53:28 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 18d3f3510dd7090345f802ccff8641360cef80e8
Author: Graeme Gott <graeme at gottcode.org>
Date:   Thu Jun 27 12:34:16 2013 -0400

    Fix excessive menu reloading when apps are installed.
---
 src/applications_page.cpp |   29 ++++++++++++++++++++++-------
 src/applications_page.hpp |    8 ++++++--
 src/menu.cpp              |    5 ++++-
 src/panel_plugin.cpp      |    2 +-
 4 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/applications_page.cpp b/src/applications_page.cpp
index fd45561..7013155 100644
--- a/src/applications_page.cpp
+++ b/src/applications_page.cpp
@@ -48,7 +48,8 @@ ApplicationsPage::Category::Category(GarconMenuDirectory* directory)
 ApplicationsPage::ApplicationsPage(Menu* menu) :
 	FilterPage(menu),
 	m_garcon_menu(NULL),
-	m_current_category(NULL)
+	m_current_category(NULL),
+	m_loaded(false)
 {
 	// Set desktop environment for applications
 	const gchar* desktop = g_getenv("XDG_CURRENT_DESKTOP");
@@ -115,8 +116,13 @@ bool ApplicationsPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
 
 //-----------------------------------------------------------------------------
 
-void ApplicationsPage::reload_applications()
+void ApplicationsPage::load_applications()
 {
+	if (m_loaded)
+	{
+		return;
+	}
+
 	// Remove previous menu data
 	clear_applications();
 
@@ -125,7 +131,7 @@ void ApplicationsPage::reload_applications()
 	g_object_ref(m_garcon_menu);
 	if (garcon_menu_load(m_garcon_menu, NULL, NULL))
 	{
-		g_signal_connect_swapped(m_garcon_menu, "reload-required", SLOT_CALLBACK(ApplicationsPage::reload_applications), this);
+		g_signal_connect_swapped(m_garcon_menu, "reload-required", SLOT_CALLBACK(ApplicationsPage::invalidate_applications), this);
 		load_menu(m_garcon_menu);
 	}
 
@@ -149,10 +155,19 @@ void ApplicationsPage::reload_applications()
 	set_model(model.get_model());
 
 	// Update filters
-	reload_categories();
+	load_categories();
 
 	// Update menu items of other panels
 	get_menu()->set_items(m_items);
+
+	m_loaded = true;
+}
+
+//-----------------------------------------------------------------------------
+
+void ApplicationsPage::invalidate_applications()
+{
+	m_loaded = false;
 }
 
 //-----------------------------------------------------------------------------
@@ -256,7 +271,7 @@ void ApplicationsPage::load_menu(GarconMenu* menu)
 	}
 
 	// Listen for menu changes
-	g_signal_connect_swapped(menu, "directory-changed", SLOT_CALLBACK(ApplicationsPage::reload_applications), this);
+	g_signal_connect_swapped(menu, "directory-changed", SLOT_CALLBACK(ApplicationsPage::invalidate_applications), this);
 }
 
 //-----------------------------------------------------------------------------
@@ -284,12 +299,12 @@ void ApplicationsPage::load_menu_item(const gchar* desktop_id, GarconMenuItem* m
 	}
 
 	// Listen for menu changes
-	g_signal_connect_swapped(menu_item, "changed", SLOT_CALLBACK(ApplicationsPage::reload_applications), page);
+	g_signal_connect_swapped(menu_item, "changed", SLOT_CALLBACK(ApplicationsPage::invalidate_applications), page);
 }
 
 //-----------------------------------------------------------------------------
 
-void ApplicationsPage::reload_categories()
+void ApplicationsPage::load_categories()
 {
 	std::vector<GtkRadioButton*> category_buttons;
 
diff --git a/src/applications_page.hpp b/src/applications_page.hpp
index 7fb1897..587e5f8 100644
--- a/src/applications_page.hpp
+++ b/src/applications_page.hpp
@@ -62,7 +62,10 @@ public:
 	ApplicationsPage(Menu* menu);
 	~ApplicationsPage();
 
-	SLOT_0(void, ApplicationsPage, reload_applications);
+	void load_applications();
+
+public:
+	SLOT_0(void, ApplicationsPage, invalidate_applications);
 
 private:
 	SLOT_1(void, ApplicationsPage, apply_filter, GtkToggleButton*);
@@ -72,7 +75,7 @@ private:
 	void clear_applications();
 	void load_menu(GarconMenu* menu);
 	static void load_menu_item(const gchar* desktop_id, GarconMenuItem* menu_item, ApplicationsPage* page);
-	void reload_categories();
+	void load_categories();
 
 private:
 	GarconMenu* m_garcon_menu;
@@ -80,6 +83,7 @@ private:
 	std::map<GtkRadioButton*, Category*> m_category_buttons;
 	std::map<Category*, std::vector<Launcher*> > m_categories;
 	std::map<std::string, Launcher*> m_items;
+	bool m_loaded;
 };
 
 }
diff --git a/src/menu.cpp b/src/menu.cpp
index 4cd3ab2..45b31bc 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -168,7 +168,7 @@ Menu::Menu(XfceRc* settings) :
 	gtk_box_pack_start(m_sidebar_box, gtk_hseparator_new(), false, true, 0);
 
 	// Populate app menu
-	m_applications->reload_applications();
+	m_applications->load_applications();
 
 	// Show widgets
 	gtk_widget_show_all(GTK_WIDGET(m_vbox));
@@ -222,6 +222,9 @@ void Menu::hide()
 
 void Menu::show(GtkWidget* parent, bool horizontal)
 {
+	// Make sure applications list is current; does nothing unless list has changed
+	m_applications->load_applications();
+
 	// Reset mouse cursor by forcing favorites to hide
 	gtk_widget_show(m_favorites->get_widget());
 
diff --git a/src/panel_plugin.cpp b/src/panel_plugin.cpp
index bea95f0..76338b7 100644
--- a/src/panel_plugin.cpp
+++ b/src/panel_plugin.cpp
@@ -101,7 +101,7 @@ PanelPlugin::~PanelPlugin()
 void PanelPlugin::reload()
 {
 	m_menu->hide();
-	m_menu->get_applications()->reload_applications();
+	m_menu->get_applications()->invalidate_applications();
 }
 
 //-----------------------------------------------------------------------------

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


More information about the Xfce4-commits mailing list