From d0648a5c6ec0315a1d264a2d81af91370434856c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 19 Mar 2023 17:07:53 +0000 Subject: [PATCH] Merge branch 'wip/otte/for-main' into 'main' treelistmodel: Clear item in right place Closes #5681 See merge request GNOME/gtk!5682 (cherry picked from commit 56b904f1e6edec67e95e6d6ea3004d73eb343121) dd1e76e6 treelistmodel: Clear item in right place --- gtk/gtktreelistmodel.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gtk/gtktreelistmodel.c b/gtk/gtktreelistmodel.c index 8a189fe2ce..dd3b3009cc 100644 --- a/gtk/gtktreelistmodel.c +++ b/gtk/gtktreelistmodel.c @@ -362,6 +362,7 @@ gtk_tree_list_model_items_changed_cb (GListModel *model, child = gtk_rb_tree_insert_before (node->children, child); child->parent = node; child->item = g_list_model_get_item (model, position + i); + g_assert (child->item); } if (self->autoexpand) { @@ -387,8 +388,6 @@ static void gtk_tree_list_row_destroy (GtkTreeListRow *row); static void gtk_tree_list_model_clear_node_children (TreeNode *node) { - g_clear_object (&node->item); - if (node->model) { g_signal_handlers_disconnect_by_func (node->model, @@ -409,6 +408,8 @@ gtk_tree_list_model_clear_node (gpointer data) gtk_tree_list_row_destroy (node->row); gtk_tree_list_model_clear_node_children (node); + + g_clear_object (&node->item); } static void @@ -464,6 +465,7 @@ gtk_tree_list_model_init_node (GtkTreeListModel *list, node = gtk_rb_tree_insert_after (self->children, node); node->parent = self; node->item = g_list_model_get_item (model, i); + g_assert (node ->item); if (list->autoexpand) gtk_tree_list_model_expand_node (list, node); } @@ -945,12 +947,13 @@ gtk_tree_list_row_destroy (GtkTreeListRow *self) { g_object_freeze_notify (G_OBJECT (self)); + self->node = NULL; + /* FIXME: We could check some properties to avoid excess notifies */ g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_DEPTH]); g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_EXPANDABLE]); g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_EXPANDED]); - self->node = NULL; g_object_thaw_notify (G_OBJECT (self)); }