[gtk/editable-label: 2/3] gtk-demo: Use editable labels in the settings demo



commit 1d93ddd453d09dca082e641d42749db7bb59868a
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 12 11:07:37 2020 -0400

    gtk-demo: Use editable labels in the settings demo
    
    This is more in line with the expected behavior for
    editable lists.

 demos/gtk-demo/listview_settings.c  | 20 +++++++++++++++-----
 demos/gtk-demo/listview_settings.ui |  7 +++----
 2 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/demos/gtk-demo/listview_settings.c b/demos/gtk-demo/listview_settings.c
index e5908047b3..3c0de54d9f 100644
--- a/demos/gtk-demo/listview_settings.c
+++ b/demos/gtk-demo/listview_settings.c
@@ -143,8 +143,9 @@ settings_key_new (GSettings          *settings,
 }
 
 static void
-item_value_changed (GtkListItem *item,
-                    GtkEntry    *entry)
+item_value_changed (GtkEditableLabel *label,
+                    GParamSpec       *pspec,
+                    GtkListItem      *item)
 {
   SettingsKey *self;
   const char *text;
@@ -152,8 +153,9 @@ item_value_changed (GtkListItem *item,
   GVariant *variant;
   GError *error = NULL;
   const char *name;
+  char *value;
 
-  text = gtk_editable_get_text (GTK_EDITABLE (entry));
+  text = gtk_editable_get_text (GTK_EDITABLE (label));
 
   g_object_get (item, "item", &self, NULL);
   g_object_unref (self);
@@ -166,17 +168,25 @@ item_value_changed (GtkListItem *item,
     {
       g_warning ("%s", error->message);
       g_clear_error (&error);
-      return;
+      goto revert;
     }
 
   if (!g_settings_schema_key_range_check (self->key, variant))
     {
       g_warning ("Not a valid value for %s", name);
-      return;
+      goto revert;
     }
 
   g_settings_set_value (self->settings, name, variant);
   g_variant_unref (variant);
+  return;
+
+revert:
+  gtk_widget_error_bell (GTK_WIDGET (label));
+
+  g_object_get (self, "value", &value, NULL);
+  gtk_editable_set_text (GTK_EDITABLE (label), value);
+  g_free (value);
 }
 
 static int
diff --git a/demos/gtk-demo/listview_settings.ui b/demos/gtk-demo/listview_settings.ui
index cf2651d50b..8bf7e2582d 100644
--- a/demos/gtk-demo/listview_settings.ui
+++ b/demos/gtk-demo/listview_settings.ui
@@ -113,14 +113,13 @@
 <interface>
   <template class="GtkListItem">
     <property name="child">
-      <object class="GtkEntry">
-        <signal name="activate" handler="item_value_changed" object="GtkListItem" swapped="yes"/>
-        <property name="xalign">0</property>
-        <binding name="text">
+      <object class="GtkEditableLabel">
+        <binding name="label">
           <lookup name="value" type="SettingsKey">
             <lookup name="item">GtkListItem</lookup>
           </lookup>
         </binding>
+        <signal name="notify::label" handler="item_value_changed"/>
       </object>
     </property>
   </template>


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