[gnome-builder] ls: add directory actions to editors



commit 3198bfb4dc61e4f1f326e632786323c033b507b9
Author: Christian Hergert <chergert redhat com>
Date:   Fri Apr 26 16:36:48 2019 -0700

    ls: add directory actions to editors

 src/libide/sourceview/gtk/menus.ui        |   3 +
 src/plugins/ls/gbp-ls-editor-page-addin.c | 126 ++++++++++++++++++++++++++++++
 src/plugins/ls/gbp-ls-editor-page-addin.h |  31 ++++++++
 src/plugins/ls/gtk/menus.ui               |  14 ++++
 src/plugins/ls/ls-plugin.c                |   5 ++
 src/plugins/ls/meson.build                |   1 +
 6 files changed, 180 insertions(+)
---
diff --git a/src/libide/sourceview/gtk/menus.ui b/src/libide/sourceview/gtk/menus.ui
index dc5b0ea6f..d93dcffa1 100644
--- a/src/libide/sourceview/gtk/menus.ui
+++ b/src/libide/sourceview/gtk/menus.ui
@@ -3,14 +3,17 @@
   <menu id="ide-source-view-popup-menu">
     <section id="ide-source-view-popup-menu-jump-section">
       <item>
+        <attribute name="id">source-view-goto-def</attribute>
         <attribute name="label" translatable="yes">_Go to Definition</attribute>
         <attribute name="action">sourceview.goto-definition</attribute>
       </item>
       <item>
+        <attribute name="id">source-view-find-references</attribute>
         <attribute name="label" translatable="yes">_Find references</attribute>
         <attribute name="action">sourceview.find-references</attribute>
       </item>
     </section>
+    <section id="ide-source-view-popup-menu-files-section"/>
     <section id="ide-source-view-popup-menu-undo-section">
       <item>
         <attribute name="label" translatable="yes">_Undo</attribute>
diff --git a/src/plugins/ls/gbp-ls-editor-page-addin.c b/src/plugins/ls/gbp-ls-editor-page-addin.c
new file mode 100644
index 000000000..60cb4d4f3
--- /dev/null
+++ b/src/plugins/ls/gbp-ls-editor-page-addin.c
@@ -0,0 +1,126 @@
+/* gbp-ls-editor-page-addin.c
+ *
+ * Copyright 2019 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-ls-editor-page-addin"
+
+#include "config.h"
+
+#include <dazzle.h>
+#include <libide-editor.h>
+
+#include "gbp-ls-editor-page-addin.h"
+#include "gbp-ls-page.h"
+
+struct _GbpLsEditorPageAddin
+{
+  GObject parent_instance;
+};
+
+static void
+open_directory_cb (GSimpleAction *action,
+                   GVariant      *param,
+                   gpointer       user_data)
+{
+  IdeEditorPage *editor = user_data;
+  g_autoptr(GFile) directory = NULL;
+  GtkWidget *stack;
+  GbpLsPage *page;
+  GFile *file;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_EDITOR_PAGE (editor));
+
+  file = ide_editor_page_get_file (editor);
+  directory = g_file_get_parent (file);
+
+  stack = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_STACK);
+  page = g_object_new (GBP_TYPE_LS_PAGE,
+                       "close-on-activate", TRUE,
+                       "visible", TRUE,
+                       NULL);
+  gtk_container_add (GTK_CONTAINER (stack), GTK_WIDGET (page));
+  gbp_ls_page_set_directory (page, directory);
+}
+
+static void
+open_in_files_cb (GSimpleAction *action,
+                  GVariant      *param,
+                  gpointer       user_data)
+{
+  IdeEditorPage *editor = user_data;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_EDITOR_PAGE (editor));
+
+  dzl_file_manager_show (ide_editor_page_get_file (editor), NULL);
+}
+
+static void
+gbp_ls_editor_page_addin_load (IdeEditorPageAddin *addin,
+                               IdeEditorPage      *page)
+{
+  g_autoptr(GSimpleActionGroup) group = NULL;
+  static const GActionEntry actions[] = {
+    { "open-directory", open_directory_cb },
+    { "open-in-files", open_in_files_cb },
+  };
+
+  g_assert (IDE_IS_EDITOR_PAGE_ADDIN (addin));
+  g_assert (IDE_IS_EDITOR_PAGE (page));
+
+  group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (group),
+                                   actions,
+                                   G_N_ELEMENTS (actions),
+                                   page);
+
+  gtk_widget_insert_action_group (GTK_WIDGET (page), "ls", G_ACTION_GROUP (group));
+}
+
+static void
+gbp_ls_editor_page_addin_unload (IdeEditorPageAddin *addin,
+                                 IdeEditorPage      *page)
+{
+  g_assert (IDE_IS_EDITOR_PAGE_ADDIN (addin));
+  g_assert (IDE_IS_EDITOR_PAGE (page));
+
+  gtk_widget_insert_action_group (GTK_WIDGET (page), "ls", NULL);
+}
+
+static void
+editor_page_addin_iface_init (IdeEditorPageAddinInterface *iface)
+{
+  iface->load = gbp_ls_editor_page_addin_load;
+  iface->unload = gbp_ls_editor_page_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpLsEditorPageAddin, gbp_ls_editor_page_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_PAGE_ADDIN,
+                                                editor_page_addin_iface_init))
+
+static void
+gbp_ls_editor_page_addin_class_init (GbpLsEditorPageAddinClass *klass)
+{
+}
+
+static void
+gbp_ls_editor_page_addin_init (GbpLsEditorPageAddin *self)
+{
+}
diff --git a/src/plugins/ls/gbp-ls-editor-page-addin.h b/src/plugins/ls/gbp-ls-editor-page-addin.h
new file mode 100644
index 000000000..683709271
--- /dev/null
+++ b/src/plugins/ls/gbp-ls-editor-page-addin.h
@@ -0,0 +1,31 @@
+/* gbp-ls-editor-page-addin.h
+ *
+ * Copyright 2019 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_LS_EDITOR_PAGE_ADDIN (gbp_ls_editor_page_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpLsEditorPageAddin, gbp_ls_editor_page_addin, GBP, LS_EDITOR_PAGE_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/ls/gtk/menus.ui b/src/plugins/ls/gtk/menus.ui
index 276c17b99..9045588ca 100644
--- a/src/plugins/ls/gtk/menus.ui
+++ b/src/plugins/ls/gtk/menus.ui
@@ -14,4 +14,18 @@
       </submenu>
     </section>
   </menu>
+  <menu id="ide-source-view-popup-menu">
+    <section id="ide-source-view-popup-menu-files-section">
+      <item>
+        <attribute name="id">source-view-open-directory</attribute>
+        <attribute name="label" translatable="yes">Switch to Folder</attribute>
+        <attribute name="action">ls.open-directory</attribute>
+      </item>
+      <item>
+        <attribute name="id">source-view-open-in-files</attribute>
+        <attribute name="label" translatable="yes">Open Containing Folder</attribute>
+        <attribute name="action">ls.open-in-files</attribute>
+      </item>
+    </section>
+  </menu>
 </interface>
diff --git a/src/plugins/ls/ls-plugin.c b/src/plugins/ls/ls-plugin.c
index c078b8906..1117ed0ba 100644
--- a/src/plugins/ls/ls-plugin.c
+++ b/src/plugins/ls/ls-plugin.c
@@ -21,13 +21,18 @@
 #include "config.h"
 
 #include <libpeas/peas.h>
+#include <libide-editor.h>
 #include <libide-gui.h>
 
+#include "gbp-ls-editor-page-addin.h"
 #include "gbp-ls-workbench-addin.h"
 
 _IDE_EXTERN void
 _gbp_ls_register_types (PeasObjectModule *module)
 {
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_EDITOR_PAGE_ADDIN,
+                                              GBP_TYPE_LS_EDITOR_PAGE_ADDIN);
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_WORKBENCH_ADDIN,
                                               GBP_TYPE_LS_WORKBENCH_ADDIN);
diff --git a/src/plugins/ls/meson.build b/src/plugins/ls/meson.build
index 27f4bb85e..b4afd4aa9 100644
--- a/src/plugins/ls/meson.build
+++ b/src/plugins/ls/meson.build
@@ -1,6 +1,7 @@
 plugins_sources += files([
   'gbp-ls-model.c',
   'gbp-ls-page.c',
+  'gbp-ls-editor-page-addin.c',
   'gbp-ls-workbench-addin.c',
   'ls-plugin.c',
 ])


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