[nautilus] files-view: Indicate when Ctrl+V cannot be executed



commit ebd6a475737d112083993b090b5223151e3b634e
Author: George Mocanu <mocanu geo98 gmail com>
Date:   Sun Jan 13 15:17:24 2019 +0200

    files-view: Indicate when Ctrl+V cannot be executed
    
    Currently, the Paste action is disabled in Read-Only
    directories (both the Ctrl+V accelerator and the "Paste"
    option from Context Menu), but the user isn't informed
    that the operation cannot be executed if he uses Ctrl+V.
    
    A pop-over should inform the user that the Paste action
    couldn't be completed if Ctrl+V accelerator was used.
    
    This patch solves this by adding a new action and mapping
    the Ctrl+V accelerator to that.
    
    Closes https://gitlab.gnome.org/GNOME/nautilus/issues/824

 src/nautilus-files-view.c | 47 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 41 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 591d87b52..0dad2fe96 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -2660,6 +2660,23 @@ paste_clipboard_text_received_callback (GtkClipboard     *clipboard,
     g_object_unref (view);
 }
 
+static void
+paste_files (NautilusFilesView *view)
+{
+    GtkClipboard *clipboard;
+
+    clipboard = nautilus_clipboard_get (GTK_WIDGET (view));
+
+    /* Performing an async request of clipboard contents, corresponding unref
+     * is in the callback.
+     */
+    g_object_ref (view);
+
+    gtk_clipboard_request_text (clipboard,
+                                paste_clipboard_text_received_callback,
+                                view);
+}
+
 static void
 action_paste_files (GSimpleAction *action,
                     GVariant      *state,
@@ -2667,14 +2684,31 @@ action_paste_files (GSimpleAction *action,
 {
     NautilusFilesView *view;
 
-    g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+    view = NAUTILUS_FILES_VIEW (user_data);
+
+    paste_files (view);
+}
+
+static void
+action_paste_files_accel (GSimpleAction *action,
+                          GVariant      *state,
+                          gpointer       user_data)
+{
+    NautilusFilesView *view;
 
     view = NAUTILUS_FILES_VIEW (user_data);
 
-    g_object_ref (view);
-    gtk_clipboard_request_text (nautilus_clipboard_get (GTK_WIDGET (view)),
-                                paste_clipboard_text_received_callback,
-                                view);
+    if (nautilus_files_view_is_read_only (view))
+    {
+        show_dialog (_("Could not paste files"),
+                     _("Permissions do not allow pasting files in this directory"),
+                     nautilus_files_view_get_containing_window (view),
+                     GTK_MESSAGE_ERROR);
+    }
+    else
+    {
+        paste_files (view);
+    }
 }
 
 static void
@@ -6907,6 +6941,7 @@ const GActionEntry view_entries[] =
     { "new-folder", action_new_folder },
     { "select-all", action_select_all },
     { "paste", action_paste_files },
+    { "paste_accel", action_paste_files_accel },
     { "create-link", action_create_links },
     { "new-document" },
     /* Selection menu */
@@ -9687,7 +9722,7 @@ nautilus_files_view_init (NautilusFilesView *view)
     nautilus_application_set_accelerator (app, "view.show-hidden-files", "<control>h");
     /* Background menu */
     nautilus_application_set_accelerator (app, "view.select-all", "<control>a");
-    nautilus_application_set_accelerator (app, "view.paste", "<control>v");
+    nautilus_application_set_accelerator (app, "view.paste_accel", "<control>v");
     nautilus_application_set_accelerator (app, "view.create-link", "<control>m");
     /* Selection menu */
     nautilus_application_set_accelerators (app, "view.open-with-default-application", open_accels);


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