[gnome-builder] project-tree: sort directories first only if configured



commit 8b6725955065c81f76ec2c42857ebc814fedf744
Author: Daniel Buch <boogiewasthere gmail com>
Date:   Thu Feb 14 21:25:07 2019 +0100

    project-tree: sort directories first only if configured

 src/plugins/project-tree/gbp-project-tree-addin.c | 31 ++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/project-tree/gbp-project-tree-addin.c 
b/src/plugins/project-tree/gbp-project-tree-addin.c
index 470c784ce..809879189 100644
--- a/src/plugins/project-tree/gbp-project-tree-addin.c
+++ b/src/plugins/project-tree/gbp-project-tree-addin.c
@@ -350,8 +350,8 @@ collect_files (GFile *file,
 }
 
 static int
-node_compare (IdeTreeNode *node,
-              IdeTreeNode *child)
+node_compare_directories_first (IdeTreeNode *node,
+                                IdeTreeNode *child)
 {
   gint cmp;
   const gchar *child_name, *node_name;
@@ -384,6 +384,28 @@ node_compare (IdeTreeNode *node,
   return cmp > 0 ? cmp : 0;
 }
 
+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,
@@ -455,7 +477,10 @@ gbp_project_tree_addin_add_file (GbpProjectTreeAddin *self,
       project_file = ide_project_file_new (directory, info);
       node = create_file_node (project_file);
 
-      ide_tree_node_insert_sorted (parent, node, node_compare);
+      if (self->sort_directories_first)
+        ide_tree_node_insert_sorted (parent, node, node_compare_directories_first);
+      else
+        ide_tree_node_insert_sorted (parent, node, node_compare);
 
       if (!ide_tree_node_expanded (self->tree, parent))
         ide_tree_expand_node (self->tree, parent);


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