[gnome-builder] editor: add "Reveal in Project Tree" action
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: add "Reveal in Project Tree" action
- Date: Fri, 24 Apr 2015 01:08:47 +0000 (UTC)
commit 16451fbe909cffce0d09719b05b50917eb05c85a
Author: Christian Hergert <christian hergert me>
Date: Thu Apr 23 18:08:39 2015 -0700
editor: add "Reveal in Project Tree" action
This action will select the current file in the project tree, expanding
tree nodes as necessary.
src/editor/gb-editor-frame.c | 35 +++++++++++++++++++++++++++++
src/editor/gb-editor-view-actions.c | 23 +++++++++++++++++++
src/editor/gb-editor-workspace.c | 42 +++++++++++++++++++++++++++++++++++
src/editor/gb-editor-workspace.h | 2 +
4 files changed, 102 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index 89cee7a..6c847fc 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -493,6 +493,35 @@ gb_editor_frame_set_show_map (GbEditorFrame *self,
}
static void
+gb_editor_frame__source_view_populate_popup (GbEditorFrame *self,
+ GtkWidget *popup,
+ IdeSourceView *source_view)
+{
+ g_assert (GB_IS_EDITOR_FRAME (self));
+ g_assert (GTK_IS_WIDGET (popup));
+ g_assert (IDE_IS_SOURCE_VIEW (source_view));
+
+ if (GTK_IS_MENU_SHELL (popup))
+ {
+ GtkWidget *item;
+ GtkWidget *sep;
+
+ sep = g_object_new (GTK_TYPE_SEPARATOR_MENU_ITEM,
+ "visible", TRUE,
+ NULL);
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup), sep);
+
+ item = g_object_new (GTK_TYPE_MENU_ITEM,
+ "action-name", "view.reveal",
+ "label", _("Re_veal in Project Tree"),
+ "use-underline", TRUE,
+ "visible", TRUE,
+ NULL);
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup), item);
+ }
+}
+
+static void
gb_editor_frame_constructed (GObject *object)
{
GbEditorFrame *self = (GbEditorFrame *)object;
@@ -518,6 +547,12 @@ gb_editor_frame_constructed (GObject *object)
G_CONNECT_SWAPPED);
g_signal_connect_object (self->source_view,
+ "populate-popup",
+ G_CALLBACK (gb_editor_frame__source_view_populate_popup),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (self->source_view,
"request-documentation",
G_CALLBACK (gb_editor_frame__source_view_request_documentation),
self,
diff --git a/src/editor/gb-editor-view-actions.c b/src/editor/gb-editor-view-actions.c
index 404a918..d935d76 100644
--- a/src/editor/gb-editor-view-actions.c
+++ b/src/editor/gb-editor-view-actions.c
@@ -25,6 +25,7 @@
#include "gb-editor-frame-private.h"
#include "gb-editor-view-actions.h"
#include "gb-editor-view-private.h"
+#include "gb-editor-workspace.h"
#include "gb-html-document.h"
#include "gb-view-grid.h"
#include "gb-widget.h"
@@ -668,6 +669,27 @@ gb_editor_view_actions_show_symbols (GSimpleAction *action,
g_signal_emit_by_name (self->symbols_button, "activate");
}
+static void
+gb_editor_view_actions_reveal (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ GbEditorView *self = user_data;
+ GbWorkbench *workbench;
+ GbEditorWorkspace *workspace;
+ IdeFile *file;
+ GFile *gfile;
+
+ g_assert (G_IS_SIMPLE_ACTION (action));
+ g_assert (GB_IS_EDITOR_VIEW (self));
+
+ 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);
+}
+
static GActionEntry GbEditorViewActions[] = {
{ "auto-indent", NULL, NULL, "false", gb_editor_view_actions_auto_indent },
{ "close", gb_editor_view_actions_close },
@@ -676,6 +698,7 @@ static GActionEntry GbEditorViewActions[] = {
{ "language", NULL, "s", "''", gb_editor_view_actions_language },
{ "preview", gb_editor_view_actions_preview },
{ "reload-buffer", gb_editor_view_actions_reload_buffer },
+ { "reveal", gb_editor_view_actions_reveal },
{ "save", gb_editor_view_actions_save },
{ "save-as", gb_editor_view_actions_save_as },
{ "show-line-numbers", NULL, NULL, "false", gb_editor_view_actions_show_line_numbers },
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 7870570..605586e 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -419,3 +419,45 @@ gb_editor_workspace_search_help (GbEditorWorkspace *self,
g_clear_object (&document);
}
+
+static gboolean
+gb_editor_workspace_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_editor_workspace_reveal_file (GbEditorWorkspace *self,
+ GFile *file)
+{
+ GbTreeNode *node;
+
+ g_return_if_fail (GB_IS_EDITOR_WORKSPACE (self));
+ g_return_if_fail (G_IS_FILE (file));
+
+ node = gb_tree_find_custom (GB_TREE (self->project_tree),
+ gb_editor_workspace_reveal_file_cb,
+ file);
+
+ if (node != NULL)
+ {
+ gb_tree_expand_to_node (GB_TREE (self->project_tree), node);
+ gb_tree_node_select (node);
+ }
+}
diff --git a/src/editor/gb-editor-workspace.h b/src/editor/gb-editor-workspace.h
index fb7ed0d..6b7ead5 100644
--- a/src/editor/gb-editor-workspace.h
+++ b/src/editor/gb-editor-workspace.h
@@ -31,6 +31,8 @@ void gb_editor_workspace_search_help (GbEditorWorkspace *self,
const gchar *keyword);
void gb_editor_workspace_show_help (GbEditorWorkspace *self,
const gchar *uri);
+void gb_editor_workspace_reveal_file (GbEditorWorkspace *self,
+ GFile *file);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]