[gtk/stack-fixes] sidebar: Stop connecting to the stack ::destroy



commit 1dfe5c87fbc39a1a71e1e9425ba2edab69d9f54d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 9 19:09:22 2019 -0500

    sidebar: Stop connecting to the stack ::destroy
    
    No need for this, the model gets empties, we can just
    listen for that.
    
    Also, avoid notification when unsetting the stack in
    dispose.

 gtk/gtkstacksidebar.c | 52 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkstacksidebar.c b/gtk/gtkstacksidebar.c
index 112093b2bf..77fabd66b2 100644
--- a/gtk/gtkstacksidebar.c
+++ b/gtk/gtkstacksidebar.c
@@ -365,7 +365,6 @@ disconnect_stack_signals (GtkStackSidebar *sidebar)
 
   g_signal_handlers_disconnect_by_func (priv->pages, items_changed_cb, sidebar);
   g_signal_handlers_disconnect_by_func (priv->pages, selection_changed_cb, sidebar);
-  g_signal_handlers_disconnect_by_func (priv->stack, disconnect_stack_signals, sidebar);
 }
 
 static void
@@ -375,7 +374,35 @@ connect_stack_signals (GtkStackSidebar *sidebar)
 
   g_signal_connect (priv->pages, "items-changed", G_CALLBACK (items_changed_cb), sidebar);
   g_signal_connect (priv->pages, "selection-changed", G_CALLBACK (selection_changed_cb), sidebar);
-  g_signal_connect_swapped (priv->stack, "destroy", G_CALLBACK (disconnect_stack_signals), sidebar);
+}
+
+static void
+set_stack (GtkStackSidebar *sidebar,
+           GtkStack        *stack)
+{
+  GtkStackSidebarPrivate *priv = gtk_stack_sidebar_get_instance_private (sidebar);
+
+  if (stack)
+    {
+      priv->stack = g_object_ref (stack);
+      priv->pages = gtk_stack_get_pages (stack);
+      populate_sidebar (sidebar);
+      connect_stack_signals (sidebar);
+    }
+}
+
+static void
+unset_stack (GtkStackSidebar *sidebar)
+{
+  GtkStackSidebarPrivate *priv = gtk_stack_sidebar_get_instance_private (sidebar);
+
+  if (priv->stack)
+    {
+      disconnect_stack_signals (sidebar);
+      clear_sidebar (sidebar);
+      g_clear_object (&priv->stack);
+      g_clear_object (&priv->pages);
+    }
 }
 
 static void
@@ -383,7 +410,7 @@ gtk_stack_sidebar_dispose (GObject *object)
 {
   GtkStackSidebar *sidebar = GTK_STACK_SIDEBAR (object);
 
-  gtk_stack_sidebar_set_stack (sidebar, NULL);
+  unset_stack (sidebar);
 
   G_OBJECT_CLASS (gtk_stack_sidebar_parent_class)->dispose (object);
 }
@@ -448,30 +475,17 @@ void
 gtk_stack_sidebar_set_stack (GtkStackSidebar *sidebar,
                              GtkStack        *stack)
 {
-  GtkStackSidebarPrivate *priv;
+  GtkStackSidebarPrivate *priv = gtk_stack_sidebar_get_instance_private (sidebar);
 
   g_return_if_fail (GTK_IS_STACK_SIDEBAR (sidebar));
   g_return_if_fail (GTK_IS_STACK (stack) || stack == NULL);
 
-  priv = gtk_stack_sidebar_get_instance_private (sidebar);
 
   if (priv->stack == stack)
     return;
 
-  if (priv->stack)
-    {
-      disconnect_stack_signals (sidebar);
-      clear_sidebar (sidebar);
-      g_clear_object (&priv->stack);
-      g_clear_object (&priv->pages);
-    }
-  if (stack)
-    {
-      priv->stack = g_object_ref (stack);
-      priv->pages = gtk_stack_get_pages (stack);
-      populate_sidebar (sidebar);
-      connect_stack_signals (sidebar);
-    }
+  unset_stack (sidebar);
+  set_stack (sidebar, stack);
 
   gtk_widget_queue_resize (GTK_WIDGET (sidebar));
 


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