[gtk/dnd-gestures-2: 57/66] filechooser: Convert to GtkDropTarget
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/dnd-gestures-2: 57/66] filechooser: Convert to GtkDropTarget
- Date: Sat, 4 Jan 2020 14:32:09 +0000 (UTC)
commit 6e22f57fe6111465efb10b3119f9e03b43483e89
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jan 2 08:46:30 2020 -0500
filechooser: Convert to GtkDropTarget
gtk/gtkfilechooserwidget.c | 64 ++++++++++++++++++++----------------------
gtk/ui/gtkfilechooserwidget.ui | 3 --
2 files changed, 30 insertions(+), 37 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index ef0b4a0d2f..eb3d19d038 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -1982,25 +1982,26 @@ out:
}
static void
-file_list_drag_data_received_cb (GtkWidget *widget,
- GdkDrop *drop,
- GtkSelectionData *selection_data,
- gpointer user_data)
+file_list_drag_data_received_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (user_data);
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
+ GtkDropTarget *dest = GTK_DROP_TARGET (source);
+ GtkWidget *widget = gtk_drop_target_get_target (dest);
+ GdkDrop *drop = gtk_drop_target_get_drop (dest);
+ GdkDrag *drag = gdk_drop_get_drag (drop);
gchar **uris;
char *uri;
GFile *file;
+ GtkSelectionData *selection_data;
- /* Allow only drags from other widgets; see bug #533891. */
- if (gdk_drop_get_drag (drop) &&
- gtk_drag_source_get_origin (gtk_drag_get_source (gdk_drop_get_drag (drop))) == widget)
- {
- g_signal_stop_emission_by_name (widget, "drag-data-received");
- return;
- }
+ selection_data = gtk_drop_target_read_selection_finish (dest, result, NULL);
+ /* Allow only drags from other widgets; see bug #533891. */
+ if (drag && gtk_drag_source_get_origin (gtk_drag_get_source (drag)) == widget)
+ return;
/* Parse the text/uri-list string, navigate to the first one */
uris = gtk_selection_data_get_uris (selection_data);
@@ -2025,19 +2026,19 @@ file_list_drag_data_received_cb (GtkWidget *widget,
file_list_drag_data_received_get_info_cb,
data);
}
-
- g_signal_stop_emission_by_name (widget, "drag-data-received");
}
/* Don't do anything with the drag_drop signal */
static gboolean
-file_list_drag_drop_cb (GtkWidget *widget,
- GdkDrop *drop,
- gint x,
- gint y,
+file_list_drag_drop_cb (GtkDropTarget *dest,
+ int x,
+ int y,
GtkFileChooserWidget *impl)
{
- g_signal_stop_emission_by_name (widget, "drag-drop");
+ const char *target = g_intern_static_string ("text/uri-list");
+
+ gtk_drop_target_read_selection (dest, target, NULL, file_list_drag_data_received_cb, impl);
+
return TRUE;
}
@@ -2054,13 +2055,12 @@ file_list_drag_begin_cb (GtkDragSource *source,
/* Disable the normal tree drag motion handler, it makes it look like you're
dropping the dragged item onto a tree item */
static gboolean
-file_list_drag_motion_cb (GtkWidget *widget,
- GdkDrop *drop,
- gint x,
- gint y,
+file_list_drag_motion_cb (GtkDropTarget *dest,
+ int x,
+ int y,
GtkFileChooserWidget *impl)
{
- g_signal_stop_emission_by_name (widget, "drag-motion");
+ g_signal_stop_emission_by_name (dest, "drag-motion");
return TRUE;
}
@@ -8463,14 +8463,9 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, box);
/* And a *lot* of callbacks to bind ... */
- gtk_widget_class_bind_template_callback (widget_class, file_list_drag_drop_cb);
- gtk_widget_class_bind_template_callback (widget_class, file_list_drag_data_received_cb);
gtk_widget_class_bind_template_callback (widget_class, list_popup_menu_cb);
gtk_widget_class_bind_template_callback (widget_class, file_list_query_tooltip_cb);
gtk_widget_class_bind_template_callback (widget_class, list_row_activated);
- gtk_widget_class_bind_template_callback (widget_class, file_list_drag_begin_cb);
- gtk_widget_class_bind_template_callback (widget_class, file_list_drag_motion_cb);
- gtk_widget_class_bind_template_callback (widget_class, file_list_drag_end_cb);
gtk_widget_class_bind_template_callback (widget_class, list_selection_changed);
gtk_widget_class_bind_template_callback (widget_class, list_cursor_changed);
gtk_widget_class_bind_template_callback (widget_class, browse_files_tree_view_keynav_failed_cb);
@@ -8506,6 +8501,7 @@ post_process_ui (GtkFileChooserWidget *impl)
GList *cells;
GFile *file;
GtkDragSource *source;
+ GtkDropTarget *dest;
GdkContentFormats *formats;
/* Setup file list treeview */
@@ -8519,15 +8515,15 @@ post_process_ui (GtkFileChooserWidget *impl)
GDK_BUTTON1_MASK,
formats,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
- gdk_content_formats_unref (formats);
g_signal_connect (source, "drag-begin", G_CALLBACK (file_list_drag_begin_cb), impl);
g_signal_connect (source, "drag-end", G_CALLBACK (file_list_drag_end_cb), impl);
- gtk_drag_dest_set (priv->browse_files_tree_view,
- GTK_DEST_DEFAULT_ALL,
- NULL,
- GDK_ACTION_COPY | GDK_ACTION_MOVE);
- gtk_drag_dest_add_uri_targets (priv->browse_files_tree_view);
+
+ dest = gtk_drop_target_new (GTK_DEST_DEFAULT_ALL, formats, GDK_ACTION_COPY | GDK_ACTION_MOVE);
+ g_signal_connect (dest, "drag-motion", G_CALLBACK (file_list_drag_motion_cb), impl);
+ g_signal_connect (dest, "drag-drop", G_CALLBACK (file_list_drag_drop_cb), impl);
+ gtk_drop_target_attach (dest, priv->browse_files_tree_view);
+ gdk_content_formats_unref (formats);
/* File browser treemodel columns are shared between GtkFileChooser implementations,
* so we don't set cell renderer attributes in GtkBuilder, but rather keep that
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index cf82bee991..a1ee4f8573 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -156,9 +156,6 @@
<signal name="key-pressed" handler="treeview_key_press_cb"
swapped="no"/>
</object>
</child>
- <signal name="drag-data-received"
handler="file_list_drag_data_received_cb" swapped="no"/>
- <signal name="drag-drop" handler="file_list_drag_drop_cb"
swapped="no"/>
- <signal name="drag-motion" handler="file_list_drag_motion_cb"
swapped="no"/>
<signal name="popup-menu" handler="list_popup_menu_cb"
swapped="no"/>
<signal name="query-tooltip"
handler="file_list_query_tooltip_cb" swapped="no"/>
<signal name="row-activated" handler="list_row_activated"
swapped="no"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]