[gtk/state-saving: 7/12] stack: Add default state saving




commit fe6e75732c72f7b195161885ee60a2048cf9b622
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 2 23:11:05 2021 -0400

    stack: Add default state saving
    
    Save the current child.

 gtk/gtkstack.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index d53eb0653a..8106efea55 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -794,6 +794,29 @@ gtk_stack_set_property (GObject     *object,
     }
 }
 
+static gboolean
+gtk_stack_save_state (GtkWidget    *widget,
+                      GVariantDict *dict,
+                      gboolean     *save_children)
+{
+  g_variant_dict_insert (dict, "visible-page", "s", gtk_stack_get_visible_child_name (GTK_STACK (widget)));
+  *save_children = TRUE;
+
+  return TRUE;
+}
+
+static gboolean
+gtk_stack_restore_state (GtkWidget *widget,
+                         GVariant  *data)
+{
+  const char *name;
+
+  if (g_variant_lookup (data, "visible-page", "&s", &name))
+    gtk_stack_set_visible_child_name (GTK_STACK (widget), name);
+
+  return TRUE;
+}
+
 static void
 gtk_stack_class_init (GtkStackClass *klass)
 {
@@ -810,6 +833,8 @@ gtk_stack_class_init (GtkStackClass *klass)
   widget_class->measure = gtk_stack_measure;
   widget_class->compute_expand = gtk_stack_compute_expand;
   widget_class->get_request_mode = gtk_stack_get_request_mode;
+  widget_class->save_state = gtk_stack_save_state;
+  widget_class->restore_state = gtk_stack_restore_state;
 
   /**
    * GtkStack:hhomogeneous: (attributes org.gtk.Property.get=gtk_stack_get_hhomogeneous 
org.gtk.Property.set=gtk_stack_set_hhomogeneous)


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