[nautilus/wip/antoniof/drag-source-changes: 2/3] files-view: Add Drag Source
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/drag-source-changes: 2/3] files-view: Add Drag Source
- Date: Sat, 4 Jun 2022 18:04:48 +0000 (UTC)
commit f32f718b1d1450754f21d13934c462857e6347b1
Author: Corey Berla <corey berla me>
Date: Tue May 17 12:52:31 2022 -0700
files-view: Add Drag Source
Create DragSource and connect to signals. Use existing functions
to get the selection and convert to a file list. Pick the first
icon for a drag icon.
src/nautilus-files-view.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 109d991c2..2b4ff4dfd 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -4198,6 +4198,47 @@ on_end_file_changes (NautilusFilesView *view)
}
}
+static GdkContentProvider *
+on_drag_prepare (GtkDragSource *source,
+ double x,
+ double y,
+ NautilusFilesView *self)
+{
+ g_autolist (NautilusFile) selection = NULL;
+ g_autoslist (GFile) file_list = NULL;
+ g_autoptr (GdkPaintable) paintable = NULL;
+ g_autoptr (GtkSnapshot) snapshot = NULL;
+ GdkDragAction actions;
+
+ selection = nautilus_files_view_get_selection (NAUTILUS_VIEW (self));
+ if (selection != NULL)
+ {
+ file_list = convert_file_list_to_gdk_file_list (selection);
+ actions = GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK | GDK_ACTION_MOVE;
+ gtk_drag_source_set_actions (source, actions);
+ paintable = nautilus_file_get_icon_paintable (selection->data, NAUTILUS_GRID_ICON_SIZE_LARGE, 1, 0);
+ for (GList *cur_file = selection->next; cur_file != NULL; cur_file = cur_file->next)
+ {
+ g_autoptr (GdkPaintable) paintable2 = NULL;
+ paintable2 = nautilus_file_get_icon_paintable (cur_file->data, NAUTILUS_GRID_ICON_SIZE_LARGE, 1,
0);
+ if (paintable2 != paintable || cur_file->next == NULL)
+ {
+ snapshot = gtk_snapshot_new ();
+ gdk_paintable_snapshot (paintable, snapshot, NAUTILUS_GRID_ICON_SIZE_LARGE,
NAUTILUS_GRID_ICON_SIZE_LARGE);
+ gdk_paintable_snapshot (paintable2, snapshot, NAUTILUS_GRID_ICON_SIZE_LARGE * 0.5,
NAUTILUS_GRID_ICON_SIZE_LARGE * 0.5);
+ g_object_unref (paintable);
+ paintable = gtk_snapshot_to_paintable (snapshot, NULL);
+ break;
+ }
+ }
+
+ gtk_drag_source_set_icon (source, paintable, 0, 0);
+ return gdk_content_provider_new_typed (GDK_TYPE_FILE_LIST, file_list);
+ }
+
+ return NULL;
+}
+
static int
compare_pointers (gconstpointer pointer_1,
gconstpointer pointer_2)
@@ -9348,6 +9389,7 @@ nautilus_files_view_init (NautilusFilesView *view)
#endif
NautilusDirectory *scripts_directory;
NautilusDirectory *templates_directory;
+ GtkDragSource *drag_source;
GtkEventController *controller;
gchar *templates_uri;
GdkClipboard *clipboard;
@@ -9552,6 +9594,10 @@ nautilus_files_view_init (NautilusFilesView *view)
priv->in_destruction = FALSE;
+ drag_source = gtk_drag_source_new ();
+ g_signal_connect (drag_source, "prepare", G_CALLBACK (on_drag_prepare), view);
+ gtk_widget_add_controller (GTK_WIDGET (view), GTK_EVENT_CONTROLLER (drag_source));
+
#if 0 && NAUTILUS_A11Y_NEEDS_GTK4_REIMPLEMENTATION
/* Accessibility */
atk_object = gtk_widget_get_accessible (GTK_WIDGET (view));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]