[nautilus/wip/corey/rework-clipboard: 3/4] files-view: Allow pasting from G_TYPE_FILE




commit 6ec2e30bef1b8cc2e0659c44e34c27b99d695b9a
Author: Corey Berla <corey berla me>
Date:   Tue Sep 20 15:15:47 2022 -0700

    files-view: Allow pasting from G_TYPE_FILE
    
    Copying / pasting within Nautilus is always handled by NAUTILUS_CLIPBOARD
    (GDK_TYPE_FILE_LIST), but sometimes, copying outside of Nautilus
    may pass a G_TYPE_FILE.  Now that the clipboard handling has been
    simplified we can accept these other types.
    
    Issue 540 is actually an issue related to G_TYPE_FILE, not the image
    itself.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/540

 src/nautilus-files-view.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 7b815f0a5..c78523f3a 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -2751,6 +2751,16 @@ paste_value_received_callback (GObject      *source_object,
         }
         handle_clipboard_data (data->view, clip, data->dest_uri, data->action);
     }
+    else if (G_VALUE_HOLDS (value, G_TYPE_FILE))
+    {
+        g_autofree char *view_uri = NULL;
+        GFile *location = g_value_get_object (value);
+        GList *item_uris = g_list_append (NULL, g_file_get_uri (location));
+
+        nautilus_files_view_move_copy_items (data->view, item_uris, data->dest_uri, GDK_ACTION_COPY);
+
+        g_list_free_full (item_uris, g_free);
+    }
 
     paste_callback_data_free (data);
 }
@@ -2781,6 +2791,10 @@ paste_files (NautilusFilesView *view,
     {
         gdk_clipboard_read_value_async (clipboard, NAUTILUS_TYPE_CLIPBOARD, 0, priv->clipboard_cancellable, 
paste_value_received_callback, data);
     }
+    else if (gdk_content_formats_contain_gtype (formats, G_TYPE_FILE))
+    {
+        gdk_clipboard_read_value_async (clipboard, G_TYPE_FILE, 0, priv->clipboard_cancellable, 
paste_value_received_callback, data);
+    }
 }
 
 static void
@@ -7196,7 +7210,8 @@ update_actions_state_for_clipboard_targets (NautilusFilesView *view)
     priv = nautilus_files_view_get_instance_private (view);
     clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view));
     formats = gdk_clipboard_get_formats (clipboard);
-    is_data_copied = gdk_content_formats_contain_gtype (formats, NAUTILUS_TYPE_CLIPBOARD);
+    is_data_copied = gdk_content_formats_contain_gtype (formats, NAUTILUS_TYPE_CLIPBOARD) ||
+                     gdk_content_formats_contain_gtype (formats, G_TYPE_FILE);
 
     action = g_action_map_lookup_action (G_ACTION_MAP (priv->view_action_group),
                                          "paste");


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