[gtk/state-saving: 6/14] paned: Add default state saving




commit 26c5240dcb23d709e338d47c3512bc951b99b835
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 2 23:10:18 2021 -0400

    paned: Add default state saving
    
    Save the paned position.

 gtk/gtkpaned.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index e12c8e5c9c..6e73bd07b3 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -390,6 +390,29 @@ gtk_paned_set_orientation (GtkPaned       *self,
     }
 }
 
+static gboolean
+gtk_paned_save_state (GtkWidget    *paned,
+                      GVariantDict *dict,
+                      gboolean     *save_children)
+{
+  g_variant_dict_insert (dict, "position", "i", gtk_paned_get_position (GTK_PANED (paned)));
+  *save_children = TRUE;
+
+  return TRUE;
+}
+
+static gboolean
+gtk_paned_restore_state (GtkWidget *paned,
+                         GVariant  *data)
+{
+  int value;
+
+  if (g_variant_lookup (data, "position", "i", &value))
+    gtk_paned_set_position(GTK_PANED (paned), value);
+
+  return TRUE;
+}
+
 static void
 gtk_paned_class_init (GtkPanedClass *class)
 {
@@ -408,6 +431,8 @@ gtk_paned_class_init (GtkPanedClass *class)
   widget_class->css_changed = gtk_paned_css_changed;
   widget_class->get_request_mode = gtk_paned_get_request_mode;
   widget_class->compute_expand = gtk_paned_compute_expand;
+  widget_class->save_state = gtk_paned_save_state;
+  widget_class->restore_state = gtk_paned_restore_state;
 
   class->cycle_child_focus = gtk_paned_cycle_child_focus;
   class->toggle_handle_focus = gtk_paned_toggle_handle_focus;


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