[Xfce4-commits] <xfce4-settings:nick/settings-editor> WIP: Add some more functionality to the property dialog.

Nick Schermer noreply at xfce.org
Sat Feb 4 14:22:01 CET 2012


Updating branch refs/heads/nick/settings-editor
         to 06c13c07a9823f3a501f013e0498a7cf7f21adc5 (commit)
       from 1f2b6ac09c598d3e74efe7d61577805a7f3721bb (commit)

commit 06c13c07a9823f3a501f013e0498a7cf7f21adc5
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Feb 4 14:19:51 2012 +0100

    WIP: Add some more functionality to the property dialog.

 .../xfce-settings-editor-dialog.c                  |   10 +-
 xfce4-settings-editor/xfce-settings-prop-dialog.c  |  186 +++++++++++++++++++-
 2 files changed, 189 insertions(+), 7 deletions(-)

diff --git a/xfce4-settings-editor/xfce-settings-editor-dialog.c b/xfce4-settings-editor/xfce-settings-editor-dialog.c
index c9934de..75a3126 100644
--- a/xfce4-settings-editor/xfce-settings-editor-dialog.c
+++ b/xfce4-settings-editor/xfce-settings-editor-dialog.c
@@ -90,7 +90,8 @@ enum
 
 
 
-static GSList *monitor_dialogs = NULL;
+static GSList         *monitor_dialogs = NULL;
+static GtkWindowGroup *monitor_group = NULL;
 
 
 
@@ -344,6 +345,9 @@ xfce_settings_editor_dialog_finalize (GObject *object)
         gtk_dialog_response (GTK_DIALOG (li->data), GTK_RESPONSE_CLOSE);
     }
 
+    if (monitor_group != NULL)
+       g_object_unref (G_OBJECT (monitor_group));
+
     g_object_unref (G_OBJECT (dialog->channels_store));
 
     g_object_unref (G_OBJECT (dialog->props_store));
@@ -932,6 +936,10 @@ xfce_settings_editor_dialog_channel_monitor (XfceSettingsEditorDialog *dialog)
 
     monitor_dialogs = g_slist_prepend (monitor_dialogs, window);
 
+    if (monitor_group == NULL)
+        monitor_group = gtk_window_group_new ();
+    gtk_window_group_add_window (monitor_group, GTK_WINDOW (window));
+
     scroll = gtk_scrolled_window_new (NULL, NULL);
     content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
     gtk_box_pack_start (GTK_BOX (content_area), scroll, TRUE, TRUE, 0);
diff --git a/xfce4-settings-editor/xfce-settings-prop-dialog.c b/xfce4-settings-editor/xfce-settings-prop-dialog.c
index f31b647..5ae5f57 100644
--- a/xfce4-settings-editor/xfce-settings-prop-dialog.c
+++ b/xfce4-settings-editor/xfce-settings-prop-dialog.c
@@ -54,8 +54,13 @@ struct _XfceSettingsPropDialog
 
     GValue         cancel_value;
 
+    gulong         prop_binding;
+
     GtkWidget     *prop_name;
     GtkWidget     *prop_type;
+    GtkWidget     *prop_string;
+    GtkWidget     *prop_integer;
+    GtkWidget     *prop_bool;
 };
 
 typedef struct
@@ -70,6 +75,11 @@ ValueTypes;
 static void     xfce_settings_prop_dialog_finalize             (GObject                   *object);
 static void     xfce_settings_prop_dialog_response             (GtkDialog                 *widget,
                                                                 gint                       response_id);
+static void     xfce_settings_prop_dialog_visible_bind         (GtkWidget                 *widget,
+                                                                GtkWidget                 *label);
+static void     xfce_settings_prop_dialog_button_toggled       (GtkWidget                 *button);
+static void     xfce_settings_prop_dialog_type_changed         (GtkWidget                 *combo,
+                                                                XfceSettingsPropDialog    *dialog);
 
 
 
@@ -124,22 +134,23 @@ xfce_settings_prop_dialog_init (XfceSettingsPropDialog *dialog)
     GtkWidget       *label;
     GtkWidget       *entry;
     GtkWidget       *combo;
+    GtkWidget       *spin;
+    GtkWidget       *toggle;
     GtkListStore    *store;
     guint            i;
     GtkCellRenderer *render;
 
     gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Property"));
-    gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 400);
+    gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 200);
     gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                             GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
     gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
-    table = gtk_table_new (3, 2, FALSE);
+    table = gtk_table_new (5, 2, FALSE);
     content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
     gtk_box_pack_start (GTK_BOX (content_area), table, TRUE, TRUE, 0);
     gtk_table_set_col_spacings (GTK_TABLE (table), 12);
-    gtk_table_set_row_spacings (GTK_TABLE (table), 6);
     gtk_container_set_border_width (GTK_CONTAINER (table), 6);
     gtk_widget_show (table);
 
@@ -147,12 +158,13 @@ xfce_settings_prop_dialog_init (XfceSettingsPropDialog *dialog)
     gtk_misc_set_alignment (GTK_MISC (label), 0.00, 0.50);
     gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
                       GTK_FILL, GTK_FILL, 0, 0);
+    gtk_table_set_row_spacing (GTK_TABLE (table), 0, 6);
     gtk_widget_show (label);
 
     dialog->prop_name = entry = gtk_entry_new ();
     gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
                       GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
-    gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+    xfce_settings_prop_dialog_visible_bind (entry, label);
     gtk_widget_show (entry);
 
     label = gtk_label_new_with_mnemonic (_("_Type:"));
@@ -172,8 +184,11 @@ xfce_settings_prop_dialog_init (XfceSettingsPropDialog *dialog)
     dialog->prop_type = combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
     gtk_table_attach (GTK_TABLE (table), combo, 1, 2, 1, 2,
                       GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
-    gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
+    gtk_table_set_row_spacing (GTK_TABLE (table), 1, 6);
+    xfce_settings_prop_dialog_visible_bind (combo, label);
     gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+    g_signal_connect (G_OBJECT (combo), "changed",
+        G_CALLBACK (xfce_settings_prop_dialog_type_changed), dialog);
     gtk_widget_show (combo);
     g_object_unref (G_OBJECT (store));
 
@@ -182,11 +197,41 @@ xfce_settings_prop_dialog_init (XfceSettingsPropDialog *dialog)
     gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), render,
                                    "text", COLUMN_NAME);
 
+    /* strings */
     label = gtk_label_new_with_mnemonic (_("_Value:"));
     gtk_misc_set_alignment (GTK_MISC (label), 0.00, 0.50);
     gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
                       GTK_FILL, GTK_FILL, 0, 0);
-    gtk_widget_show (label);
+
+    entry = dialog->prop_string = gtk_entry_new ();
+    gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 2, 3,
+                      GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+    xfce_settings_prop_dialog_visible_bind (entry, label);
+
+    /* integers */
+    label = gtk_label_new_with_mnemonic (_("_Value:"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.00, 0.50);
+    gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
+                      GTK_FILL, GTK_FILL, 0, 0);
+
+    spin = dialog->prop_integer = gtk_spin_button_new_with_range (0.00, 0.00, 1.00);
+    gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin), TRUE);
+    gtk_table_attach (GTK_TABLE (table), spin, 1, 2, 3, 4,
+                      GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+    xfce_settings_prop_dialog_visible_bind (spin, label);
+
+    /* bool */
+    label = gtk_label_new_with_mnemonic (_("_Value:"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.00, 0.50);
+    gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
+                      GTK_FILL, GTK_FILL, 0, 0);
+
+    toggle = dialog->prop_bool = gtk_toggle_button_new_with_label ("FALSE");
+    g_signal_connect (G_OBJECT (toggle), "toggled",
+        G_CALLBACK (xfce_settings_prop_dialog_button_toggled), NULL);
+    gtk_table_attach (GTK_TABLE (table), toggle, 1, 2, 4, 5,
+                      GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+    xfce_settings_prop_dialog_visible_bind (toggle, label);
 }
 
 
@@ -231,6 +276,134 @@ xfce_settings_prop_dialog_response (GtkDialog *widget,
 
 
 static void
+xfce_settings_prop_dialog_visible_changed (GtkWidget  *widget,
+                                           GParamSpec *pspec,
+                                           GtkWidget  *label)
+{
+    g_return_if_fail (GTK_IS_WIDGET (widget));
+    g_return_if_fail (GTK_IS_LABEL (label));
+
+    gtk_widget_set_visible (label, gtk_widget_get_visible (widget));
+}
+
+
+
+static void
+xfce_settings_prop_dialog_sensitive_changed (GtkWidget  *widget,
+                                             GParamSpec *pspec,
+                                             GtkWidget  *label)
+{
+    g_return_if_fail (GTK_IS_WIDGET (widget));
+    g_return_if_fail (GTK_IS_LABEL (label));
+
+    gtk_widget_set_sensitive (label, gtk_widget_get_sensitive (widget));
+}
+
+
+
+static void
+xfce_settings_prop_dialog_visible_bind (GtkWidget *widget,
+                                        GtkWidget *label)
+{
+    gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
+    g_signal_connect (G_OBJECT (widget), "notify::visible",
+        G_CALLBACK (xfce_settings_prop_dialog_visible_changed), label);
+    g_signal_connect (G_OBJECT (widget), "notify::sensitive",
+        G_CALLBACK (xfce_settings_prop_dialog_sensitive_changed), label);
+}
+
+
+
+static void
+xfce_settings_prop_dialog_button_toggled (GtkWidget *button)
+{
+    const gchar *label;
+
+    label = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) ? "TRUE" : "FALSE";
+    gtk_button_set_label (GTK_BUTTON (button), label);
+}
+
+
+
+static void
+xfce_settings_prop_dialog_type_changed (GtkWidget              *combo,
+                                        XfceSettingsPropDialog *dialog)
+{
+    gint        active;
+    ValueTypes *value_type;
+
+    gtk_widget_hide (dialog->prop_string);
+    gtk_widget_hide (dialog->prop_integer);
+    gtk_widget_hide (dialog->prop_bool);
+
+    if (dialog->prop_binding != 0)
+    {
+        xfconf_g_property_unbind (dialog->prop_binding);
+        dialog->prop_binding = 0;
+    }
+
+    active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+    if (active < 0 || active >= (gint) G_N_ELEMENTS (value_types))
+        return;
+
+    value_type = &value_types[active];
+
+    switch (value_type->type)
+    {
+        case G_TYPE_NONE:
+            return;
+
+        case G_TYPE_STRING:
+            gtk_widget_show (dialog->prop_string);
+
+            if (dialog->property != NULL)
+            {
+                dialog->prop_binding = xfconf_g_property_bind (dialog->channel,
+                                                               dialog->property,
+                                                               G_TYPE_STRING,
+                                                               dialog->prop_string,
+                                                               "text");
+            }
+            break;
+
+        case G_TYPE_BOOLEAN:
+            gtk_widget_show (dialog->prop_bool);
+
+            if (dialog->property != NULL)
+            {
+                dialog->prop_binding = xfconf_g_property_bind (dialog->channel,
+                                                               dialog->property,
+                                                               G_TYPE_BOOLEAN,
+                                                               dialog->prop_bool,
+                                                               "active");
+            }
+            break;
+
+        case G_TYPE_BOXED:
+            break;
+
+        case G_TYPE_INT:
+        case G_TYPE_DOUBLE:
+        case G_TYPE_UINT:
+        case G_TYPE_INT64:
+        case G_TYPE_UINT64:
+            gtk_widget_show (dialog->prop_integer);
+
+            if (dialog->property != NULL)
+            {
+                dialog->prop_binding = xfconf_g_property_bind (dialog->channel,
+                                                               dialog->property,
+                                                               value_type->type,
+                                                               dialog->prop_integer,
+                                                               "value");
+            }
+            break;
+    }
+}
+
+
+
+static void
 xfce_settings_prop_dialog_type_set_active (XfceSettingsPropDialog *dialog,
                                            GType                   value_type)
 {
@@ -276,6 +449,7 @@ xfce_settings_prop_dialog_new (GtkWindow     *parent,
 
         xfce_settings_prop_dialog_type_set_active (dialog,
             G_VALUE_TYPE (&dialog->cancel_value));
+        gtk_widget_set_sensitive (dialog->prop_type, FALSE);
     }
 
     /* set the transient parent (if any) */


More information about the Xfce4-commits mailing list