[gnome-builder/wip/plugins] editor: bring back "Reveal in Project Tree"



commit 814b0190195862b3b41aab61f9223cb01ab2c3f0
Author: Christian Hergert <christian hergert me>
Date:   Thu Jun 11 12:59:53 2015 -0700

    editor: bring back "Reveal in Project Tree"
    
    Disabled this during the plugins extraction work, can bring it back now
    and move the helper to GbWorkbench.
    
    Long term, I'd like to figure out a clean way to move the project tree to
    plugins, which will complicate this a bit. However, once we have a
    GbEditorViewAddin (or whatever better naming we come up with), the
    project-tree could provide this feature itself.

 src/editor/gb-editor-view-actions.c |    6 +----
 src/workbench/gb-workbench.c        |   43 +++++++++++++++++++++++++++++++++++
 src/workbench/gb-workbench.h        |    2 +
 3 files changed, 46 insertions(+), 5 deletions(-)
---
diff --git a/src/editor/gb-editor-view-actions.c b/src/editor/gb-editor-view-actions.c
index 2f84841..338057e 100644
--- a/src/editor/gb-editor-view-actions.c
+++ b/src/editor/gb-editor-view-actions.c
@@ -673,10 +673,8 @@ gb_editor_view_actions_reveal (GSimpleAction *action,
                                GVariant      *param,
                                gpointer       user_data)
 {
-#if 0
   GbEditorView *self = user_data;
   GbWorkbench *workbench;
-  GbEditorWorkspace *workspace;
   IdeFile *file;
   GFile *gfile;
 
@@ -686,9 +684,7 @@ gb_editor_view_actions_reveal (GSimpleAction *action,
   file = ide_buffer_get_file (IDE_BUFFER (self->document));
   gfile = ide_file_get_file (file);
   workbench = gb_widget_get_workbench (GTK_WIDGET (self));
-  workspace = gb_workbench_get_workspace_typed (workbench, GB_TYPE_EDITOR_WORKSPACE);
-  gb_editor_workspace_reveal_file (workspace, gfile);
-#endif
+  gb_workbench_reveal_file (workbench, gfile);
 }
 
 static GActionEntry GbEditorViewActions[] = {
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 08de9a3..166a79e 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -902,3 +902,46 @@ gb_workbench_get_view_grid (GbWorkbench *self)
 
   return GTK_WIDGET (self->view_grid);
 }
+
+static gboolean
+gb_workbench_reveal_file_cb (gconstpointer a,
+                             gconstpointer b)
+{
+  GFile *file = (GFile *)a;
+  GObject *object = (GObject *)b;
+
+  g_assert (G_IS_FILE (file));
+  g_assert (G_IS_OBJECT (object));
+
+  if (IDE_IS_PROJECT_FILE (object))
+    {
+      IdeProjectFile *pf = (IdeProjectFile *)object;
+      GFile *pf_file;
+
+      pf_file = ide_project_file_get_file (pf);
+      return g_file_equal (pf_file, file);
+    }
+
+  return FALSE;
+}
+
+void
+gb_workbench_reveal_file (GbWorkbench *self,
+                          GFile       *file)
+{
+  GbTreeNode *node;
+
+  g_return_if_fail (GB_IS_WORKBENCH (self));
+  g_return_if_fail (G_IS_FILE (file));
+
+  node = gb_tree_find_custom (GB_TREE (self->project_tree),
+                              gb_workbench_reveal_file_cb,
+                              file);
+
+  if (node != NULL)
+    {
+      gb_tree_expand_to_node (GB_TREE (self->project_tree), node);
+      gb_tree_scroll_to_node (GB_TREE (self->project_tree), node);
+      gb_tree_node_select (node);
+    }
+}
diff --git a/src/workbench/gb-workbench.h b/src/workbench/gb-workbench.h
index e4f84d4..67ebb77 100644
--- a/src/workbench/gb-workbench.h
+++ b/src/workbench/gb-workbench.h
@@ -50,6 +50,8 @@ void              gb_workbench_views_foreach        (GbWorkbench         *self,
                                                      gpointer             callback_data);
 GtkWidget        *gb_workbench_get_workspace        (GbWorkbench         *self);
 GtkWidget        *gb_workbench_get_view_grid        (GbWorkbench         *self);
+void              gb_workbench_reveal_file          (GbWorkbench         *self,
+                                                     GFile               *file);
 
 G_END_DECLS
 


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