[nautilus] files-view: Add menu item to copy current path
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] files-view: Add menu item to copy current path
- Date: Sat, 9 Apr 2022 19:08:36 +0000 (UTC)
commit 5bb70b7a422a41725d894df3f4035e39d6905f0c
Author: utkarshvg2401 <utkarshvg2401 gmail com>
Date: Fri Apr 1 10:48:08 2022 +0530
files-view: Add menu item to copy current path
Currently, there is no option to directly copy the path of the current open directory.
This can be useful when users want to use the path of the directory in the terminal or some code.
Close https://gitlab.gnome.org/GNOME/nautilus/-/issues/1966
src/nautilus-files-view.c | 29 ++++++++++++++++++++++
.../ui/nautilus-files-view-context-menus.ui | 4 +++
2 files changed, 33 insertions(+)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 2223d0bdf..1d491c2e4 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -6008,6 +6008,30 @@ action_cut (GSimpleAction *action,
nautilus_file_list_free (selection);
}
+static void
+action_copy_current_location (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusFilesView *view;
+ GdkClipboard *clipboard;
+ GList *files;
+ NautilusFilesViewPrivate *priv;
+
+ view = NAUTILUS_FILES_VIEW (user_data);
+ priv = nautilus_files_view_get_instance_private (view);
+
+ if (priv->directory_as_file != NULL)
+ {
+ files = g_list_append (NULL, nautilus_file_ref (priv->directory_as_file));
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view));
+ nautilus_clipboard_prepare_for_files (clipboard, files, FALSE);
+
+ nautilus_file_list_free (files);
+ }
+}
+
static void
action_create_links_in_place (GSimpleAction *action,
GVariant *state,
@@ -7015,6 +7039,7 @@ const GActionEntry view_entries[] =
{ "new-folder", action_new_folder },
{ "select-all", action_select_all },
{ "paste", action_paste_files },
+ { "copy-current-location", action_copy_current_location },
{ "paste_accel", action_paste_files_accel },
{ "create-link", action_create_links },
{ "new-document" },
@@ -7630,6 +7655,10 @@ real_update_actions_state (NautilusFilesView *view)
action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
"preview-selection");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count != 0);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "copy-current-location");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ !selection_contains_search);
/* Drive menu */
show_mount = (selection != NULL);
diff --git a/src/resources/ui/nautilus-files-view-context-menus.ui
b/src/resources/ui/nautilus-files-view-context-menus.ui
index b15970366..40a066aba 100644
--- a/src/resources/ui/nautilus-files-view-context-menus.ui
+++ b/src/resources/ui/nautilus-files-view-context-menus.ui
@@ -20,6 +20,10 @@
<attribute name="label" translatable="yes">_Open With Other Application</attribute>
<attribute name="action">view.open-current-directory-with-other-application</attribute>
</item>
+ <item>
+ <attribute name="label" translatable="yes">_Copy Location</attribute>
+ <attribute name="action">view.copy-current-location</attribute>
+ </item>
</section>
<section>
<item>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]