[nautilus] files-view: Add menu item for "Open in Console"
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] files-view: Add menu item for "Open in Console"
- Date: Thu, 4 Aug 2022 22:31:06 +0000 (UTC)
commit 7c283f456c5c92c32824905462191a7f717b3e21
Author: Corey Berla <corey berla me>
Date: Sat Jul 30 16:49:57 2022 -0700
files-view: Add menu item for "Open in Console"
In preparation for removal of the menu item extension the Console app
we should add the menu item directly in Nautilus.
* Only show the menu item if GNOME Console is installed.
* Only show the menu item if a single directory is selected
or if we are working on the current directory.
src/nautilus-files-view.c | 58 ++++++++++++++++++++++
.../ui/nautilus-files-view-context-menus.ui | 14 ++++++
2 files changed, 72 insertions(+)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 52e9e6ac4..3d644da3f 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -55,6 +55,7 @@
#include "nautilus-batch-rename-utilities.h"
#include "nautilus-clipboard.h"
#include "nautilus-compress-dialog-controller.h"
+#include "nautilus-dbus-launcher.h"
#include "nautilus-directory.h"
#include "nautilus-dnd.h"
#include "nautilus-enums.h"
@@ -2510,6 +2511,50 @@ action_new_folder_with_selection (GSimpleAction *action,
nautilus_files_view_new_folder (NAUTILUS_FILES_VIEW (user_data), TRUE);
}
+static void
+real_open_console (NautilusFile *file,
+ NautilusFilesView *view)
+{
+ GtkRoot *window = gtk_widget_get_root (GTK_WIDGET (view));
+ GVariant *parameters;
+ g_autofree gchar *uri = NULL;
+
+ uri = nautilus_file_get_uri (file);
+ parameters = g_variant_new_parsed ("([%s], @a{sv} {})", uri);
+ nautilus_dbus_launcher_call (nautilus_dbus_launcher_get (),
+ NAUTILUS_DBUS_LAUNCHER_CONSOLE,
+ "Open",
+ parameters, GTK_WINDOW (window));
+}
+
+static void
+action_open_console (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ g_autolist (NautilusFile) selection = NULL;
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (user_data));
+ g_return_if_fail (selection != NULL && g_list_length (selection) == 1);
+
+ real_open_console (NAUTILUS_FILE (selection->data), NAUTILUS_FILES_VIEW (user_data));
+}
+
+static void
+action_current_dir_open_console (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusFilesView *view;
+ NautilusFilesViewPrivate *priv;
+
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (user_data));
+
+ view = NAUTILUS_FILES_VIEW (user_data);
+ priv = nautilus_files_view_get_instance_private (view);
+ real_open_console (priv->directory_as_file, view);
+}
+
static void
action_properties (GSimpleAction *action,
GVariant *state,
@@ -7083,6 +7128,8 @@ const GActionEntry view_entries[] =
{ "extract-to", action_extract_to },
{ "compress", action_compress },
{ "send-email", action_send_email },
+ { "console", action_open_console },
+ { "current-directory-console", action_current_dir_open_console },
{ "properties", action_properties},
{ "current-directory-properties", action_current_dir_properties},
{ "run-in-terminal", action_run_in_terminal },
@@ -7774,6 +7821,17 @@ real_update_actions_state (NautilusFilesView *view)
!selection_is_read_only && !selection_contains_recent &&
can_paste_files_into && !selection_contains_starred);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "console");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ selection_count == 1 && nautilus_file_is_directory (selection->data) &&
+ nautilus_dbus_launcher_is_available (nautilus_dbus_launcher_get (),
+ NAUTILUS_DBUS_LAUNCHER_CONSOLE));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "current-directory-console");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ nautilus_dbus_launcher_is_available (nautilus_dbus_launcher_get (),
+ NAUTILUS_DBUS_LAUNCHER_CONSOLE));
action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
"properties");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
diff --git a/src/resources/ui/nautilus-files-view-context-menus.ui
b/src/resources/ui/nautilus-files-view-context-menus.ui
index a88e5c5a0..9d90d9671 100644
--- a/src/resources/ui/nautilus-files-view-context-menus.ui
+++ b/src/resources/ui/nautilus-files-view-context-menus.ui
@@ -53,6 +53,13 @@
</item>
</section>
<section id="background-extensions-section"/>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Open in Consol_e</attribute>
+ <attribute name="action">view.current-directory-console</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </section>
<section>
<item>
<attribute name="label" translatable="yes">P_roperties</attribute>
@@ -258,6 +265,13 @@
<attribute name="hidden-when">action-disabled</attribute>
</item>
</section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Open in Consol_e</attribute>
+ <attribute name="action">view.console</attribute>
+ <attribute name="hidden-when">action-disabled</attribute>
+ </item>
+ </section>
<section>
<item>
<attribute name="label" translatable="yes">P_roperties</attribute>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]