[gtk/treelistmodel-collapse-test: 1/2] treelistmodel: Fix handling of collapsed nodes




commit f1c1c979c2ddc5a73a1859edbd74b261735bd531
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Aug 24 08:20:33 2022 -0400

    treelistmodel: Fix handling of collapsed nodes
    
    When we collapse a node, we clear out the children,
    but we were not disconnecting the signal handler on
    the child listmodel, leading to bad outcomes when
    that model is persistent and changing.
    
    Fixes: #4595

 gtk/gtktreelistmodel.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtktreelistmodel.c b/gtk/gtktreelistmodel.c
index 268aa449ef..ab053b323f 100644
--- a/gtk/gtktreelistmodel.c
+++ b/gtk/gtktreelistmodel.c
@@ -441,22 +441,28 @@ gtk_tree_list_model_items_changed_cb (GListModel *model,
 static void gtk_tree_list_row_destroy (GtkTreeListRow *row);
 
 static void
-gtk_tree_list_model_clear_node (gpointer data)
+gtk_tree_list_model_clear_node_children (TreeNode *node)
 {
-  TreeNode *node = data;
-
-  if (node->row)
-    gtk_tree_list_row_destroy (node->row);
-
   if (node->model)
     {
       g_signal_handlers_disconnect_by_func (node->model,
                                             gtk_tree_list_model_items_changed_cb,
                                             node);
-      g_object_unref (node->model);
+      g_clear_object (&node->model);
     }
-  if (node->children)
-    gtk_rb_tree_unref (node->children);
+
+  g_clear_pointer (&node->children, gtk_rb_tree_unref);
+}
+
+static void
+gtk_tree_list_model_clear_node (gpointer data)
+{
+  TreeNode *node = data;
+
+  if (node->row)
+    gtk_tree_list_row_destroy (node->row);
+
+  gtk_tree_list_model_clear_node_children (node);
 }
 
 static void
@@ -551,8 +557,7 @@ gtk_tree_list_model_collapse_node (GtkTreeListModel *self,
 
   n_items = tree_node_get_n_children (node);
 
-  g_clear_pointer (&node->children, gtk_rb_tree_unref);
-  g_clear_object (&node->model);
+  gtk_tree_list_model_clear_node_children (node);
 
   tree_node_mark_dirty (node);
 


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