[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 77/473: Add optional button title to panel button. Closes #4.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:54:07 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 c6bbf752734ed854fd31afbf45231c7c177d1186
Author: Graeme Gott <graeme at gottcode.org>
Date: Tue Jul 9 18:33:02 2013 -0400
Add optional button title to panel button. Closes #4.
---
src/configuration_dialog.cpp | 38 +++++++++++++++++++++--
src/configuration_dialog.hpp | 4 +++
src/panel_plugin.cpp | 69 +++++++++++++++++++++++++++++++++++++-----
src/panel_plugin.hpp | 31 ++++++++++++++++++-
4 files changed, 131 insertions(+), 11 deletions(-)
diff --git a/src/configuration_dialog.cpp b/src/configuration_dialog.cpp
index 96739a9..a7a61ef 100644
--- a/src/configuration_dialog.cpp
+++ b/src/configuration_dialog.cpp
@@ -79,11 +79,31 @@ ConfigurationDialog::ConfigurationDialog(PanelPlugin* plugin) :
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_descriptions), Launcher::get_show_description());
g_signal_connect(m_show_descriptions, "toggled", SLOT_CALLBACK(ConfigurationDialog::toggle_show_description), this);
+ // Add title selector
+ m_show_title = gtk_check_button_new_with_mnemonic(_("_Show button title"));
+ gtk_box_pack_start(appearance_vbox, m_show_title, true, true, 0);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_title), m_plugin->get_button_title_visible());
+ g_signal_connect(m_show_title, "toggled", SLOT_CALLBACK(ConfigurationDialog::toggle_show_title), this);
+
+ GtkBox* hbox = GTK_BOX(gtk_hbox_new(false, 12));
+ gtk_box_pack_start(appearance_vbox, GTK_WIDGET(hbox), false, false, 0);
+
+ GtkWidget* label = gtk_label_new_with_mnemonic(_("Button _title:"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+ gtk_box_pack_start(hbox, label, false, false, 0);
+ gtk_size_group_add_widget(label_size_group, label);
+
+ m_title = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(m_title), m_plugin->get_button_title().c_str());
+ gtk_box_pack_start(hbox, m_title, false, false, 0);
+ gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_title);
+ g_signal_connect(m_title, "changed", SLOT_CALLBACK(ConfigurationDialog::title_changed), this);
+
// Add icon selector
- GtkBox* hbox = GTK_BOX(gtk_hbox_new(false, 2));
+ hbox = GTK_BOX(gtk_hbox_new(false, 12));
gtk_box_pack_start(appearance_vbox, GTK_WIDGET(hbox), false, false, 0);
- GtkWidget* label = gtk_label_new_with_mnemonic(_("_Icon:"));
+ label = gtk_label_new_with_mnemonic(_("_Icon:"));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_box_pack_start(hbox, label, false, false, 0);
gtk_size_group_add_widget(label_size_group, label);
@@ -151,6 +171,13 @@ void ConfigurationDialog::choose_icon()
//-----------------------------------------------------------------------------
+void ConfigurationDialog::title_changed(GtkEditable*)
+{
+ m_plugin->set_button_title(gtk_entry_get_text(GTK_ENTRY(m_title)));
+}
+
+//-----------------------------------------------------------------------------
+
void ConfigurationDialog::toggle_hover_switch_category(GtkToggleButton* button)
{
section_button_set_hover_activate(gtk_toggle_button_get_active(button));
@@ -174,6 +201,13 @@ void ConfigurationDialog::toggle_show_description(GtkToggleButton*)
//-----------------------------------------------------------------------------
+void ConfigurationDialog::toggle_show_title(GtkToggleButton*)
+{
+ m_plugin->set_button_title_visible(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_show_title)));
+}
+
+//-----------------------------------------------------------------------------
+
void ConfigurationDialog::response(GtkDialog*, gint response_id)
{
if (response_id == GTK_RESPONSE_CLOSE)
diff --git a/src/configuration_dialog.hpp b/src/configuration_dialog.hpp
index b518997..96de632 100644
--- a/src/configuration_dialog.hpp
+++ b/src/configuration_dialog.hpp
@@ -42,19 +42,23 @@ public:
private:
SLOT_0(void, ConfigurationDialog, choose_icon);
+ SLOT_1(void, ConfigurationDialog, title_changed, GtkEditable*);
SLOT_1(void, ConfigurationDialog, toggle_hover_switch_category, GtkToggleButton*);
SLOT_1(void, ConfigurationDialog, toggle_show_name, GtkToggleButton*);
SLOT_1(void, ConfigurationDialog, toggle_show_description, GtkToggleButton*);
+ SLOT_1(void, ConfigurationDialog, toggle_show_title, GtkToggleButton*);
SLOT_2(void, ConfigurationDialog, response, GtkDialog*, gint);
private:
PanelPlugin* m_plugin;
GtkWidget* m_window;
+ GtkWidget* m_title;
GtkWidget* m_icon;
GtkWidget* m_icon_button;
GtkWidget* m_show_names;
GtkWidget* m_show_descriptions;
+ GtkWidget* m_show_title;
GtkWidget* m_hover_switch_category;
};
diff --git a/src/panel_plugin.cpp b/src/panel_plugin.cpp
index b6140f5..8cf8855 100644
--- a/src/panel_plugin.cpp
+++ b/src/panel_plugin.cpp
@@ -42,6 +42,8 @@ static void whiskermenu_free(XfcePanelPlugin*, PanelPlugin* whiskermenu)
PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
m_plugin(plugin),
+ m_button_title(_("Applications Menu")),
+ m_button_title_visible(false),
m_button_icon_name("xfce4-whiskermenu"),
m_menu(NULL)
{
@@ -52,6 +54,8 @@ PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
XfceRc* settings = xfce_rc_simple_open(file, true);
g_free(file);
+ m_button_title = xfce_rc_read_entry(settings, "button-title", m_button_title.c_str());
+ m_button_title_visible = xfce_rc_read_bool_entry(settings, "show-button-title", m_button_title_visible);
m_button_icon_name = xfce_rc_read_entry(settings, "button-icon", m_button_icon_name.c_str());
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));
@@ -69,10 +73,23 @@ PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
// Create toggle button
m_button = xfce_create_panel_toggle_button();
gtk_button_set_relief(GTK_BUTTON(m_button), GTK_RELIEF_NONE);
- m_button_icon = XFCE_PANEL_IMAGE(xfce_panel_image_new_from_source(m_button_icon_name.c_str()));
- gtk_container_add(GTK_CONTAINER(m_button), GTK_WIDGET(m_button_icon));
- gtk_widget_show_all(m_button);
g_signal_connect(m_button, "button-press-event", SLOT_CALLBACK(PanelPlugin::button_clicked), this);
+ gtk_widget_show(m_button);
+
+ m_button_box = GTK_BOX(gtk_hbox_new(false, 1));
+ gtk_container_add(GTK_CONTAINER(m_button), GTK_WIDGET(m_button_box));
+ gtk_widget_show(GTK_WIDGET(m_button_box));
+
+ m_button_icon = XFCE_PANEL_IMAGE(xfce_panel_image_new_from_source(m_button_icon_name.c_str()));
+ gtk_box_pack_start(m_button_box, GTK_WIDGET(m_button_icon), false, false, 0);
+ gtk_widget_show(GTK_WIDGET(m_button_icon));
+
+ m_button_label = GTK_LABEL(gtk_label_new(m_button_title.c_str()));
+ gtk_box_pack_start(m_button_box, GTK_WIDGET(m_button_label), false, false, 0);
+ if (m_button_title_visible)
+ {
+ gtk_widget_show(GTK_WIDGET(m_button_label));
+ }
// Add plugin to panel
gtk_container_add(GTK_CONTAINER(plugin), m_button);
@@ -81,7 +98,11 @@ PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
// Connect plugin signals to functions
g_signal_connect(plugin, "free-data", G_CALLBACK(whiskermenu_free), this);
g_signal_connect_swapped(plugin, "configure-plugin", SLOT_CALLBACK(PanelPlugin::configure), this);
- g_signal_connect(plugin, "orientation-changed", SLOT_CALLBACK(PanelPlugin::orientation_changed), this);
+#if (LIBXFCE4PANEL_CHECK_VERSION(4,10,0))
+ g_signal_connect(plugin, "mode-changed", G_CALLBACK(PanelPlugin::mode_changed_slot), this);
+#else
+ g_signal_connect(plugin, "orientation-changed", G_CALLBACK(PanelPlugin::orientation_changed_slot), this);
+#endif
g_signal_connect(plugin, "remote-event", SLOT_CALLBACK(PanelPlugin::remote_event), this);
g_signal_connect_swapped(plugin, "save", SLOT_CALLBACK(PanelPlugin::save), this);
g_signal_connect(plugin, "size-changed", SLOT_CALLBACK(PanelPlugin::size_changed), this);
@@ -110,6 +131,29 @@ void PanelPlugin::reload()
//-----------------------------------------------------------------------------
+void PanelPlugin::set_button_title(const std::string& title)
+{
+ m_button_title = title;
+ gtk_label_set_label(m_button_label, m_button_title.c_str());
+}
+
+//-----------------------------------------------------------------------------
+
+void PanelPlugin::set_button_title_visible(bool visible)
+{
+ m_button_title_visible = visible;
+ if (m_button_title_visible)
+ {
+ gtk_widget_show(GTK_WIDGET(m_button_label));
+ }
+ else
+ {
+ gtk_widget_hide(GTK_WIDGET(m_button_label));
+ }
+}
+
+//-----------------------------------------------------------------------------
+
void PanelPlugin::set_button_icon_name(const std::string& icon)
{
m_button_icon_name = icon;
@@ -173,8 +217,10 @@ void PanelPlugin::configure()
//-----------------------------------------------------------------------------
-void PanelPlugin::orientation_changed(XfcePanelPlugin*, GtkOrientation)
+void PanelPlugin::orientation_changed(bool vertical)
{
+ gtk_label_set_angle(m_button_label, vertical ? 270: 0);
+
size_changed(m_plugin, xfce_panel_plugin_get_size(m_plugin));
}
@@ -204,6 +250,8 @@ void PanelPlugin::save()
XfceRc* settings = xfce_rc_simple_open(file, false);
g_free(file);
+ xfce_rc_write_entry(settings, "button-title", m_button_title.c_str());
+ xfce_rc_write_bool_entry(settings, "show-button-title", m_button_title_visible);
xfce_rc_write_entry(settings, "button-icon", m_button_icon_name.c_str());
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());
@@ -223,15 +271,20 @@ gboolean PanelPlugin::size_changed(XfcePanelPlugin*, gint size)
gint row_size = size;
#endif
+ GtkOrientation orientation = xfce_panel_plugin_get_orientation(m_plugin);
+
xfce_panel_image_set_size(m_button_icon, -1);
- if (xfce_panel_plugin_get_orientation(m_plugin) == GTK_ORIENTATION_HORIZONTAL)
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
- gtk_widget_set_size_request(GTK_WIDGET(m_plugin), row_size, size);
+ gtk_widget_set_size_request(GTK_WIDGET(m_button_icon), row_size, size);
}
else
{
- gtk_widget_set_size_request(GTK_WIDGET(m_plugin), size, row_size);
+ gtk_widget_set_size_request(GTK_WIDGET(m_button_icon), size, row_size);
}
+
+ gtk_orientable_set_orientation(GTK_ORIENTABLE(m_button_box), orientation);
+
return true;
}
diff --git a/src/panel_plugin.hpp b/src/panel_plugin.hpp
index eef3aaf..b9c3a1a 100644
--- a/src/panel_plugin.hpp
+++ b/src/panel_plugin.hpp
@@ -43,12 +43,24 @@ public:
return m_button;
}
+ std::string get_button_title() const
+ {
+ return m_button_title;
+ }
+
+ bool get_button_title_visible() const
+ {
+ return m_button_title_visible;
+ }
+
std::string get_button_icon_name() const
{
return m_button_icon_name;
}
void reload();
+ void set_button_title(const std::string& title);
+ void set_button_title_visible(bool visible);
void set_button_icon_name(const std::string& icon);
void set_configure_enabled(bool enabled);
@@ -56,17 +68,34 @@ private:
SLOT_2(gboolean, PanelPlugin, button_clicked, GtkWidget*, GdkEventButton*);
SLOT_0(void, PanelPlugin, menu_hidden);
SLOT_0(void, PanelPlugin, configure);
- SLOT_2(void, PanelPlugin, orientation_changed, XfcePanelPlugin*, GtkOrientation);
SLOT_3(gboolean, PanelPlugin, remote_event, XfcePanelPlugin*, gchar*, GValue*);
SLOT_0(void, PanelPlugin, save);
SLOT_2(gboolean, PanelPlugin, size_changed, XfcePanelPlugin*, gint);
private:
+#if (LIBXFCE4PANEL_CHECK_VERSION(4,10,0))
+ static void mode_changed_slot(XfcePanelPlugin*, XfcePanelPluginMode mode, PanelPlugin* obj)
+ {
+ obj->orientation_changed(mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL);
+ }
+#else
+ static void orientation_changed_slot(XfcePanelPlugin*, GtkOrientation orientation, PanelPlugin* obj)
+ {
+ obj->orientation_changed(orientation == GTK_ORIENTATION_VERTICAL);
+ }
+#endif
+
+private:
+ void orientation_changed(bool vertical);
void popup_menu(bool at_cursor);
private:
XfcePanelPlugin* m_plugin;
GtkWidget* m_button;
+ GtkBox* m_button_box;
+ std::string m_button_title;
+ bool m_button_title_visible;
+ GtkLabel* m_button_label;
std::string m_button_icon_name;
XfcePanelImage* m_button_icon;
Menu* m_menu;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list