[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 79/473: Make panel button icon optional. References #4.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:54:09 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 94e7dfc125a3feb5c55962517a614ad4e4b19de0
Author: Graeme Gott <graeme at gottcode.org>
Date: Wed Jul 10 09:28:06 2013 -0400
Make panel button icon optional. References #4.
---
src/configuration_dialog.cpp | 56 +++++++++++++++++++++++++----------
src/configuration_dialog.hpp | 4 +--
src/panel_plugin.cpp | 67 ++++++++++++++++++++++++++++++++----------
src/panel_plugin.hpp | 30 +++++++++++++------
4 files changed, 115 insertions(+), 42 deletions(-)
diff --git a/src/configuration_dialog.cpp b/src/configuration_dialog.cpp
index 5bfa6f4..945c26a 100644
--- a/src/configuration_dialog.cpp
+++ b/src/configuration_dialog.cpp
@@ -79,29 +79,48 @@ 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);
+ // Create panel button section
+ GtkBox* panel_vbox = GTK_BOX(gtk_vbox_new(false, 8));
+ GtkWidget* panel_frame = xfce_gtk_frame_box_new_with_content(_("Panel Button"), GTK_WIDGET(panel_vbox));
+ gtk_box_pack_start(contents_vbox, panel_frame, false, false, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(panel_frame), 6);
+ // Add button style selector
GtkBox* hbox = GTK_BOX(gtk_hbox_new(false, 12));
- gtk_box_pack_start(appearance_vbox, GTK_WIDGET(hbox), false, false, 0);
+ gtk_box_pack_start(panel_vbox, GTK_WIDGET(hbox), false, false, 0);
- GtkWidget* label = gtk_label_new_with_mnemonic(_("Button _title:"));
+ GtkWidget* label = gtk_label_new_with_mnemonic(_("Di_splay:"));
+ 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_button_style = gtk_combo_box_text_new();
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(m_button_style), _("Icon"));
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(m_button_style), _("Title"));
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(m_button_style), _("Icon and title"));
+ gtk_combo_box_set_active(GTK_COMBO_BOX(m_button_style), static_cast<int>(m_plugin->get_button_style()) - 1);
+ gtk_box_pack_start(hbox, m_button_style, false, false, 0);
+ gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_button_style);
+ g_signal_connect(m_button_style, "changed", SLOT_CALLBACK(ConfigurationDialog::style_changed), this);
+
+ // Add title selector
+ hbox = GTK_BOX(gtk_hbox_new(false, 12));
+ gtk_box_pack_start(panel_vbox, GTK_WIDGET(hbox), false, false, 0);
+
+ label = gtk_label_new_with_mnemonic(_("_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_box_pack_start(hbox, m_title, true, true, 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
hbox = GTK_BOX(gtk_hbox_new(false, 12));
- gtk_box_pack_start(appearance_vbox, GTK_WIDGET(hbox), false, false, 0);
+ gtk_box_pack_start(panel_vbox, GTK_WIDGET(hbox), false, false, 0);
label = gtk_label_new_with_mnemonic(_("_Icon:"));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
@@ -171,6 +190,13 @@ void ConfigurationDialog::choose_icon()
//-----------------------------------------------------------------------------
+void ConfigurationDialog::style_changed(GtkComboBox* combo)
+{
+ m_plugin->set_button_style(PanelPlugin::ButtonStyle(gtk_combo_box_get_active(combo) + 1));
+}
+
+//-----------------------------------------------------------------------------
+
void ConfigurationDialog::title_changed(GtkEditable*)
{
const gchar* text = gtk_entry_get_text(GTK_ENTRY(m_title));
@@ -202,15 +228,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 ((m_plugin->get_button_style() == PanelPlugin::ShowText) && m_plugin->get_button_title().empty())
+ {
+ m_plugin->set_button_title(PanelPlugin::get_button_title_default());
+ }
+
if (response_id == GTK_RESPONSE_CLOSE)
{
gtk_widget_destroy(m_window);
diff --git a/src/configuration_dialog.hpp b/src/configuration_dialog.hpp
index 96de632..93a80cb 100644
--- a/src/configuration_dialog.hpp
+++ b/src/configuration_dialog.hpp
@@ -42,23 +42,23 @@ public:
private:
SLOT_0(void, ConfigurationDialog, choose_icon);
+ SLOT_1(void, ConfigurationDialog, style_changed, GtkComboBox*);
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_button_style;
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 4194a66..6ff652f 100644
--- a/src/panel_plugin.cpp
+++ b/src/panel_plugin.cpp
@@ -42,10 +42,11 @@ 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_menu(NULL),
+ m_button_title(get_button_title_default()),
m_button_icon_name("xfce4-whiskermenu"),
- m_menu(NULL)
+ m_button_title_visible(false),
+ m_button_icon_visible(true)
{
// Load settings
gchar* file = xfce_panel_plugin_lookup_rc_file(m_plugin);
@@ -55,8 +56,9 @@ PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
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());
+ m_button_title_visible = xfce_rc_read_bool_entry(settings, "show-button-title", m_button_title_visible);
+ 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));
@@ -70,6 +72,19 @@ PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
}
g_signal_connect_swapped(m_menu->get_widget(), "unmap", SLOT_CALLBACK(PanelPlugin::menu_hidden), this);
+ // Prevent empty panel button
+ if (!m_button_icon_visible)
+ {
+ if (!m_button_title_visible)
+ {
+ m_button_icon_visible = true;
+ }
+ else if (m_button_title.empty())
+ {
+ m_button_title = get_button_title_default();
+ }
+ }
+
// Create toggle button
m_button = xfce_create_panel_toggle_button();
gtk_button_set_relief(GTK_BUTTON(m_button), GTK_RELIEF_NONE);
@@ -82,7 +97,10 @@ PanelPlugin::PanelPlugin(XfcePanelPlugin* plugin) :
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));
+ if (m_button_icon_visible)
+ {
+ 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);
@@ -123,26 +141,34 @@ PanelPlugin::~PanelPlugin()
//-----------------------------------------------------------------------------
-void PanelPlugin::reload()
+std::string PanelPlugin::get_button_title_default()
{
- m_menu->hide();
- m_menu->get_applications()->invalidate_applications();
+ return _("Applications Menu");
}
//-----------------------------------------------------------------------------
-void PanelPlugin::set_button_title(const std::string& title)
+void PanelPlugin::reload()
{
- m_button_title = title;
- gtk_label_set_label(m_button_label, m_button_title.c_str());
- size_changed(m_plugin, xfce_panel_plugin_get_size(m_plugin));
+ m_menu->hide();
+ m_menu->get_applications()->invalidate_applications();
}
//-----------------------------------------------------------------------------
-void PanelPlugin::set_button_title_visible(bool visible)
+void PanelPlugin::set_button_style(ButtonStyle style)
{
- m_button_title_visible = visible;
+ m_button_icon_visible = style & ShowIcon;
+ if (m_button_icon_visible)
+ {
+ gtk_widget_show(GTK_WIDGET(m_button_icon));
+ }
+ else
+ {
+ gtk_widget_hide(GTK_WIDGET(m_button_icon));
+ }
+
+ m_button_title_visible = style & ShowText;
if (m_button_title_visible)
{
gtk_widget_show(GTK_WIDGET(m_button_label));
@@ -151,6 +177,16 @@ void PanelPlugin::set_button_title_visible(bool visible)
{
gtk_widget_hide(GTK_WIDGET(m_button_label));
}
+
+ size_changed(m_plugin, xfce_panel_plugin_get_size(m_plugin));
+}
+
+//-----------------------------------------------------------------------------
+
+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());
size_changed(m_plugin, xfce_panel_plugin_get_size(m_plugin));
}
@@ -254,8 +290,9 @@ void PanelPlugin::save()
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, "show-button-title", m_button_title_visible);
+ 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());
diff --git a/src/panel_plugin.hpp b/src/panel_plugin.hpp
index b9c3a1a..8112bb9 100644
--- a/src/panel_plugin.hpp
+++ b/src/panel_plugin.hpp
@@ -43,24 +43,33 @@ public:
return m_button;
}
- std::string get_button_title() const
+ enum ButtonStyle
{
- return m_button_title;
+ ShowIcon = 0x1,
+ ShowText = 0x2,
+ ShowIconAndText = ShowIcon | ShowText
+ };
+
+ ButtonStyle get_button_style() const
+ {
+ return ButtonStyle(m_button_icon_visible | (m_button_title_visible << 1));
}
- bool get_button_title_visible() const
+ std::string get_button_title() const
{
- return m_button_title_visible;
+ return m_button_title;
}
+ static std::string get_button_title_default();
+
std::string get_button_icon_name() const
{
return m_button_icon_name;
}
void reload();
+ void set_button_style(ButtonStyle style);
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);
@@ -91,14 +100,17 @@ private:
private:
XfcePanelPlugin* m_plugin;
- GtkWidget* m_button;
- GtkBox* m_button_box;
+ Menu* m_menu;
+
std::string m_button_title;
+ std::string m_button_icon_name;
bool m_button_title_visible;
+ bool m_button_icon_visible;
+
+ GtkWidget* m_button;
+ GtkBox* m_button_box;
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