[Xfce4-commits] <xfce4-embed-plugin:master> Reworked configuration dialog code to make it readable.
David Schneider
noreply at xfce.org
Wed Feb 1 10:50:01 CET 2012
Updating branch refs/heads/master
to aa809016aad7026e3ba2d6b0ea762f278aa44510 (commit)
from bfcfde8cb3ed0a673f6f264635e7073091542b4b (commit)
commit aa809016aad7026e3ba2d6b0ea762f278aa44510
Author: David Schneider <dnschneid at gmail.com>
Date: Wed Feb 1 01:33:20 2012 -0800
Reworked configuration dialog code to make it readable.
panel-plugin/embed-dialogs.c | 251 +++++++++++++++++++++++++-----------------
1 files changed, 149 insertions(+), 102 deletions(-)
diff --git a/panel-plugin/embed-dialogs.c b/panel-plugin/embed-dialogs.c
index 1d9de71..4ce251c 100644
--- a/panel-plugin/embed-dialogs.c
+++ b/panel-plugin/embed-dialogs.c
@@ -195,11 +195,115 @@ embed_expand_toggled (GtkToggleButton *toggle, EmbedPlugin *embed)
+static void
+set_tooltips (GtkWidget *widgetA, GtkWidget *widgetB, const gchar *text)
+{
+ gtk_widget_set_tooltip_text (widgetA, text);
+ gtk_widget_set_tooltip_text (widgetB, text);
+}
+
+
+
+static GtkWidget *
+add_frame (GtkWidget *content, gint rows, const gchar *title)
+{
+ GtkWidget *table, *frame;
+ table = gtk_table_new (rows, 2, FALSE);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 12);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+ frame = xfce_gtk_frame_box_new_with_content (title, table);
+ gtk_box_pack_start_defaults (GTK_BOX (content), frame);
+ return table;
+}
+
+
+
+
+static GtkWidget *
+add_label (GtkWidget *table, gint row,
+ GtkWidget *mnemonic_widget, const gchar *text)
+{
+ GtkWidget *label = gtk_label_new_with_mnemonic (text);
+ if (mnemonic_widget) {
+ gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5f);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), mnemonic_widget);
+ }
+ gtk_table_attach_defaults (GTK_TABLE (table), label,
+ 0, mnemonic_widget ? 1 : 2, row, row+1);
+ return label;
+}
+
+
+
+static void
+add_entry (EmbedPlugin *embed, GtkWidget *table, gint row,
+ const gchar *value, gboolean show_icon, gpointer callback,
+ const gchar *labeltext, const gchar *tooltiptext)
+{
+ GtkWidget *label, *entry;
+ entry = gtk_entry_new ();
+ label = add_label (table, row, entry, labeltext);
+ if (value) gtk_entry_set_text (GTK_ENTRY (entry), value);
+ if (show_icon) embed_entry_set_good (GTK_ENTRY (entry), TRUE);
+ g_signal_connect (G_OBJECT (entry), "changed", G_CALLBACK (callback), embed);
+ set_tooltips (label, entry, tooltiptext);
+ gtk_table_attach_defaults (GTK_TABLE (table), entry, 1, 2, row, row+1);
+}
+
+
+
+static void
+add_fontbutton (EmbedPlugin *embed, GtkWidget *table, gint row,
+ const gchar *value, gpointer callback,
+ const gchar *labeltext, const gchar *tooltiptext)
+{
+ GtkWidget *label, *button;
+ button = gtk_font_button_new ();
+ label = add_label (table, row, button, labeltext);
+ if (value) gtk_font_button_set_font_name (GTK_FONT_BUTTON (button), value);
+ g_signal_connect (G_OBJECT (button), "font-set",
+ G_CALLBACK (callback), embed);
+ set_tooltips (label, button, tooltiptext);
+ gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, row, row+1);
+}
+
+
+
+static void
+add_spinbutton (EmbedPlugin *embed, GtkWidget *table, gint row,
+ gint value, gpointer callback,
+ const gchar *labeltext, const gchar *tooltiptext)
+{
+ GtkWidget *label, *button;
+ button = gtk_spin_button_new_with_range (0, G_MAXINT, 1);
+ label = add_label (table, row, button, labeltext);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (button), value);
+ g_signal_connect (G_OBJECT (button), "value-changed",
+ G_CALLBACK (callback), embed);
+ set_tooltips (label, button, tooltiptext);
+ gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, row, row+1);
+}
+
+
+
+static void
+add_checkbutton (EmbedPlugin *embed, GtkWidget *table, gint row,
+ gboolean value, gpointer callback,
+ const gchar *labeltext, const gchar *tooltiptext)
+{
+ GtkWidget *button = gtk_check_button_new_with_mnemonic (labeltext);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), value);
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (callback), embed);
+ gtk_widget_set_tooltip_text (button, tooltiptext);
+ gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, row, row+1);
+}
+
+
+
void
embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed)
{
- GtkWidget *dialog, *content, *table, *label, *widget;
- const gchar *tooltip;
+ GtkWidget *dialog, *content, *table;
/* block the plugin menu */
xfce_panel_plugin_block_menu (plugin);
@@ -218,129 +322,72 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed)
content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-#define ADD(widget, row, column) \
- gtk_table_attach_defaults (GTK_TABLE (table), widget, \
- column, column+1, row, row+1)
-#define TOOLTIP2(widgetA, widgetB, tooltiptext) \
- tooltip = tooltiptext; \
- gtk_widget_set_tooltip_text (widgetA, tooltip); \
- gtk_widget_set_tooltip_text (widgetB, tooltip)
-#define LABEL(row, labeltext) \
- widget = gtk_label_new (labeltext); \
- gtk_table_attach_defaults (GTK_TABLE (table), widget, 0, 2, row, row+1)
-#define ENTRY(row, labeltext, tooltiptext, value, callback) \
- label = gtk_label_new_with_mnemonic (labeltext); \
- widget = gtk_entry_new (); \
- if (value) \
- gtk_entry_set_text (GTK_ENTRY (widget), value); \
- g_signal_connect (G_OBJECT (widget), "changed", \
- G_CALLBACK (callback), embed); \
- TOOLTIP2(label, widget, tooltiptext); \
- gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5f); \
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); \
- ADD(label, row, 0); ADD(widget, row, 1)
-#define FONTBUTTON(row, labeltext, tooltiptext, value, callback) \
- label = gtk_label_new_with_mnemonic (labeltext); \
- widget = gtk_font_button_new (); \
- if (value) \
- gtk_font_button_set_font_name (GTK_FONT_BUTTON (widget), value); \
- g_signal_connect (G_OBJECT (widget), "font-set", \
- G_CALLBACK (callback), embed); \
- TOOLTIP2(label, widget, tooltiptext); \
- gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5f); \
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); \
- ADD(label, row, 0); ADD(widget, row, 1)
-#define SPIN(row, labeltext, tooltiptext, value, callback) \
- label = gtk_label_new_with_mnemonic (labeltext); \
- widget = gtk_spin_button_new_with_range (0, G_MAXINT, 1); \
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value); \
- g_signal_connect (G_OBJECT (widget), "value-changed", \
- G_CALLBACK (callback), embed); \
- TOOLTIP2(label, widget, tooltiptext); \
- gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5f); \
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); \
- ADD(label, row, 0); ADD(widget, row, 1)
-#define START_FRAME(title, rows) \
- table = gtk_table_new (rows, 2, FALSE); \
- gtk_table_set_col_spacings (GTK_TABLE (table), 12); \
- gtk_table_set_row_spacings (GTK_TABLE (table), 6); \
- widget = xfce_gtk_frame_box_new_with_content (title, table); \
- gtk_box_pack_start_defaults (GTK_BOX (content), widget)
-
- START_FRAME(_("Application Launching"), 2);
- LABEL(0,
+ table = add_frame (content, 2, _("Application Launching"));
+ add_label (table, 0, NULL,
_("If a window is not found (or there are no criteria), a command can\n"
"optionally be launched. The command can either result in a window\n"
"that matches the below criteria, or it can use the socket ID passed\n"
"to it (" EMBED_LAUNCH_CMD_SOCKET ") to embed itself automatically."));
/* launch_cmd */
- ENTRY(1, _("L_aunch command"),
+ add_entry (embed, table, 1, embed->launch_cmd, TRUE, embed_launch_cmd_changed,
+ _("L_aunch command"),
_("Leave blank to not launch anything\n"
- EMBED_LAUNCH_CMD_SOCKET " expands to the socket ID"),
- embed->launch_cmd, embed_launch_cmd_changed);
- embed_entry_set_good (GTK_ENTRY (widget), TRUE);
+ EMBED_LAUNCH_CMD_SOCKET " expands to the socket ID"));
- START_FRAME(_("Selection Criteria"), 4);
- LABEL(0,
+ /* poll_delay */
+ /* No UI element. Generally polling is unnecessary, unless you have a very
+ * strange window that you're trying to match that is not uniquely
+ * identifiable when it is mapped. */
+
+
+ table = add_frame (content, 4, _("Selection Criteria"));
+ add_label (table, 0, NULL,
_("The window to embed must match all of the non-blank criteria.\n"
"Leave everything blank to rely on a launch command with socket ID."));
/* proc_name */
- ENTRY(1, _("_Process name"),
+ add_entry (embed, table, 1, embed->proc_name, FALSE, embed_proc_name_changed,
+ _("_Process name"),
_("Match the window's application's process name\n"
- "Leave blank if it is not a criterion"),
- embed->proc_name, embed_proc_name_changed);
+ "Leave blank if it is not a criterion"));
/* window_class */
- ENTRY(2, _("_Window class"), _("Match the window's class\n"
- "Leave blank if it is not a criterion"),
- embed->window_class, embed_window_class_changed);
+ add_entry (embed, table, 2, embed->window_class, FALSE,
+ embed_window_class_changed,
+ _("_Window class"),
+ _("Match the window's class\n"
+ "Leave blank if it is not a criterion"));
/* window_regex */
- ENTRY(3, _("Window _title"), _("Match the window's title using a REGEX\n"
- "Leave blank if it is not a criterion"),
- embed->window_regex, embed_window_regex_changed);
- embed_entry_set_good (GTK_ENTRY (widget), TRUE);
+ add_entry (embed, table, 3, embed->window_regex, TRUE,
+ embed_window_regex_changed,
+ _("Window _title"),
+ _("Match the window's title using a REGEX\n"
+ "Leave blank if it is not a criterion"));
- /* poll_delay */
- /* No UI element. Generally polling is unnecessary, unless you have a very
- * strange window that you're trying to match that is not uniquely
- * identifiable when it is mapped. */
-
-
- START_FRAME(_("Display"), 3);
+ table = add_frame (content, 3, _("Display"));
/* label_fmt */
- ENTRY(0, _("_Label format"), _("Leave blank to hide the label\n"
- EMBED_LABEL_FMT_TITLE " expands to the embedded window's title"),
- embed->label_fmt, embed_label_fmt_changed);
+ add_entry (embed, table, 0, embed->label_fmt, FALSE, embed_label_fmt_changed,
+ _("_Label format"),
+ _("Leave blank to hide the label\n"
+ EMBED_LABEL_FMT_TITLE " expands to the embedded window's title"));
/* label font */
- FONTBUTTON(1, _("Label _font"), _("Choose the label font"),
- embed->label_font, embed_label_font_changed);
+ add_fontbutton (embed, table, 1, embed->label_font, embed_label_font_changed,
+ _("Label _font"),
+ _("Choose the label font"));
/* min_size */
- SPIN(2, _("Minimum _size (px)"),
- _("Minimum size of the embedded window\n"
- "Set to 0 to keep the original window size"),
- embed->min_size, embed_min_size_changed);
+ add_spinbutton (embed, table, 2, embed->min_size, embed_min_size_changed,
+ _("Minimum _size (px)"),
+ _("Minimum size of the embedded window\n"
+ "Set to 0 to keep the original window size"));
/* expand */
- widget = gtk_check_button_new_with_mnemonic (_("_Expand"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), embed->expand);
- g_signal_connect (G_OBJECT (widget), "toggled",
- G_CALLBACK (embed_expand_toggled), embed);
- gtk_widget_set_tooltip_text (widget, _("Use up all available panel space"));
- ADD(widget, 3, 1);
-
-#undef ADD
-#undef TOOLTIP2
-#undef LABEL
-#undef ENTRY
-#undef FONTBUTTON
-#undef SPIN
-#undef START_FRAME
-
- gtk_widget_show_all (content);
+ add_checkbutton (embed, table, 3, embed->expand, embed_expand_toggled,
+ _("_Expand"),
+ _("Use up all available panel space"));
+
/* center dialog on the screen */
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
@@ -360,5 +407,5 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed)
G_CALLBACK (embed_configure_response), embed);
/* show the entire dialog */
- gtk_widget_show (dialog);
+ gtk_widget_show_all (dialog);
}
More information about the Xfce4-commits
mailing list