[gnome-builder] project-tree: remove synthesized "Empty" node before insertion
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] project-tree: remove synthesized "Empty" node before insertion
- Date: Wed, 6 Dec 2017 00:16:44 +0000 (UTC)
commit 4861ba8900af374b60bbc04c0ab637ed1a8c2d30
Author: Christian Hergert <chergert redhat com>
Date: Tue Dec 5 16:16:14 2017 -0800
project-tree: remove synthesized "Empty" node before insertion
If we have a synthesized "Empty" node in the tree, we should remove it
before inserting our newly created file. Otherwise, we'll do a node
comparison for insertion sort and segfault from a NULL DzlTreeNode:item
property.
https://bugzilla.gnome.org/show_bug.cgi?id=791278
src/plugins/project-tree/gb-project-tree-builder.c | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/project-tree/gb-project-tree-builder.c
b/src/plugins/project-tree/gb-project-tree-builder.c
index cf0a0a8..73ed58d 100644
--- a/src/plugins/project-tree/gb-project-tree-builder.c
+++ b/src/plugins/project-tree/gb-project-tree-builder.c
@@ -67,6 +67,7 @@ gb_project_tree_builder_add (GbProjectTreeBuilder *self,
g_autofree gchar *name = NULL;
g_autoptr(GFileInfo) file_info = NULL;
g_autoptr(GbProjectFile) item = NULL;
+ g_autoptr(DzlTreeNode) first = NULL;
DzlTreeNode *child;
const gchar *display_name;
const gchar *icon_name;
@@ -85,6 +86,16 @@ gb_project_tree_builder_add (GbProjectTreeBuilder *self,
if (file_info == NULL)
return;
+ /*
+ * If the parent has a single child and that is a dummy "Empty"
+ * item, then we should remove it before we add our child. We know
+ * it is an "Empty" item if it has no DzlTreeNode:item value.
+ */
+ first = dzl_tree_node_nth_child (parent, 0);
+ if (first != NULL && NULL == dzl_tree_node_get_item (first))
+ dzl_tree_node_remove (parent, first);
+
+ /* Now create our new node for the child. */
item = gb_project_file_new (file, file_info);
display_name = gb_project_file_get_display_name (item);
icon_name = gb_project_file_get_icon_name (item);
@@ -99,13 +110,16 @@ gb_project_tree_builder_add (GbProjectTreeBuilder *self,
"item", item,
NULL);
- dzl_tree_node_insert_sorted (parent, child, compare_nodes_func, self);
-
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
{
dzl_tree_node_set_children_possible (child, TRUE);
dzl_tree_node_set_reset_on_collapse (child, TRUE);
}
+
+ /* Insertion sort our child, which should now only have valid siblings
+ * or be the first child of the parent.
+ */
+ dzl_tree_node_insert_sorted (parent, child, compare_nodes_func, self);
}
static DzlTreeNode *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]