[gnome-builder] project-tree: Use ide_tree_node_insert_sorted() for add_file()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] project-tree: Use ide_tree_node_insert_sorted() for add_file()
- Date: Tue, 15 Jan 2019 21:25:33 +0000 (UTC)
commit 6b55406aad2e7d9f6098c001b23a7d6beefd37dd
Author: Daniel Buch <boogiewasthere gmail com>
Date: Tue Jan 15 21:20:14 2019 +0100
project-tree: Use ide_tree_node_insert_sorted() for add_file()
src/plugins/project-tree/gbp-project-tree-addin.c | 27 +++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/project-tree/gbp-project-tree-addin.c
b/src/plugins/project-tree/gbp-project-tree-addin.c
index d3d0a7f48..7c23a996c 100644
--- a/src/plugins/project-tree/gbp-project-tree-addin.c
+++ b/src/plugins/project-tree/gbp-project-tree-addin.c
@@ -347,6 +347,30 @@ collect_files (GFile *file,
return g_steal_pointer (&list);
}
+static int
+node_compare (IdeTreeNode *node,
+ IdeTreeNode *child)
+{
+ gint cmp;
+ const gchar *child_name, *node_name;
+ g_autofree gchar *collated_child = NULL;
+ g_autofree gchar *collated_node = NULL;
+
+ g_assert (IDE_IS_TREE_NODE (node));
+ g_assert (IDE_IS_TREE_NODE (child));
+
+ child_name = ide_tree_node_get_display_name (child);
+ node_name = ide_tree_node_get_display_name (node);
+
+ collated_child = g_utf8_collate_key_for_filename (child_name, -1);
+ collated_node = g_utf8_collate_key_for_filename (node_name, -1);
+
+ cmp = g_strcmp0 (collated_child, collated_node);
+
+ return cmp > 0 ? cmp : 0;
+}
+
+
static void
gbp_project_tree_addin_add_file (GbpProjectTreeAddin *self,
GFile *file)
@@ -409,8 +433,7 @@ gbp_project_tree_addin_add_file (GbpProjectTreeAddin *self,
project_file = ide_project_file_new (directory, info);
node = create_file_node (project_file);
- /* TODO: Sort item */
- ide_tree_node_append (parent, node);
+ ide_tree_node_insert_sorted (parent, node, node_compare);
}
IDE_EXIT;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]