[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 232/473: Refactor code for editting commands.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:56:42 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 d35af9be2891970f0e34a7ebbb194647aba5311e
Author: Graeme Gott <graeme at gottcode.org>
Date: Sun Nov 10 16:20:59 2013 -0500
Refactor code for editting commands.
---
panel-plugin/CMakeLists.txt | 2 +
panel-plugin/command-edit.cpp | 128 ++++++++++++++++++++++++++++
panel-plugin/{command.h => command-edit.h} | 65 ++++++--------
panel-plugin/command.h | 5 ++
panel-plugin/configuration-dialog.cpp | 103 ++++------------------
panel-plugin/configuration-dialog.h | 34 ++------
6 files changed, 182 insertions(+), 155 deletions(-)
diff --git a/panel-plugin/CMakeLists.txt b/panel-plugin/CMakeLists.txt
index 17f34e7..7e2b3b8 100644
--- a/panel-plugin/CMakeLists.txt
+++ b/panel-plugin/CMakeLists.txt
@@ -38,6 +38,7 @@ link_directories(
add_definitions(
-DGETTEXT_PACKAGE="xfce4-whiskermenu-plugin"
-DPACKAGE_LOCALE_DIR="${CMAKE_INSTALL_FULL_LOCALEDIR}"
+ -DBINDIR="${CMAKE_INSTALL_FULL_BINDIR}"
-DDATADIR="${CMAKE_INSTALL_FULL_DATADIR}"
-DG_LOG_DOMAIN="whiskermenu"
-DGSEAL_ENABLE
@@ -63,6 +64,7 @@ add_library(whiskermenu MODULE
applications-page.cpp
category.cpp
command.cpp
+ command-edit.cpp
configuration-dialog.cpp
element.h
favorites-page.cpp
diff --git a/panel-plugin/command-edit.cpp b/panel-plugin/command-edit.cpp
new file mode 100644
index 0000000..103f298
--- /dev/null
+++ b/panel-plugin/command-edit.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "command-edit.h"
+
+#include "command.h"
+
+#include <glib/gi18n.h>
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+CommandEdit::CommandEdit(Command* command) :
+ m_command(command)
+{
+ m_widget = gtk_vbox_new(false, 6);
+
+ m_shown = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_mnemonic(m_command->get_text()));
+ gtk_toggle_button_set_active(m_shown, m_command->get_shown());
+ gtk_box_pack_start(GTK_BOX(m_widget), GTK_WIDGET(m_shown), false, false, 0);
+ g_signal_connect(m_shown, "toggled", G_CALLBACK(CommandEdit::shown_toggled_slot), this);
+
+ GtkAlignment* alignment = GTK_ALIGNMENT(gtk_alignment_new(0.0, 0.0, 1.0, 1.0));
+ gtk_alignment_set_padding(alignment, 0, 0, 18, 0);
+ gtk_box_pack_start(GTK_BOX(m_widget), GTK_WIDGET(alignment), false, false, 0);
+
+ GtkBox* hbox = GTK_BOX(gtk_hbox_new(false, 6));
+ gtk_container_add(GTK_CONTAINER(alignment), GTK_WIDGET(hbox));
+
+ GtkWidget* label = gtk_label_new(_("Command:"));
+ gtk_box_pack_start(hbox, label, false, false, 6);
+
+ m_entry = GTK_ENTRY(gtk_entry_new());
+ gtk_entry_set_text(m_entry, m_command->get());
+ gtk_box_pack_start(hbox, GTK_WIDGET(m_entry), true, true, 0);
+ g_signal_connect(m_entry, "changed", G_CALLBACK(CommandEdit::command_changed_slot), this);
+
+ m_browse_button = gtk_button_new();
+ gtk_widget_set_tooltip_text(m_browse_button, _("Browse the file system to choose a custom command."));
+ gtk_box_pack_start(hbox, m_browse_button, false, false, 0);
+ gtk_widget_show(m_browse_button);
+
+ GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
+ gtk_container_add(GTK_CONTAINER(m_browse_button), image);
+ gtk_widget_show(image);
+ g_signal_connect(m_browse_button, "clicked", G_CALLBACK(CommandEdit::browse_clicked_slot), this);
+}
+
+//-----------------------------------------------------------------------------
+
+void CommandEdit::browse_clicked()
+{
+ GtkFileChooser* chooser = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new(_("Select Command"),
+ GTK_WINDOW(gtk_widget_get_toplevel(m_widget)),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ NULL));
+ gtk_file_chooser_set_local_only(chooser, true);
+ gtk_file_chooser_set_current_folder(chooser, BINDIR);
+
+ // Select current command
+ gchar* filename = g_strdup(m_command->get());
+ if (filename != NULL)
+ {
+ // Make sure command is absolute path
+ if (!g_path_is_absolute(filename))
+ {
+ gchar* absolute_path = g_find_program_in_path(filename);
+ if (absolute_path != NULL)
+ {
+ g_free(filename);
+ filename = absolute_path;
+ }
+ }
+
+ if (g_path_is_absolute(filename))
+ {
+ gtk_file_chooser_set_filename(chooser, filename);
+ }
+ g_free(filename);
+ }
+
+ // Set new command
+ if (gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_ACCEPT)
+ {
+ filename = gtk_file_chooser_get_filename(chooser);
+ gtk_entry_set_text(m_entry, filename);
+ m_command->set(filename);
+ g_free(filename);
+ }
+
+ gtk_widget_destroy(GTK_WIDGET(chooser));
+}
+
+//-----------------------------------------------------------------------------
+
+void CommandEdit::command_changed()
+{
+ m_command->set(gtk_entry_get_text(m_entry));
+}
+
+//-----------------------------------------------------------------------------
+
+void CommandEdit::shown_toggled()
+{
+ bool active = gtk_toggle_button_get_active(m_shown);
+ m_command->set_shown(active);
+ gtk_widget_set_sensitive(GTK_WIDGET(m_entry), active);
+ gtk_widget_set_sensitive(GTK_WIDGET(m_browse_button), active);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/panel-plugin/command.h b/panel-plugin/command-edit.h
similarity index 52%
copy from panel-plugin/command.h
copy to panel-plugin/command-edit.h
index a3d276c..cb641a7 100644
--- a/panel-plugin/command.h
+++ b/panel-plugin/command-edit.h
@@ -15,8 +15,8 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef WHISKERMENU_COMMAND_H
-#define WHISKERMENU_COMMAND_H
+#ifndef WHISKERMENU_COMMAND_EDIT_H
+#define WHISKERMENU_COMMAND_EDIT_H
extern "C"
{
@@ -26,60 +26,49 @@ extern "C"
namespace WhiskerMenu
{
-class Command
+class Command;
+
+class CommandEdit
{
public:
- Command(const gchar* icon, const gchar* text, const gchar* command, const gchar* error_text);
- ~Command();
-
- GtkWidget* get_button();
- GtkWidget* get_menuitem();
-
- const gchar* get() const
- {
- return m_command;
- }
-
- bool get_shown() const
- {
- return m_shown;
- }
-
- void set(const gchar* command);
+ CommandEdit(Command* command);
- void set_shown(bool shown)
+ GtkWidget* get_widget() const
{
- m_shown = shown;
+ return m_widget;
}
- void check();
-
private:
- void activated();
+ void browse_clicked();
+ void command_changed();
+ void shown_toggled();
private:
- GtkWidget* m_button;
- GtkWidget* m_menuitem;
- gchar* m_icon;
- gchar* m_text;
- gchar* m_command;
- gchar* m_error_text;
- gint m_status;
- bool m_shown;
+ Command* m_command;
+
+ GtkWidget* m_widget;
+ GtkToggleButton* m_shown;
+ GtkEntry* m_entry;
+ GtkWidget* m_browse_button;
private:
- static void clicked_slot(GtkButton*, Command* obj)
+ static void browse_clicked_slot(GtkWidget*, CommandEdit* obj)
+ {
+ obj->browse_clicked();
+ }
+
+ static void command_changed_slot(GtkEditable*, CommandEdit* obj)
{
- obj->activated();
+ obj->command_changed();
}
- static void activated_slot(GtkMenuItem*, Command* obj)
+ static void shown_toggled_slot(GtkToggleButton*, CommandEdit* obj)
{
- obj->activated();
+ obj->shown_toggled();
}
};
}
-#endif // WHISKERMENU_COMMAND_H
+#endif // WHISKERMENU_COMMAND_EDIT_H
diff --git a/panel-plugin/command.h b/panel-plugin/command.h
index a3d276c..a7bbcc5 100644
--- a/panel-plugin/command.h
+++ b/panel-plugin/command.h
@@ -45,6 +45,11 @@ public:
return m_shown;
}
+ const gchar* get_text() const
+ {
+ return m_text;
+ }
+
void set(const gchar* command);
void set_shown(bool shown)
diff --git a/panel-plugin/configuration-dialog.cpp b/panel-plugin/configuration-dialog.cpp
index 8b4d849..a3a6ce7 100644
--- a/panel-plugin/configuration-dialog.cpp
+++ b/panel-plugin/configuration-dialog.cpp
@@ -18,6 +18,7 @@
#include "configuration-dialog.h"
#include "command.h"
+#include "command-edit.h"
#include "icon-size.h"
#include "plugin.h"
#include "settings.h"
@@ -81,6 +82,11 @@ ConfigurationDialog::ConfigurationDialog(Plugin* plugin) :
ConfigurationDialog::~ConfigurationDialog()
{
+ delete m_settings_command;
+ delete m_lockscreen_command;
+ delete m_logout_command;
+ delete m_menueditor_command;
+
m_plugin->set_configure_enabled(true);
}
@@ -203,38 +209,6 @@ void ConfigurationDialog::toggle_display_recent(GtkToggleButton* button)
//-----------------------------------------------------------------------------
-void ConfigurationDialog::settings_command_changed()
-{
- const gchar* text = gtk_entry_get_text(GTK_ENTRY(m_settings_command));
- wm_settings->command_settings->set(text);
-}
-
-//-----------------------------------------------------------------------------
-
-void ConfigurationDialog::lockscreen_command_changed()
-{
- const gchar* text = gtk_entry_get_text(GTK_ENTRY(m_lockscreen_command));
- wm_settings->command_lockscreen->set(text);
-}
-
-//-----------------------------------------------------------------------------
-
-void ConfigurationDialog::logout_command_changed()
-{
- const gchar* text = gtk_entry_get_text(GTK_ENTRY(m_logout_command));
- wm_settings->command_logout->set(text);
-}
-
-//-----------------------------------------------------------------------------
-
-void ConfigurationDialog::menueditor_command_changed()
-{
- const gchar* text = gtk_entry_get_text(GTK_ENTRY(m_menueditor_command));
- wm_settings->command_menueditor->set(text);
-}
-
-//-----------------------------------------------------------------------------
-
void ConfigurationDialog::response(int response_id)
{
if ((m_plugin->get_button_style() == Plugin::ShowText) && m_plugin->get_button_title().empty())
@@ -441,74 +415,27 @@ GtkWidget* ConfigurationDialog::init_behavior_tab()
GtkWidget* ConfigurationDialog::init_commands_tab()
{
- // Create size group for labels
- GtkSizeGroup* label_size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-
// Create commands section
GtkWidget* page = gtk_alignment_new(0, 0, 1, 0);
gtk_container_set_border_width(GTK_CONTAINER(page), 8);
- GtkBox* panel_vbox = GTK_BOX(gtk_vbox_new(false, 8));
+ GtkBox* panel_vbox = GTK_BOX(gtk_vbox_new(false, 18));
gtk_container_add(GTK_CONTAINER(page), GTK_WIDGET(panel_vbox));
// Add settings command entry
- GtkBox* hbox = GTK_BOX(gtk_hbox_new(false, 12));
- gtk_box_pack_start(panel_vbox, GTK_WIDGET(hbox), false, false, 0);
-
- GtkWidget* label = gtk_label_new_with_mnemonic(_("_Settings:"));
- 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_settings_command = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(m_settings_command), wm_settings->command_settings->get());
- gtk_box_pack_start(hbox, m_settings_command, true, true, 0);
- gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_settings_command);
- g_signal_connect(m_settings_command, "changed", G_CALLBACK(ConfigurationDialog::settings_command_changed_slot), this);
+ m_settings_command = new CommandEdit(wm_settings->command_settings);
+ gtk_box_pack_start(panel_vbox, m_settings_command->get_widget(), false, false, 0);
// Add lock screen command entry
- 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(_("Lock _Screen:"));
- 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_lockscreen_command = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(m_lockscreen_command), wm_settings->command_lockscreen->get());
- gtk_box_pack_start(hbox, m_lockscreen_command, true, true, 0);
- gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_lockscreen_command);
- g_signal_connect(m_lockscreen_command, "changed", G_CALLBACK(ConfigurationDialog::lockscreen_command_changed_slot), this);
+ m_lockscreen_command = new CommandEdit(wm_settings->command_lockscreen);
+ gtk_box_pack_start(panel_vbox, m_lockscreen_command->get_widget(), false, false, 0);
// Add log out command entry
- 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(_("Log _Out:"));
- 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_logout_command = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(m_logout_command), wm_settings->command_logout->get());
- gtk_box_pack_start(hbox, m_logout_command, true, true, 0);
- gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_logout_command);
- g_signal_connect(m_logout_command, "changed", G_CALLBACK(ConfigurationDialog::logout_command_changed_slot), this);
+ m_logout_command = new CommandEdit(wm_settings->command_logout);
+ gtk_box_pack_start(panel_vbox, m_logout_command->get_widget(), false, false, 0);
// Add menu editor command entry
- 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(_("Edit _Applications:"));
- 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_menueditor_command = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(m_menueditor_command), wm_settings->command_menueditor->get());
- gtk_box_pack_start(hbox, m_menueditor_command, true, true, 0);
- gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_menueditor_command);
- g_signal_connect(m_menueditor_command, "changed", G_CALLBACK(ConfigurationDialog::menueditor_command_changed_slot), this);
+ m_menueditor_command = new CommandEdit(wm_settings->command_menueditor);
+ gtk_box_pack_start(panel_vbox, m_menueditor_command->get_widget(), false, false, 0);
return page;
}
diff --git a/panel-plugin/configuration-dialog.h b/panel-plugin/configuration-dialog.h
index e449e4c..ea6823c 100644
--- a/panel-plugin/configuration-dialog.h
+++ b/panel-plugin/configuration-dialog.h
@@ -26,6 +26,7 @@ extern "C"
namespace WhiskerMenu
{
+class CommandEdit;
class Plugin;
class ConfigurationDialog
@@ -56,11 +57,6 @@ private:
void toggle_remember_favorites(GtkToggleButton* button);
void toggle_display_recent(GtkToggleButton* button);
- void settings_command_changed();
- void lockscreen_command_changed();
- void logout_command_changed();
- void menueditor_command_changed();
-
void response(int response_id);
GtkWidget* init_appearance_tab();
GtkWidget* init_panel_button_tab();
@@ -88,10 +84,10 @@ private:
GtkWidget* m_remember_favorites;
GtkWidget* m_display_recent;
- GtkWidget* m_settings_command;
- GtkWidget* m_lockscreen_command;
- GtkWidget* m_logout_command;
- GtkWidget* m_menueditor_command;
+ CommandEdit* m_settings_command;
+ CommandEdit* m_lockscreen_command;
+ CommandEdit* m_logout_command;
+ CommandEdit* m_menueditor_command;
private:
@@ -164,26 +160,6 @@ private:
{
obj->response(response_id);
}
-
- static void settings_command_changed_slot(GtkEditable*, ConfigurationDialog* obj)
- {
- obj->settings_command_changed();
- }
-
- static void lockscreen_command_changed_slot(GtkEditable*, ConfigurationDialog* obj)
- {
- obj->lockscreen_command_changed();
- }
-
- static void logout_command_changed_slot(GtkEditable*, ConfigurationDialog* obj)
- {
- obj->logout_command_changed();
- }
-
- static void menueditor_command_changed_slot(GtkEditable*, ConfigurationDialog* obj)
- {
- obj->menueditor_command_changed();
- }
};
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list