[gnome-builder] project-tree: add "Reveal in Project" menu items
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] project-tree: add "Reveal in Project" menu items
- Date: Mon, 26 Oct 2020 21:25:40 +0000 (UTC)
commit 1fb541dbb29455d42e4df1c1010b5ff7a040d7f0
Author: Christian Hergert <chergert redhat com>
Date: Mon Oct 26 14:16:20 2020 -0700
project-tree: add "Reveal in Project" menu items
This allows jumping to the file or directory that is currently visualized
in an IdePage (if the page implementation supports it).
Fixes #1320
.../project-tree/gbp-project-tree-frame-addin.c | 130 +++++++++++++++++++++
.../project-tree/gbp-project-tree-frame-addin.h | 31 +++++
src/plugins/project-tree/gtk/menus.ui | 20 ++++
src/plugins/project-tree/meson.build | 1 +
src/plugins/project-tree/project-tree-plugin.c | 4 +
5 files changed, 186 insertions(+)
---
diff --git a/src/plugins/project-tree/gbp-project-tree-frame-addin.c
b/src/plugins/project-tree/gbp-project-tree-frame-addin.c
new file mode 100644
index 000000000..c45b3b9d7
--- /dev/null
+++ b/src/plugins/project-tree/gbp-project-tree-frame-addin.c
@@ -0,0 +1,130 @@
+/* gbp-project-tree-frame-addin.c
+ *
+ * Copyright 2020 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-project-tree-frame-addin"
+
+#include "config.h"
+
+#include <libide-gui.h>
+#include <libide-editor.h>
+
+#include "gbp-project-tree-frame-addin.h"
+#include "gbp-project-tree-workspace-addin.h"
+#include "gbp-project-tree.h"
+
+struct _GbpProjectTreeFrameAddin
+{
+ GObject parent_instance;
+ IdeFrame *frame;
+ IdePage *page;
+ GActionMap *actions;
+};
+
+static void
+gbp_project_tree_frame_addin_reveal (GSimpleAction *action,
+ GVariant *params,
+ gpointer user_data)
+{
+ GbpProjectTreeFrameAddin *self = user_data;
+ g_autoptr(GFile) file = NULL;
+ GtkWidget *workspace;
+ IdeWorkspaceAddin *addin;
+ GbpProjectTree *tree;
+
+ g_assert (GBP_IS_PROJECT_TREE_FRAME_ADDIN (self));
+
+ if (self->page == NULL ||
+ !(file = ide_page_get_file_or_directory (self->page)) ||
+ !(workspace = gtk_widget_get_ancestor (GTK_WIDGET (self->page), IDE_TYPE_WORKSPACE)) ||
+ !(addin = ide_workspace_addin_find_by_module_name (IDE_WORKSPACE (workspace), "project-tree")) ||
+ !GBP_IS_PROJECT_TREE_WORKSPACE_ADDIN (addin) ||
+ !(tree = gbp_project_tree_workspace_addin_get_tree (GBP_PROJECT_TREE_WORKSPACE_ADDIN (addin))))
+ return;
+
+ gbp_project_tree_reveal (tree, file);
+}
+
+static void
+gbp_project_tree_frame_addin_load (IdeFrameAddin *addin,
+ IdeFrame *frame)
+{
+ GbpProjectTreeFrameAddin *self = (GbpProjectTreeFrameAddin *)addin;
+ g_autoptr(GSimpleActionGroup) group = NULL;
+ static const GActionEntry actions[] = {
+ { "reveal", gbp_project_tree_frame_addin_reveal },
+ };
+
+ g_assert (GBP_IS_PROJECT_TREE_FRAME_ADDIN (self));
+ g_assert (IDE_IS_FRAME (frame));
+
+ group = g_simple_action_group_new ();
+
+ self->frame = frame;
+ self->actions = g_object_ref (G_ACTION_MAP (group));
+
+ g_action_map_add_action_entries (G_ACTION_MAP (group), actions, G_N_ELEMENTS (actions), self);
+ gtk_widget_insert_action_group (GTK_WIDGET (frame), "project-tree", G_ACTION_GROUP (group));
+}
+
+static void
+gbp_project_tree_frame_addin_unload (IdeFrameAddin *addin,
+ IdeFrame *frame)
+{
+ GbpProjectTreeFrameAddin *self = (GbpProjectTreeFrameAddin *)addin;
+
+ g_assert (GBP_IS_PROJECT_TREE_FRAME_ADDIN (self));
+ g_assert (IDE_IS_FRAME (frame));
+
+ self->page = NULL;
+ self->frame = NULL;
+ g_clear_object (&self->actions);
+ gtk_widget_insert_action_group (GTK_WIDGET (frame), "project-tree", NULL);
+}
+
+static void
+gbp_project_tree_frame_addin_set_page (IdeFrameAddin *addin,
+ IdePage *page)
+{
+ g_assert (GBP_IS_PROJECT_TREE_FRAME_ADDIN (addin));
+ g_assert (!page || IDE_IS_PAGE (page));
+
+ GBP_PROJECT_TREE_FRAME_ADDIN (addin)->page = page;
+}
+
+static void
+frame_addin_iface_init (IdeFrameAddinInterface *iface)
+{
+ iface->load = gbp_project_tree_frame_addin_load;
+ iface->unload = gbp_project_tree_frame_addin_unload;
+ iface->set_page = gbp_project_tree_frame_addin_set_page;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpProjectTreeFrameAddin, gbp_project_tree_frame_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_FRAME_ADDIN, frame_addin_iface_init))
+
+static void
+gbp_project_tree_frame_addin_class_init (GbpProjectTreeFrameAddinClass *klass)
+{
+}
+
+static void
+gbp_project_tree_frame_addin_init (GbpProjectTreeFrameAddin *self)
+{
+}
diff --git a/src/plugins/project-tree/gbp-project-tree-frame-addin.h
b/src/plugins/project-tree/gbp-project-tree-frame-addin.h
new file mode 100644
index 000000000..444c209ce
--- /dev/null
+++ b/src/plugins/project-tree/gbp-project-tree-frame-addin.h
@@ -0,0 +1,31 @@
+/* gbp-project-tree-frame-addin.h
+ *
+ * Copyright 2020 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_PROJECT_TREE_FRAME_ADDIN (gbp_project_tree_frame_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpProjectTreeFrameAddin, gbp_project_tree_frame_addin, GBP, PROJECT_TREE_FRAME_ADDIN,
GObject)
+
+G_END_DECLS
diff --git a/src/plugins/project-tree/gtk/menus.ui b/src/plugins/project-tree/gtk/menus.ui
index dc82aff28..45c504c8e 100644
--- a/src/plugins/project-tree/gtk/menus.ui
+++ b/src/plugins/project-tree/gtk/menus.ui
@@ -85,4 +85,24 @@
</submenu>
</section>
</menu>
+ <menu id="ide-editor-page-document-menu">
+ <section id="ide-frame-menu-reveal">
+ <attribute name="after">editor-document-preferences-section</attribute>
+ <attribute name="before">editor-document-save-section</attribute>
+ <item>
+ <attribute name="id">project-tree-reveal</attribute>
+ <attribute name="label" translatable="yes">Reveal in Project</attribute>
+ <attribute name="action">project-tree.reveal</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </section>
+ </menu>
+ <menu id="ide-source-view-popup-menu">
+ <section id="ide-source-view-popup-menu-files-section">
+ <item>
+ <attribute name="label" translatable="yes">Reveal in Project</attribute>
+ <attribute name="action">project-tree.reveal</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
diff --git a/src/plugins/project-tree/meson.build b/src/plugins/project-tree/meson.build
index 3c0037a2f..2c4095230 100644
--- a/src/plugins/project-tree/meson.build
+++ b/src/plugins/project-tree/meson.build
@@ -2,6 +2,7 @@ plugins_sources += files([
'project-tree-plugin.c',
'gbp-project-tree.c',
'gbp-project-tree-addin.c',
+ 'gbp-project-tree-frame-addin.c',
'gbp-project-tree-pane.c',
'gbp-project-tree-pane-actions.c',
'gbp-project-tree-workspace-addin.c',
diff --git a/src/plugins/project-tree/project-tree-plugin.c b/src/plugins/project-tree/project-tree-plugin.c
index 1221ebadd..fec200437 100644
--- a/src/plugins/project-tree/project-tree-plugin.c
+++ b/src/plugins/project-tree/project-tree-plugin.c
@@ -27,6 +27,7 @@
#include <libpeas/peas.h>
#include "gbp-project-tree-addin.h"
+#include "gbp-project-tree-frame-addin.h"
#include "gbp-project-tree-workspace-addin.h"
void
@@ -35,6 +36,9 @@ _gbp_project_tree_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_TREE_ADDIN,
GBP_TYPE_PROJECT_TREE_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_FRAME_ADDIN,
+ GBP_TYPE_PROJECT_TREE_FRAME_ADDIN);
peas_object_module_register_extension_type (module,
IDE_TYPE_WORKSPACE_ADDIN,
GBP_TYPE_PROJECT_TREE_WORKSPACE_ADDIN);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]