[gtk/state-saving: 5/12] switch: Add default state saving




commit b5e4bf728d2ef989fb601a8e9f16448c74d1105a
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 2 22:52:39 2021 -0400

    switch: Add default state saving

 gtk/gtkswitch.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
---
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index 5f7fff01bf..dccd3f9e2d 100644
--- a/gtk/gtkswitch.c
+++ b/gtk/gtkswitch.c
@@ -506,6 +506,29 @@ state_set (GtkSwitch *self,
   return TRUE;
 }
 
+static gboolean
+gtk_switch_save_state (GtkWidget    *self,
+                       GVariantDict *dict,
+                       gboolean     *save_children)
+{
+  g_variant_dict_insert (dict, "active", "b", gtk_switch_get_active (GTK_SWITCH (self)));
+  *save_children = FALSE;
+
+  return TRUE;
+}
+
+static gboolean
+gtk_switch_restore_state (GtkWidget *self,
+                          GVariant  *data)
+{
+  gboolean value;
+
+  if (g_variant_lookup (data, "active", "b", &value))
+    gtk_switch_set_active (GTK_SWITCH (self), value);
+
+  return TRUE;
+}
+
 static void
 gtk_switch_class_init (GtkSwitchClass *klass)
 {
@@ -545,6 +568,9 @@ gtk_switch_class_init (GtkSwitchClass *klass)
 
   g_object_class_install_properties (gobject_class, LAST_PROP, switch_props);
 
+  widget_class->save_state = gtk_switch_save_state;
+  widget_class->restore_state = gtk_switch_restore_state;
+
   klass->activate = gtk_switch_activate;
   klass->state_set = state_set;
 


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