[gnome-builder] libide/tweaks: GC old pages after transitions complete



commit a491ef608297b676cafe9ba44e2e0b62e646a53c
Author: Christian Hergert <chergert redhat com>
Date:   Tue Aug 2 22:49:09 2022 -0700

    libide/tweaks: GC old pages after transitions complete

 src/libide/tweaks/ide-tweaks-window.c  | 40 ++++++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-window.ui |  1 +
 2 files changed, 41 insertions(+)
---
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index 2238c73ff..7d4d0cabc 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -26,6 +26,8 @@
 #include "ide-tweaks-panel-list-private.h"
 #include "ide-tweaks-window.h"
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GtkStackPage, g_object_unref)
+
 struct _IdeTweaksWindow
 {
   AdwWindow  parent_instance;
@@ -127,6 +129,43 @@ ide_tweaks_window_rebuild (IdeTweaksWindow *self)
   ide_tweaks_panel_list_select_first (IDE_TWEAKS_PANEL_LIST (list));
 }
 
+static void
+panel_stack_notify_transition_running_cb (IdeTweaksWindow *self,
+                                          GParamSpec      *pspec,
+                                          GtkStack        *stack)
+{
+  GtkSelectionModel *model;
+  IdeTweaksPage *current_page;
+  guint n_items;
+
+  g_assert (IDE_IS_TWEAKS_WINDOW (self));
+  g_assert (GTK_IS_STACK (stack));
+
+  if (gtk_stack_get_transition_running (stack))
+    return;
+
+  if (!(current_page = ide_tweaks_window_get_current_page (self)))
+    return;
+
+  model = gtk_stack_get_pages (stack);
+  n_items = g_list_model_get_n_items (G_LIST_MODEL (model));
+
+  for (guint i = n_items; i > 0; i--)
+    {
+      g_autoptr(GtkStackPage) page = g_list_model_get_item (G_LIST_MODEL (model), i - 1);
+      IdeTweaksPanel *panel;
+      IdeTweaksPage *item;
+
+      panel = IDE_TWEAKS_PANEL (gtk_stack_page_get_child (page));
+      item = ide_tweaks_panel_get_page (panel);
+
+      if (item != NULL &&
+          item != current_page &&
+          !ide_tweaks_item_is_ancestor (IDE_TWEAKS_ITEM (current_page), IDE_TWEAKS_ITEM (item)))
+        gtk_stack_remove (stack, GTK_WIDGET (panel));
+    }
+}
+
 static void
 ide_tweaks_window_dispose (GObject *object)
 {
@@ -199,6 +238,7 @@ ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/libide-tweaks/ide-tweaks-window.ui");
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_stack);
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_list_stack);
+  gtk_widget_class_bind_template_callback (widget_class, panel_stack_notify_transition_running_cb);
 
   g_type_ensure (IDE_TYPE_TWEAKS_PANEL);
   g_type_ensure (IDE_TYPE_TWEAKS_PANEL_LIST);
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
index 9a8ef9136..24892850d 100644
--- a/src/libide/tweaks/ide-tweaks-window.ui
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -108,6 +108,7 @@
                 <property name="vexpand">true</property>
                 <property name="transition-type">crossfade</property>
                 <property name="width-request">360</property>
+                <signal name="notify::transition-running" handler="panel_stack_notify_transition_running_cb" 
swapped="true" object="IdeTweaksWindow"/>
                 <style>
                   <class name="background"/>
                 </style>


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