[gnome-builder] project-tree: add Open With -> External Program
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] project-tree: add Open With -> External Program
- Date: Sat, 27 Jun 2020 21:07:48 +0000 (UTC)
commit 110421c4865f7e271358106734f84033886581e9
Author: Christian Hergert <chergert redhat com>
Date: Sat Jun 27 14:07:28 2020 -0700
project-tree: add Open With -> External Program
Fixes #1250
.../project-tree/gbp-project-tree-pane-actions.c | 42 ++++++++++++++++++++++
src/plugins/project-tree/gtk/menus.ui | 7 ++++
src/plugins/project-tree/meson.build | 1 +
3 files changed, 50 insertions(+)
---
diff --git a/src/plugins/project-tree/gbp-project-tree-pane-actions.c
b/src/plugins/project-tree/gbp-project-tree-pane-actions.c
index b111cfcbc..53fa73c6c 100644
--- a/src/plugins/project-tree/gbp-project-tree-pane-actions.c
+++ b/src/plugins/project-tree/gbp-project-tree-pane-actions.c
@@ -26,6 +26,10 @@
#include <libide-projects.h>
#include <vte/vte.h>
+#ifdef ENABLE_LIBPORTAL
+# include <libportal/portal-gtk3.h>
+#endif
+
#include "gbp-project-tree-private.h"
#include "gbp-rename-file-popover.h"
#include "gbp-new-file-popover.h"
@@ -463,6 +467,36 @@ DEFINE_ACTION_HANDLER (open_with_hint, {
NULL, NULL, NULL);
});
+#ifdef ENABLE_LIBPORTAL
+DEFINE_ACTION_HANDLER (open_with_external, {
+ IdeProjectFile *project_file;
+ g_autoptr(XdpPortal) portal = NULL;
+ g_autoptr(GFile) file = NULL;
+ g_autofree gchar *uri = NULL;
+ IdeTreeNode *selected;
+ XdpParent *parent;
+ GtkWidget *toplevel;
+
+ if (!(selected = ide_tree_get_selected_node (self->tree)) ||
+ !ide_tree_node_holds (selected, IDE_TYPE_PROJECT_FILE) ||
+ !(project_file = ide_tree_node_get_item (selected)))
+ return;
+
+ toplevel = gtk_widget_get_ancestor (GTK_WIDGET (self->tree), GTK_TYPE_WINDOW);
+ file = ide_project_file_ref_file (project_file);
+ uri = g_file_get_uri (file);
+
+ portal = xdp_portal_new ();
+ parent = xdp_parent_new_gtk (GTK_WINDOW (toplevel));
+ xdp_portal_open_uri (portal,
+ parent,
+ uri,
+ XDP_OPEN_URI_FLAG_ASK | XDP_OPEN_URI_FLAG_WRITABLE,
+ NULL, NULL, NULL);
+ xdp_parent_free (parent);
+});
+#endif
+
/* Based on gdesktopappinfo.c in GIO */
static gchar *
find_terminal_executable (void)
@@ -550,6 +584,9 @@ static const GActionEntry entries[] = {
{ "new-folder", gbp_project_tree_pane_actions_new_folder },
{ "open", gbp_project_tree_pane_actions_open },
{ "open-with-hint", gbp_project_tree_pane_actions_open_with_hint, "s" },
+#ifdef ENABLE_LIBPORTAL
+ { "open-with-external", gbp_project_tree_pane_actions_open_with_external },
+#endif
{ "open-containing-folder", gbp_project_tree_pane_actions_open_containing_folder },
{ "open-in-terminal", gbp_project_tree_pane_actions_open_in_terminal },
{ "rename", gbp_project_tree_pane_actions_rename },
@@ -626,6 +663,11 @@ _gbp_project_tree_pane_update_actions (GbpProjectTreePane *self)
dzl_gtk_widget_action_set (GTK_WIDGET (self->tree), "project-tree", "open-with-hint",
"enabled", is_file,
NULL);
+#ifdef ENABLE_LIBPORTAL
+ dzl_gtk_widget_action_set (GTK_WIDGET (self->tree), "project-tree", "open-with-external",
+ "enabled", is_file,
+ NULL);
+#endif
dzl_gtk_widget_action_set (GTK_WIDGET (self->tree), "project-tree", "open-containing-folder",
"enabled", is_file,
NULL);
diff --git a/src/plugins/project-tree/gtk/menus.ui b/src/plugins/project-tree/gtk/menus.ui
index 6342438cf..dc82aff28 100644
--- a/src/plugins/project-tree/gtk/menus.ui
+++ b/src/plugins/project-tree/gtk/menus.ui
@@ -24,6 +24,13 @@
</item>
<submenu id="project-tree-menu-open-with-menu">
<attribute name="label" translatable="yes">Open With…</attribute>
+ <section id="project-tree-menu-open-with-external">
+ <item>
+ <attribute name="id">project-tree-menu-open-external</attribute>
+ <attribute name="label" translatable="yes">_External Program…</attribute>
+ <attribute name="action">project-tree.open-with-external</attribute>
+ </item>
+ </section>
<section id="project-tree-menu-open-with-section">
<item>
<attribute name="id">project-tree-menu-open-editor</attribute>
diff --git a/src/plugins/project-tree/meson.build b/src/plugins/project-tree/meson.build
index 99f0e1f8c..3c0037a2f 100644
--- a/src/plugins/project-tree/meson.build
+++ b/src/plugins/project-tree/meson.build
@@ -15,4 +15,5 @@ plugin_project_tree_resources = gnome.compile_resources(
c_name: 'gbp_project_tree',
)
+plugins_deps += [libportal_dep]
plugins_sources += plugin_project_tree_resources
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]