[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 83/473: Make section button a class.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:54:13 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 0238a3e57e485a24b63969c4bf582b8fa1ff948a
Author: Graeme Gott <graeme at gottcode.org>
Date:   Thu Jul 11 19:41:44 2013 -0400

    Make section button a class.
---
 src/applications_page.cpp    |   28 ++++++++++++++++------------
 src/applications_page.hpp    |    3 ++-
 src/configuration_dialog.cpp |    4 ++--
 src/menu.cpp                 |   32 ++++++++++++++++----------------
 src/menu.hpp                 |    7 ++++---
 src/panel_plugin.cpp         |    4 ++--
 src/section_button.cpp       |   29 ++++++++++++++++++-----------
 src/section_button.hpp       |   40 +++++++++++++++++++++++++++++++++++++---
 8 files changed, 97 insertions(+), 50 deletions(-)

diff --git a/src/applications_page.cpp b/src/applications_page.cpp
index 1992db5..8e93caa 100644
--- a/src/applications_page.cpp
+++ b/src/applications_page.cpp
@@ -84,8 +84,15 @@ ApplicationsPage::~ApplicationsPage()
 void ApplicationsPage::apply_filter(GtkToggleButton* togglebutton)
 {
 	// Find category matching button
-	std::map<GtkRadioButton*, Category*>::const_iterator i = m_category_buttons.find(GTK_RADIO_BUTTON(togglebutton));
-	if (i == m_category_buttons.end())
+	std::map<SectionButton*, Category*>::const_iterator i, end = m_category_buttons.end();
+	for (i = m_category_buttons.begin(); i != end; ++i)
+	{
+		if (GTK_TOGGLE_BUTTON(i->first->get_button()) == togglebutton)
+		{
+			break;
+		}
+	}
+	if (i == end)
 	{
 		return;
 	}
@@ -183,12 +190,9 @@ void ApplicationsPage::invalidate_applications()
 void ApplicationsPage::clear_applications()
 {
 	// Free categories
-	for (std::map<GtkRadioButton*, Category*>::iterator i = m_category_buttons.begin(), end = m_category_buttons.end(); i != end; ++i)
+	for (std::map<SectionButton*, Category*>::iterator i = m_category_buttons.begin(), end = m_category_buttons.end(); i != end; ++i)
 	{
-		if (GTK_IS_WIDGET(i->first))
-		{
-			gtk_widget_destroy(GTK_WIDGET(i->first));
-		}
+		delete i->first;
 	}
 	m_category_buttons.clear();
 
@@ -314,11 +318,11 @@ void ApplicationsPage::load_menu_item(const gchar* desktop_id, GarconMenuItem* m
 
 void ApplicationsPage::load_categories()
 {
-	std::vector<GtkRadioButton*> category_buttons;
+	std::vector<SectionButton*> category_buttons;
 
 	// Add button for all applications
-	GtkRadioButton* all_button = new_section_button("applications-other", _("All"));
-	g_signal_connect(all_button, "toggled", SLOT_CALLBACK(ApplicationsPage::apply_filter), this);
+	SectionButton* all_button = new SectionButton("applications-other", _("All"));
+	g_signal_connect(all_button->get_button(), "toggled", SLOT_CALLBACK(ApplicationsPage::apply_filter), this);
 	m_category_buttons[all_button] = NULL;
 	category_buttons.push_back(all_button);
 
@@ -334,8 +338,8 @@ void ApplicationsPage::load_categories()
 	// Add buttons for sorted categories
 	for (std::map<std::string, Category*>::const_iterator i = sorted_categories.begin(), end = sorted_categories.end(); i != end; ++i)
 	{
-		GtkRadioButton* category_button = new_section_button(i->second->get_icon(), i->second->get_text());
-		g_signal_connect(category_button, "toggled", SLOT_CALLBACK(ApplicationsPage::apply_filter), this);
+		SectionButton* category_button = new SectionButton(i->second->get_icon(), i->second->get_text());
+		g_signal_connect(category_button->get_button(), "toggled", SLOT_CALLBACK(ApplicationsPage::apply_filter), 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 a9b43af..b57c065 100644
--- a/src/applications_page.hpp
+++ b/src/applications_page.hpp
@@ -35,6 +35,7 @@ namespace WhiskerMenu
 class Launcher;
 class LauncherView;
 class Menu;
+class SectionButton;
 
 class ApplicationsPage : public FilterPage
 {
@@ -80,7 +81,7 @@ private:
 private:
 	GarconMenu* m_garcon_menu;
 	Category* m_current_category;
-	std::map<GtkRadioButton*, Category*> m_category_buttons;
+	std::map<SectionButton*, 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/configuration_dialog.cpp b/src/configuration_dialog.cpp
index 945c26a..9324fb4 100644
--- a/src/configuration_dialog.cpp
+++ b/src/configuration_dialog.cpp
@@ -145,7 +145,7 @@ ConfigurationDialog::ConfigurationDialog(PanelPlugin* plugin) :
 	// Add option to use generic names
 	m_hover_switch_category = gtk_check_button_new_with_mnemonic(_("Switch categories by _hovering"));
 	gtk_box_pack_start(behavior_vbox, m_hover_switch_category, true, true, 0);
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_hover_switch_category), section_button_get_hover_activate());
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_hover_switch_category), SectionButton::get_hover_activate());
 	g_signal_connect(m_hover_switch_category, "toggled", SLOT_CALLBACK(ConfigurationDialog::toggle_hover_switch_category), this);
 
 	// Show GTK window
@@ -207,7 +207,7 @@ void ConfigurationDialog::title_changed(GtkEditable*)
 
 void ConfigurationDialog::toggle_hover_switch_category(GtkToggleButton* button)
 {
-	section_button_set_hover_activate(gtk_toggle_button_get_active(button));
+	SectionButton::set_hover_activate(gtk_toggle_button_get_active(button));
 }
 
 //-----------------------------------------------------------------------------
diff --git a/src/menu.cpp b/src/menu.cpp
index 5de79b7..f319bdb 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -116,15 +116,15 @@ Menu::Menu(XfceRc* settings) :
 	// Create favorites
 	m_favorites = new FavoritesPage(settings, this);
 
-	m_favorites_button = new_section_button("user-bookmarks", _("Favorites"));
-	g_signal_connect_swapped(m_favorites_button, "toggled", SLOT_CALLBACK(Menu::favorites_toggled), this);
+	m_favorites_button = new SectionButton("user-bookmarks", _("Favorites"));
+	g_signal_connect_swapped(m_favorites_button->get_button(), "toggled", SLOT_CALLBACK(Menu::favorites_toggled), this);
 
 	// Create recent
 	m_recent = new RecentPage(settings, this);
 
-	m_recent_button = new_section_button("document-open-recent", _("Recently Used"));
-	gtk_radio_button_set_group(m_recent_button, gtk_radio_button_get_group(m_favorites_button));
-	g_signal_connect_swapped(m_recent_button, "toggled", SLOT_CALLBACK(Menu::recent_toggled), this);
+	m_recent_button = new SectionButton("document-open-recent", _("Recently Used"));
+	m_recent_button->set_group(m_favorites_button->get_group());
+	g_signal_connect_swapped(m_recent_button->get_button(), "toggled", SLOT_CALLBACK(Menu::recent_toggled), this);
 
 	// Create applications
 	m_applications = new ApplicationsPage(this);
@@ -164,8 +164,8 @@ Menu::Menu(XfceRc* settings) :
 	// Create box for packing sidebar
 	m_sidebar_box = GTK_BOX(gtk_vbox_new(false, 0));
 	gtk_box_pack_start(m_contents_box, GTK_WIDGET(m_sidebar_box), false, false, 0);
-	gtk_box_pack_start(m_sidebar_box, GTK_WIDGET(m_favorites_button), false, false, 0);
-	gtk_box_pack_start(m_sidebar_box, GTK_WIDGET(m_recent_button), false, false, 0);
+	gtk_box_pack_start(m_sidebar_box, GTK_WIDGET(m_favorites_button->get_button()), false, false, 0);
+	gtk_box_pack_start(m_sidebar_box, GTK_WIDGET(m_recent_button->get_button()), false, false, 0);
 	gtk_box_pack_start(m_sidebar_box, gtk_hseparator_new(), false, true, 0);
 
 	// Populate app menu
@@ -176,7 +176,7 @@ Menu::Menu(XfceRc* settings) :
 	gtk_widget_hide(m_recent->get_widget());
 	gtk_widget_hide(m_applications->get_widget());
 	gtk_widget_hide(m_search_results->get_widget());
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_favorites_button), true);
+	m_favorites_button->set_active(true);
 	gtk_widget_show(frame);
 
 	// Resize to last known size
@@ -417,13 +417,13 @@ void Menu::save(XfceRc* settings)
 
 //-----------------------------------------------------------------------------
 
-void Menu::set_categories(const std::vector<GtkRadioButton*>& categories)
+void Menu::set_categories(const std::vector<SectionButton*>& categories)
 {
-	for (std::vector<GtkRadioButton*>::const_iterator i = categories.begin(), end = categories.end(); i != end; ++i)
+	for (std::vector<SectionButton*>::const_iterator i = categories.begin(), end = categories.end(); i != end; ++i)
 	{
-		gtk_radio_button_set_group(*i, gtk_radio_button_get_group(m_recent_button));
-		gtk_box_pack_start(m_sidebar_box, GTK_WIDGET(*i), false, false, 0);
-		g_signal_connect_swapped(*i, "toggled", SLOT_CALLBACK(Menu::category_toggled), this);
+		(*i)->set_group(m_recent_button->get_group());
+		gtk_box_pack_start(m_sidebar_box, GTK_WIDGET((*i)->get_button()), false, false, 0);
+		g_signal_connect_swapped((*i)->get_button(), "toggled", SLOT_CALLBACK(Menu::category_toggled), this);
 	}
 	gtk_widget_show_all(GTK_WIDGET(m_sidebar_box));
 
@@ -540,11 +540,11 @@ gboolean Menu::on_key_press_event(GtkWidget* widget, GdkEventKey* event)
 		{
 			view = m_search_results->get_view()->get_widget();
 		}
-		else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_favorites_button)))
+		else if (m_favorites_button->get_active())
 		{
 			view = m_favorites->get_view()->get_widget();
 		}
-		else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_recent_button)))
+		else if (m_recent_button->get_active())
 		{
 			view = m_recent->get_view()->get_widget();
 		}
@@ -640,7 +640,7 @@ void Menu::category_toggled()
 void Menu::show_favorites()
 {
 	// Switch to favorites panel
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_favorites_button), true);
+	m_favorites_button->set_active(true);
 
 	// Clear search entry
 	gtk_entry_set_text(m_search_entry, "");
diff --git a/src/menu.hpp b/src/menu.hpp
index f6ac5ef..66ce596 100644
--- a/src/menu.hpp
+++ b/src/menu.hpp
@@ -38,6 +38,7 @@ class Launcher;
 class ResizerWidget;
 class RecentPage;
 class SearchPage;
+class SectionButton;
 
 class Menu
 {
@@ -78,7 +79,7 @@ public:
 	void hide();
 	void show(GtkWidget* parent, bool horizontal);
 	void save(XfceRc* settings);
-	void set_categories(const std::vector<GtkRadioButton*>& categories);
+	void set_categories(const std::vector<SectionButton*>& categories);
 	void set_items(const std::map<std::string, Launcher*>& items);
 	void set_modified();
 	void unset_items();
@@ -121,8 +122,8 @@ private:
 	RecentPage* m_recent;
 	ApplicationsPage* m_applications;
 
-	GtkRadioButton* m_favorites_button;
-	GtkRadioButton* m_recent_button;
+	SectionButton* m_favorites_button;
+	SectionButton* m_recent_button;
 
 	GdkRectangle m_geometry;
 	bool m_layout_left;
diff --git a/src/panel_plugin.cpp b/src/panel_plugin.cpp
index 7b07350..c9fc00e 100644
--- a/src/panel_plugin.cpp
+++ b/src/panel_plugin.cpp
@@ -61,7 +61,7 @@ PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
 		m_button_icon_visible = xfce_rc_read_bool_entry(settings, "show-button-icon", m_button_icon_visible);
 		Launcher::set_show_name(xfce_rc_read_bool_entry(settings, "launcher-show-name", true));
 		Launcher::set_show_description(xfce_rc_read_bool_entry(settings, "launcher-show-description", true));
-		section_button_set_hover_activate(xfce_rc_read_bool_entry(settings, "hover-switch-category", false));
+		SectionButton::set_hover_activate(xfce_rc_read_bool_entry(settings, "hover-switch-category", false));
 		m_menu = new Menu(settings);
 
 		xfce_rc_close(settings);
@@ -302,7 +302,7 @@ void PanelPlugin::save()
 	xfce_rc_write_bool_entry(settings, "show-button-icon", m_button_icon_visible);
 	xfce_rc_write_bool_entry(settings, "launcher-show-name", Launcher::get_show_name());
 	xfce_rc_write_bool_entry(settings, "launcher-show-description", Launcher::get_show_description());
-	xfce_rc_write_bool_entry(settings, "hover-switch-category", section_button_get_hover_activate());
+	xfce_rc_write_bool_entry(settings, "hover-switch-category", SectionButton::get_hover_activate());
 	m_menu->save(settings);
 
 	xfce_rc_close(settings);
diff --git a/src/section_button.cpp b/src/section_button.cpp
index cd33770..cdd3e69 100644
--- a/src/section_button.cpp
+++ b/src/section_button.cpp
@@ -16,6 +16,8 @@
 
 #include "section_button.hpp"
 
+using namespace WhiskerMenu;
+
 //-----------------------------------------------------------------------------
 
 static bool f_hover_activate = false;
@@ -40,36 +42,41 @@ static gboolean on_enter_notify_event(GtkWidget*, GdkEventCrossing*, GtkToggleBu
 
 //-----------------------------------------------------------------------------
 
-GtkRadioButton* WhiskerMenu::new_section_button(const gchar* icon, const gchar* text)
+SectionButton::SectionButton(const gchar* icon, const gchar* text)
 {
-	GtkWidget* button = gtk_radio_button_new(NULL);
-	gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(button), false);
-	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
-	gtk_button_set_focus_on_click(GTK_BUTTON(button), false);
-	g_signal_connect(button, "enter-notify-event", G_CALLBACK(on_enter_notify_event), GTK_TOGGLE_BUTTON(button));
+	m_button = GTK_RADIO_BUTTON(gtk_radio_button_new(NULL));
+	gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(m_button), false);
+	gtk_button_set_relief(GTK_BUTTON(m_button), GTK_RELIEF_NONE);
+	gtk_button_set_focus_on_click(GTK_BUTTON(m_button), false);
+	g_signal_connect(m_button, "enter-notify-event", G_CALLBACK(on_enter_notify_event), GTK_TOGGLE_BUTTON(m_button));
 
 	GtkBox* box = GTK_BOX(gtk_hbox_new(false, 4));
-	gtk_container_add(GTK_CONTAINER(button), GTK_WIDGET(box));
+	gtk_container_add(GTK_CONTAINER(m_button), GTK_WIDGET(box));
 
 	GtkWidget* image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
-	gtk_box_pack_start(box, GTK_WIDGET(image), false, false, 0);
+	gtk_box_pack_start(box, image, false, false, 0);
 
 	GtkWidget* label = gtk_label_new(text);
 	gtk_box_pack_start(box, label, false, true, 0);
+}
 
-	return GTK_RADIO_BUTTON(button);
+//-----------------------------------------------------------------------------
+
+SectionButton::~SectionButton()
+{
+	gtk_widget_destroy(GTK_WIDGET(m_button));
 }
 
 //-----------------------------------------------------------------------------
 
-bool WhiskerMenu::section_button_get_hover_activate()
+bool SectionButton::get_hover_activate()
 {
 	return f_hover_activate;
 }
 
 //-----------------------------------------------------------------------------
 
-void WhiskerMenu::section_button_set_hover_activate(bool hover_activate)
+void SectionButton::set_hover_activate(bool hover_activate)
 {
 	f_hover_activate = hover_activate;
 }
diff --git a/src/section_button.hpp b/src/section_button.hpp
index bcb6cd2..bb320f4 100644
--- a/src/section_button.hpp
+++ b/src/section_button.hpp
@@ -25,9 +25,43 @@ extern "C"
 namespace WhiskerMenu
 {
 
-GtkRadioButton* new_section_button(const gchar* icon, const gchar* text);
-bool section_button_get_hover_activate();
-void section_button_set_hover_activate(bool hover_activate);
+class SectionButton
+{
+public:
+	SectionButton(const gchar* icon, const gchar* text);
+	~SectionButton();
+
+	GtkRadioButton* get_button() const
+	{
+		return m_button;
+	}
+
+	bool get_active() const
+	{
+		return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_button));
+	}
+
+	void set_active(bool active)
+	{
+		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_button), active);
+	}
+
+	GSList* get_group() const
+	{
+		return gtk_radio_button_get_group(m_button);
+	}
+
+	void set_group(GSList* group)
+	{
+		gtk_radio_button_set_group(m_button, group);
+	}
+
+	static bool get_hover_activate();
+	static void set_hover_activate(bool hover_activate);
+
+private:
+	GtkRadioButton* m_button;
+};
 
 }
 

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


More information about the Xfce4-commits mailing list