[gtk/prop-list: 5/5] inspector: Use dropdowns in property editor



commit 19fd65c5070f0508d6f7bcee6d4e836a48d239f5
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 13 16:19:53 2019 -0500

    inspector: Use dropdowns in property editor
    
    Replace combo boxes by dropdowns in the property editor.

 gtk/inspector/prop-editor.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)
---
diff --git a/gtk/inspector/prop-editor.c b/gtk/inspector/prop-editor.c
index 170e39ba9e..e272e6bbcb 100644
--- a/gtk/inspector/prop-editor.c
+++ b/gtk/inspector/prop-editor.c
@@ -450,14 +450,12 @@ bool_changed (GObject *object, GParamSpec *pspec, gpointer data)
 }
 
 static void
-enum_modified (GtkComboBox *combo, ObjectProperty *p)
+enum_modified (GtkDropDown *dropdown, GParamSpec *pspec, ObjectProperty *p)
 {
-  gint i;
+  int i = gtk_drop_down_get_selected (dropdown);
   GEnumClass *eclass;
   GValue val = G_VALUE_INIT;
 
-  i = gtk_combo_box_get_active (combo);
-
   eclass = G_ENUM_CLASS (g_type_class_peek (p->spec->value_type));
 
   g_value_init (&val, p->spec->value_type);
@@ -469,7 +467,6 @@ enum_modified (GtkComboBox *combo, ObjectProperty *p)
 static void
 enum_changed (GObject *object, GParamSpec *pspec, gpointer data)
 {
-  GtkComboBox *combo = GTK_COMBO_BOX (data);
   GValue val = G_VALUE_INIT;
   GEnumClass *eclass;
   gint i;
@@ -488,9 +485,9 @@ enum_changed (GObject *object, GParamSpec *pspec, gpointer data)
     }
   g_value_unset (&val);
 
-  block_controller (G_OBJECT (combo));
-  gtk_combo_box_set_active (combo, i);
-  unblock_controller (G_OBJECT (combo));
+  block_controller (G_OBJECT (data));
+  gtk_drop_down_set_selected (GTK_DROP_DOWN (data), i);
+  unblock_controller (G_OBJECT (data));
 }
 
 static void
@@ -911,23 +908,22 @@ property_editor (GObject                *object,
     {
       {
         GEnumClass *eclass;
+        char **names;
         gint j;
 
-        prop_edit = gtk_combo_box_text_new ();
-
         eclass = G_ENUM_CLASS (g_type_class_ref (spec->value_type));
 
-        j = 0;
-        while (j < eclass->n_values)
-          {
-            gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (prop_edit),
-                                       eclass->values[j].value_name,
-                                       eclass->values[j].value_nick);
-            ++j;
-          }
+        names = g_new (char *, eclass->n_values + 1);
+        for (j = 0; j < eclass->n_values; j++)
+          names[j] = (char *)eclass->values[j].value_name;
+        names[eclass->n_values] = NULL;
+
+        prop_edit = gtk_drop_down_new_from_strings ((const char **)names);
+
+        g_free (names);
 
-            connect_controller (G_OBJECT (prop_edit), "changed",
-                                object, spec, G_CALLBACK (enum_modified));
+        connect_controller (G_OBJECT (prop_edit), "notify::selected",
+                            object, spec, G_CALLBACK (enum_modified));
 
         g_type_class_unref (eclass);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]