[gnome-builder] project-tree: allow displaying files ignored by VCS



commit 5052d4c48c381de3380ff5f830ca1fc67bece5bf
Author: Christian Hergert <christian hergert me>
Date:   Sun Jun 21 17:05:42 2015 -0700

    project-tree: allow displaying files ignored by VCS
    
    Occasionally we might want to be able to see files ignored by the VCS.
    This allows us to display them by setting the "show-ignored-files"
    GSetting.
    
    We probably want to alter the foreground color of the ignored files, but
    we can do that in a suplimental commit.

 .../org.gnome.builder.project-tree.gschema.xml     |   11 +-
 data/gtk/menus.ui                                  |    4 +
 src/project-tree/gb-project-tree-actions.c         |   34 ++-----
 src/project-tree/gb-project-tree-builder.c         |   12 ++-
 src/project-tree/gb-project-tree-private.h         |    1 +
 src/project-tree/gb-project-tree.c                 |  105 ++++++++++++++++----
 src/project-tree/gb-project-tree.h                 |   13 ++-
 7 files changed, 125 insertions(+), 55 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.project-tree.gschema.xml 
b/data/gsettings/org.gnome.builder.project-tree.gschema.xml
index 655f59c..25f7f4b 100644
--- a/data/gsettings/org.gnome.builder.project-tree.gschema.xml
+++ b/data/gsettings/org.gnome.builder.project-tree.gschema.xml
@@ -8,13 +8,12 @@
     <key name="show-icons" type="b">
       <default>true</default>
       <summary>Show Icons</summary>
-      <description>If enabled, the sidebar will display icons next to each item.</description>
+      <description>If enabled, the project tree will display icons next to each item.</description>
     </key>
-    <key name="width" type="i">
-      <range min="1" max="1000"/>
-      <default>250</default>
-      <summary>Project Tree Width</summary>
-      <description>The width in pixels of the project tree.</description>
+    <key name="show-ignored-files" type="b">
+      <default>false</default>
+      <summary>Show Ignored Files</summary>
+      <description>If enabled, the project tree will display files that are ignored by the VCS.</description>
     </key>
   </schema>
 </schemalist>
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index 7a8738e..131df18 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -107,6 +107,10 @@
             <attribute name="action">project-tree.show-icons</attribute>
           </item>
           <item>
+            <attribute name="label" translatable="yes">Show Ignored Files</attribute>
+            <attribute name="action">project-tree.show-ignored-files</attribute>
+          </item>
+          <item>
             <attribute name="label" translatable="yes">Sort Directories First</attribute>
             <attribute name="action">project-tree.sort-directories-first</attribute>
           </item>
diff --git a/src/project-tree/gb-project-tree-actions.c b/src/project-tree/gb-project-tree-actions.c
index 77095ce..173fc2b 100644
--- a/src/project-tree/gb-project-tree-actions.c
+++ b/src/project-tree/gb-project-tree-actions.c
@@ -341,22 +341,6 @@ gb_project_tree_actions_open_in_terminal (GSimpleAction *action,
 }
 
 static void
-gb_project_tree_actions_show_icons (GSimpleAction *action,
-                                    GVariant      *variant,
-                                    gpointer       user_data)
-{
-  GbProjectTree *self = user_data;
-  gboolean show_icons;
-
-  g_assert (GB_IS_PROJECT_TREE (self));
-  g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN));
-
-  show_icons = g_variant_get_boolean (variant);
-  gb_tree_set_show_icons (GB_TREE (self), show_icons);
-  g_simple_action_set_state (action, variant);
-}
-
-static void
 gb_project_tree_actions__make_directory_cb (GObject      *object,
                                             GAsyncResult *result,
                                             gpointer      user_data)
@@ -842,7 +826,6 @@ static GActionEntry GbProjectTreeActions[] = {
   { "open-with-editor",       gb_project_tree_actions_open_with_editor },
   { "refresh",                gb_project_tree_actions_refresh },
   { "rename-file",            gb_project_tree_actions_rename_file },
-  { "show-icons",             NULL, NULL, "false", gb_project_tree_actions_show_icons },
 };
 
 void
@@ -851,14 +834,15 @@ gb_project_tree_actions_init (GbProjectTree *self)
   g_autoptr(GSettings) settings = NULL;
   g_autoptr(GSettings) tree_settings = NULL;
   g_autoptr(GSimpleActionGroup) actions = NULL;
-  g_autoptr(GAction) action = NULL;
-  g_autoptr(GVariant) show_icons = NULL;
+  g_autoptr(GVariant) show_ignored_files = NULL;
+  GAction *action;
 
   actions = g_simple_action_group_new ();
 
   settings = g_settings_new ("org.gtk.Settings.FileChooser");
   action = g_settings_create_action (settings, "sort-directories-first");
   g_action_map_add_action (G_ACTION_MAP (actions), action);
+  g_clear_object (&action);
 
   g_action_map_add_action_entries (G_ACTION_MAP (actions),
                                    GbProjectTreeActions,
@@ -869,10 +853,14 @@ gb_project_tree_actions_init (GbProjectTree *self)
                                   G_ACTION_GROUP (actions));
 
   tree_settings = g_settings_new ("org.gnome.builder.project-tree");
-  show_icons = g_settings_get_value (tree_settings, "show-icons");
-  action_set (G_ACTION_GROUP (actions), "show-icons",
-              "state", show_icons,
-              NULL);
+
+  action = g_settings_create_action (tree_settings, "show-ignored-files");
+  g_action_map_add_action (G_ACTION_MAP (actions), action);
+  g_clear_object (&action);
+
+  action = g_settings_create_action (tree_settings, "show-icons");
+  g_action_map_add_action (G_ACTION_MAP (actions), action);
+  g_clear_object (&action);
 
   gb_project_tree_actions_update (self);
 }
diff --git a/src/project-tree/gb-project-tree-builder.c b/src/project-tree/gb-project-tree-builder.c
index 74804a2..2bbe134 100644
--- a/src/project-tree/gb-project-tree-builder.c
+++ b/src/project-tree/gb-project-tree-builder.c
@@ -18,8 +18,9 @@
 
 #include <glib/gi18n.h>
 
-#include "gb-project-tree-builder.h"
 #include "gb-project-file.h"
+#include "gb-project-tree.h"
+#include "gb-project-tree-builder.h"
 #include "gb-tree.h"
 #include "gb-widget.h"
 #include "gb-workbench.h"
@@ -121,12 +122,17 @@ build_file (GbProjectTreeBuilder *self,
   gpointer file_info_ptr;
   IdeVcs *vcs;
   GFile *file;
+  GbTree *tree;
+  gboolean show_ignored_files;
 
   g_return_if_fail (GB_IS_PROJECT_TREE_BUILDER (self));
   g_return_if_fail (GB_IS_TREE_NODE (node));
 
   project_file = GB_PROJECT_FILE (gb_tree_node_get_item (node));
 
+  tree = gb_tree_builder_get_tree (GB_TREE_BUILDER (self));
+  show_ignored_files = gb_project_tree_get_show_ignored_files (GB_PROJECT_TREE (tree));
+
   vcs = get_vcs (node);
 
   /*
@@ -158,11 +164,13 @@ build_file (GbProjectTreeBuilder *self,
       const gchar *name;
       const gchar *display_name;
       const gchar *icon_name;
+      gboolean ignored;
 
       name = g_file_info_get_name (item_file_info);
       item_file = g_file_get_child (file, name);
 
-      if (ide_vcs_is_ignored (vcs, item_file, NULL))
+      ignored = ide_vcs_is_ignored (vcs, item_file, NULL);
+      if (ignored && !show_ignored_files)
         continue;
 
       item = gb_project_file_new (item_file, item_file_info);
diff --git a/src/project-tree/gb-project-tree-private.h b/src/project-tree/gb-project-tree-private.h
index 165b30d..d63b95f 100644
--- a/src/project-tree/gb-project-tree-private.h
+++ b/src/project-tree/gb-project-tree-private.h
@@ -30,6 +30,7 @@ struct _GbProjectTree
   GSettings *settings;
 
   guint      expanded_in_new : 1;
+  guint      show_ignored_files : 1;
 };
 
 G_END_DECLS
diff --git a/src/project-tree/gb-project-tree.c b/src/project-tree/gb-project-tree.c
index 84529a5..d34ef22 100644
--- a/src/project-tree/gb-project-tree.c
+++ b/src/project-tree/gb-project-tree.c
@@ -28,29 +28,20 @@
 
 G_DEFINE_TYPE (GbProjectTree, gb_project_tree, GB_TYPE_TREE)
 
+enum {
+  PROP_0,
+  PROP_SHOW_IGNORED_FILES,
+  LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
 GtkWidget *
 gb_project_tree_new (void)
 {
   return g_object_new (GB_TYPE_PROJECT_TREE, NULL);
 }
 
-guint
-gb_project_tree_get_desired_width (GbProjectTree *self)
-{
-  return g_settings_get_int (self->settings, "width");
-}
-
-void
-gb_project_tree_save_desired_width (GbProjectTree *self)
-{
-  GtkAllocation alloc;
-  guint width;
-
-  gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
-  width = CLAMP (alloc.width, WIDTH_MIN, WIDTH_MAX);
-  g_settings_set_int (self->settings, "width", width);
-}
-
 IdeContext *
 gb_project_tree_get_context (GbProjectTree *self)
 {
@@ -118,11 +109,60 @@ gb_project_tree_finalize (GObject *object)
 }
 
 static void
+gb_project_tree_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  GbProjectTree *self = GB_PROJECT_TREE(object);
+
+  switch (prop_id)
+    {
+    case PROP_SHOW_IGNORED_FILES:
+      g_value_set_boolean (value, gb_project_tree_get_show_ignored_files (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gb_project_tree_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  GbProjectTree *self = GB_PROJECT_TREE(object);
+
+  switch (prop_id)
+    {
+    case PROP_SHOW_IGNORED_FILES:
+      gb_project_tree_set_show_ignored_files (self, g_value_get_boolean (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
 gb_project_tree_class_init (GbProjectTreeClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->finalize = gb_project_tree_finalize;
+  object_class->get_property = gb_project_tree_get_property;
+  object_class->set_property = gb_project_tree_set_property;
+
+  gParamSpecs [PROP_SHOW_IGNORED_FILES] =
+    g_param_spec_boolean ("show-ignored-files",
+                          _("Show Ignored Files"),
+                          _("If files ignored by the VCS should be displayed."),
+                         FALSE,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 }
 
 static void
@@ -131,7 +171,12 @@ gb_project_tree_init (GbProjectTree *self)
   GbTreeBuilder *builder;
 
   self->settings = g_settings_new ("org.gnome.builder.project-tree");
-  g_settings_bind (self->settings, "show-icons", self, "show-icons",
+
+  g_settings_bind (self->settings, "show-icons",
+                   self, "show-icons",
+                   G_SETTINGS_BIND_DEFAULT);
+  g_settings_bind (self->settings, "show-ignored-files",
+                   self, "show-ignored-files",
                    G_SETTINGS_BIND_DEFAULT);
 
   builder = gb_project_tree_builder_new ();
@@ -144,3 +189,27 @@ gb_project_tree_init (GbProjectTree *self)
 
   gb_project_tree_actions_init (self);
 }
+
+gboolean
+gb_project_tree_get_show_ignored_files (GbProjectTree *self)
+{
+  g_return_val_if_fail (GB_IS_PROJECT_TREE (self), FALSE);
+
+  return self->show_ignored_files;
+}
+
+void
+gb_project_tree_set_show_ignored_files (GbProjectTree *self,
+                                        gboolean       show_ignored_files)
+{
+  g_return_if_fail (GB_IS_PROJECT_TREE (self));
+
+  show_ignored_files = !!show_ignored_files;
+
+  if (show_ignored_files != self->show_ignored_files)
+    {
+      self->show_ignored_files = show_ignored_files;
+      g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_SHOW_IGNORED_FILES]);
+      gb_tree_rebuild (GB_TREE (self));
+    }
+}
diff --git a/src/project-tree/gb-project-tree.h b/src/project-tree/gb-project-tree.h
index d91d703..9e7358e 100644
--- a/src/project-tree/gb-project-tree.h
+++ b/src/project-tree/gb-project-tree.h
@@ -29,12 +29,13 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbProjectTree, gb_project_tree, GB, PROJECT_TREE, GbTree)
 
-GtkWidget  *gb_project_tree_new                (void);
-void        gb_project_tree_set_context        (GbProjectTree *self,
-                                                IdeContext    *context);
-IdeContext *gb_project_tree_get_context        (GbProjectTree *self);
-guint       gb_project_tree_get_desired_width  (GbProjectTree *self);
-void        gb_project_tree_save_desired_width (GbProjectTree *self);
+GtkWidget  *gb_project_tree_new                    (void);
+void        gb_project_tree_set_context            (GbProjectTree *self,
+                                                    IdeContext    *context);
+IdeContext *gb_project_tree_get_context            (GbProjectTree *self);
+gboolean    gb_project_tree_get_show_ignored_files (GbProjectTree *self);
+void        gb_project_tree_set_show_ignored_files (GbProjectTree *self,
+                                                    gboolean       show_ignored_files);
 
 G_END_DECLS
 


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