[nautilus] Revert "pathbar: Remove dnd handling"
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Revert "pathbar: Remove dnd handling"
- Date: Thu, 17 Aug 2017 13:57:11 +0000 (UTC)
commit 715a28cd3e318e553727a8cc00dd5f0c0326659e
Author: António Fernandes <AntonioJPFernandes gmail com>
Date: Thu Aug 17 11:02:15 2017 +0100
Revert "pathbar: Remove dnd handling"
This reverts commit d379767851ac3dc28b1108d87b60ac0cad6c4c4a, which removed
drag-and-drop interaction involving the pathbar, because it interfered with
dragging to move the window from the headerbar.
This made it impossible to drop files into a parent directory. But acting as
a drop target would not interfere with dragging to move.
We are removing again the problematic drag-source parts in the next commit.
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=785619
src/nautilus-pathbar.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 177 insertions(+), 0 deletions(-)
---
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index 60817b4..b750ffd 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -94,6 +94,9 @@ struct _NautilusPathBarDetails
guint need_timer : 1;
guint ignore_click : 1;
+ unsigned int drag_slider_timeout;
+ gboolean drag_slider_timeout_for_up_button;
+
GActionGroup *action_group;
GMenu *context_menu;
@@ -226,6 +229,76 @@ get_slider_button (NautilusPathBar *path_bar,
return button;
}
+static gboolean
+slider_timeout (gpointer user_data)
+{
+ NautilusPathBar *path_bar;
+
+ path_bar = NAUTILUS_PATH_BAR (user_data);
+
+ path_bar->priv->drag_slider_timeout = 0;
+
+ if (gtk_widget_get_visible (GTK_WIDGET (path_bar)))
+ {
+ if (path_bar->priv->drag_slider_timeout_for_up_button)
+ {
+ nautilus_path_bar_scroll_up (path_bar);
+ }
+ else
+ {
+ nautilus_path_bar_scroll_down (path_bar);
+ }
+ }
+
+ return FALSE;
+}
+
+static void
+nautilus_path_bar_slider_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ unsigned int time,
+ gpointer user_data)
+{
+ NautilusPathBar *path_bar;
+ GtkSettings *settings;
+ unsigned int timeout;
+
+ path_bar = NAUTILUS_PATH_BAR (user_data);
+
+ if (path_bar->priv->drag_slider_timeout == 0)
+ {
+ settings = gtk_widget_get_settings (widget);
+
+ g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+ path_bar->priv->drag_slider_timeout =
+ g_timeout_add (timeout,
+ slider_timeout,
+ path_bar);
+
+ path_bar->priv->drag_slider_timeout_for_up_button =
+ widget == path_bar->priv->up_slider_button;
+ }
+}
+
+static void
+nautilus_path_bar_slider_drag_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ unsigned int time,
+ gpointer user_data)
+{
+ NautilusPathBar *path_bar;
+
+ path_bar = NAUTILUS_PATH_BAR (user_data);
+
+ if (path_bar->priv->drag_slider_timeout != 0)
+ {
+ g_source_remove (path_bar->priv->drag_slider_timeout);
+ path_bar->priv->drag_slider_timeout = 0;
+ }
+}
+
static void
nautilus_path_bar_init (NautilusPathBar *path_bar)
{
@@ -266,6 +339,30 @@ nautilus_path_bar_init (NautilusPathBar *path_bar)
g_signal_connect (path_bar->priv->down_slider_button, "button-press-event", G_CALLBACK
(nautilus_path_bar_slider_button_press), path_bar);
g_signal_connect (path_bar->priv->down_slider_button, "button-release-event", G_CALLBACK
(nautilus_path_bar_slider_button_release), path_bar);
+ gtk_drag_dest_set (GTK_WIDGET (path_bar->priv->up_slider_button),
+ 0, NULL, 0, 0);
+ gtk_drag_dest_set_track_motion (GTK_WIDGET (path_bar->priv->up_slider_button), TRUE);
+ g_signal_connect (path_bar->priv->up_slider_button,
+ "drag-motion",
+ G_CALLBACK (nautilus_path_bar_slider_drag_motion),
+ path_bar);
+ g_signal_connect (path_bar->priv->up_slider_button,
+ "drag-leave",
+ G_CALLBACK (nautilus_path_bar_slider_drag_leave),
+ path_bar);
+
+ gtk_drag_dest_set (GTK_WIDGET (path_bar->priv->down_slider_button),
+ 0, NULL, 0, 0);
+ gtk_drag_dest_set_track_motion (GTK_WIDGET (path_bar->priv->down_slider_button), TRUE);
+ g_signal_connect (path_bar->priv->down_slider_button,
+ "drag-motion",
+ G_CALLBACK (nautilus_path_bar_slider_drag_motion),
+ path_bar);
+ g_signal_connect (path_bar->priv->down_slider_button,
+ "drag-leave",
+ G_CALLBACK (nautilus_path_bar_slider_drag_leave),
+ path_bar);
+
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar)),
GTK_STYLE_CLASS_LINKED);
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar)),
@@ -281,6 +378,12 @@ nautilus_path_bar_finalize (GObject *object)
nautilus_path_bar_stop_scrolling (path_bar);
+ if (path_bar->priv->drag_slider_timeout != 0)
+ {
+ g_source_remove (path_bar->priv->drag_slider_timeout);
+ path_bar->priv->drag_slider_timeout = 0;
+ }
+
g_list_free (path_bar->priv->button_list);
unschedule_pop_up_context_menu (NAUTILUS_PATH_BAR (object));
@@ -1568,6 +1671,15 @@ button_event_cb (GtkWidget *button,
return GDK_EVENT_PROPAGATE;
}
+static void
+button_drag_begin_cb (GtkWidget *widget,
+ GdkDragContext *drag_context,
+ gpointer user_data)
+{
+ g_object_set_data (G_OBJECT (widget), "handle-button-release",
+ GINT_TO_POINTER (FALSE));
+}
+
static GIcon *
get_gicon_for_mount (ButtonData *button_data)
{
@@ -1732,6 +1844,66 @@ setup_button_type (ButtonData *button_data,
}
static void
+button_drag_data_get_cb (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time_,
+ gpointer user_data)
+{
+ ButtonData *button_data;
+ char *uri_list[2];
+ char *tmp;
+
+ button_data = user_data;
+
+ uri_list[0] = g_file_get_uri (button_data->path);
+ uri_list[1] = NULL;
+
+ if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST)
+ {
+ tmp = g_strdup_printf ("%s\r\n", uri_list[0]);
+ gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data),
+ 8, (const guchar *) tmp, strlen (tmp));
+ g_free (tmp);
+ }
+ else if (info == NAUTILUS_ICON_DND_URI_LIST)
+ {
+ gtk_selection_data_set_uris (selection_data, uri_list);
+ }
+
+ g_free (uri_list[0]);
+}
+
+static void
+setup_button_drag_source (ButtonData *button_data)
+{
+ GtkTargetList *target_list;
+ const GtkTargetEntry targets[] =
+ {
+ { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST }
+ };
+
+ gtk_drag_source_set (button_data->button,
+ GDK_BUTTON1_MASK |
+ GDK_BUTTON2_MASK,
+ NULL, 0,
+ GDK_ACTION_MOVE |
+ GDK_ACTION_COPY |
+ GDK_ACTION_LINK |
+ GDK_ACTION_ASK);
+
+ target_list = gtk_target_list_new (targets, G_N_ELEMENTS (targets));
+ gtk_target_list_add_uri_targets (target_list, NAUTILUS_ICON_DND_URI_LIST);
+ gtk_drag_source_set_target_list (button_data->button, target_list);
+ gtk_target_list_unref (target_list);
+
+ g_signal_connect (button_data->button, "drag-data-get",
+ G_CALLBACK (button_drag_data_get_cb),
+ button_data);
+}
+
+static void
button_data_file_changed (NautilusFile *file,
ButtonData *button_data)
{
@@ -1942,8 +2114,13 @@ make_button_data (NautilusPathBar *path_bar,
g_signal_connect (button_data->button, "clicked", G_CALLBACK (button_clicked_cb), button_data);
g_signal_connect (button_data->button, "button-press-event", G_CALLBACK (button_event_cb), button_data);
g_signal_connect (button_data->button, "button-release-event", G_CALLBACK (button_event_cb),
button_data);
+ g_signal_connect (button_data->button, "drag-begin", G_CALLBACK (button_drag_begin_cb), button_data);
g_object_weak_ref (G_OBJECT (button_data->button), (GWeakNotify) button_data_free, button_data);
+ setup_button_drag_source (button_data);
+
+ nautilus_drag_slot_proxy_init (button_data->button, button_data->file, NULL);
+
g_object_unref (path);
return button_data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]