[gnome-text-editor] window: fix DnD when dropping onto window
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] window: fix DnD when dropping onto window
- Date: Tue, 26 Oct 2021 22:37:19 +0000 (UTC)
commit 775cda893901b3e60534cad88d47d8b0fcdc126f
Author: Christian Hergert <chergert redhat com>
Date: Tue Oct 26 15:37:12 2021 -0700
window: fix DnD when dropping onto window
We have to duplicate this here and in page because otherwise the text view
will swallow the URI list as a plain UTF-8 string.
So this handles the case of dropping on the header bar or anywhere when a
document is not displayed.
We happend to miss this during the GTK 4 port after DnD was redesigned in
GTK/GDK.
Related #198
src/editor-window-dnd.c | 63 ++++++++++++++++++-------------------------------
1 file changed, 23 insertions(+), 40 deletions(-)
---
diff --git a/src/editor-window-dnd.c b/src/editor-window-dnd.c
index 607f1b5..b390c38 100644
--- a/src/editor-window-dnd.c
+++ b/src/editor-window-dnd.c
@@ -25,59 +25,42 @@
#include "editor-session.h"
#include "editor-window-private.h"
-#if 0
-static void
-editor_window_dnd_drag_data_received_cb (EditorWindow *self,
- GdkDragContext *context,
- gint x,
- gint y,
- GtkSelectionData *data,
- guint info,
- guint time_,
- GtkWidget *widget)
+static gboolean
+editor_window_drop_target_drop (EditorWindow *self,
+ const GValue *value,
+ gdouble x,
+ gdouble y,
+ GtkDropTarget *dest)
{
- g_auto(GStrv) uris = NULL;
-
g_assert (EDITOR_IS_WINDOW (self));
- g_assert (GDK_IS_DRAG_CONTEXT (context));
- g_assert (GTK_IS_WIDGET (widget));
-
- if (!(uris = gtk_selection_data_get_uris (data)) || uris[0] == NULL)
- return;
+ g_assert (GTK_IS_DROP_TARGET (dest));
- for (guint i = 0; uris[i] != NULL; i++)
+ if (G_VALUE_HOLDS (value, GDK_TYPE_FILE_LIST))
{
- g_autoptr(GFile) file = g_file_new_for_uri (uris[i]);
+ EditorSession *session = editor_application_get_session (EDITOR_APPLICATION_DEFAULT);
+ GSList *list = g_value_get_boxed (value);
- if (file != NULL)
- editor_session_open (EDITOR_SESSION_DEFAULT, self, file, NULL);
+ for (const GSList *iter = list; iter; iter = iter->next)
+ {
+ GFile *file = iter->data;
+ g_assert (G_IS_FILE (file));
+ editor_session_open (session, self, file, NULL);
+ }
}
- gtk_window_present_with_time (GTK_WINDOW (self), time_);
+ return FALSE;
}
-#endif
void
_editor_window_dnd_init (EditorWindow *self)
{
-#if 0
- static const GtkTargetEntry target_entries[] = {
- { (gchar *)"text/uri-list", 0, 0 },
- };
-
- gtk_drag_dest_unset (GTK_WIDGET (self->notebook));
+ GtkDropTarget *dest;
- gtk_drag_dest_set (GTK_WIDGET (self->paned),
- GTK_DEST_DEFAULT_ALL,
- target_entries,
- G_N_ELEMENTS (target_entries),
- GDK_ACTION_COPY);
-
- g_signal_connect_object (self->paned,
- "drag-data-received",
- G_CALLBACK (editor_window_dnd_drag_data_received_cb),
+ dest = gtk_drop_target_new (GDK_TYPE_FILE_LIST, GDK_ACTION_COPY);
+ g_signal_connect_object (dest,
+ "drop",
+ G_CALLBACK (editor_window_drop_target_drop),
self,
G_CONNECT_SWAPPED);
-
-#endif
+ gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (dest));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]