[gtk/entry-fix] inspector: Track readonly property values



commit 0fa4d54316adf4ff35d1307dab4901c5b854babc
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed May 1 04:57:54 2019 +0000

    inspector: Track readonly property values
    
    That a property can't be set does not mean
    its value can't change. This was showing up
    as the cursor-position and selection-bound
    properties in GtkText not showing their
    current value in the inspector.

 gtk/inspector/prop-editor.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/gtk/inspector/prop-editor.c b/gtk/inspector/prop-editor.c
index 1c1b5541ac..aad381b42e 100644
--- a/gtk/inspector/prop-editor.c
+++ b/gtk/inspector/prop-editor.c
@@ -819,7 +819,7 @@ property_editor (GObject                *object,
 
       prop_edit = gtk_spin_button_new (adj, 1.0, 0);
 
-      g_object_connect_property (object, spec, G_CALLBACK (int_changed), adj, G_OBJECT (adj)); 
+      g_object_connect_property (object, spec, G_CALLBACK (int_changed), adj, G_OBJECT (adj));
 
       connect_controller (G_OBJECT (adj), "value_changed",
                           object, spec, G_CALLBACK (int_modified));
@@ -1519,6 +1519,25 @@ add_gtk_settings_info (GtkInspectorPropEditor *editor)
   gtk_container_add (GTK_CONTAINER (editor), row);
 }
 
+static void
+readonly_changed (GObject    *object,
+                  GParamSpec *spec,
+                  gpointer    data)
+{
+  GValue gvalue = {0};
+  gchar *value;
+  gchar *type;
+
+  g_value_init (&gvalue, spec->value_type);
+  g_object_get_property (object, spec->name, &gvalue);
+  strdup_value_contents (&gvalue, &value, &type);
+
+  gtk_label_set_label (GTK_LABEL (data), value);
+
+  g_free (value);
+  g_free (type);
+}
+
 static void
 constructed (GObject *object)
 {
@@ -1557,20 +1576,14 @@ constructed (GObject *object)
 
   if (!can_modify)
     {
-      GValue gvalue = {0};
-      gchar *value;
-      gchar *type;
-
-      g_value_init (&gvalue, spec->value_type);
-      g_object_get_property (editor->priv->object, spec->name, &gvalue);
-      strdup_value_contents (&gvalue, &value, &type);
-
-      label = gtk_label_new (value);
+      label = gtk_label_new ("");
       gtk_style_context_add_class (gtk_widget_get_style_context (label), GTK_STYLE_CLASS_DIM_LABEL);
       gtk_container_add (GTK_CONTAINER (box), label);
 
-      g_free (value);
-      g_free (type);
+      readonly_changed (editor->priv->object, spec, label);
+      g_object_connect_property (editor->priv->object, spec,
+                                 G_CALLBACK (readonly_changed),
+                                 label, G_OBJECT (label));
 
       if (editor->priv->size_group)
         gtk_size_group_add_widget (editor->priv->size_group, box);


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