summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Neumair <cneumair@gnome.org>2008-07-13 12:07:53 +0000
committerChristian Neumair <cneumair@src.gnome.org>2008-07-13 12:07:53 +0000
commitd4f08bc033176b37124695263928999a63748beb (patch)
treee4fe3ae554af62079b2fd50b7178d664d5b88ec0 /src
parent88d90c73c4c0a74edd2f13ca00ab31e7755568cf (diff)
downloadnautilus-d4f08bc033176b37124695263928999a63748beb.tar.gz
Add simple slot drop proxy API to libnautilus-private, centered around
2008-07-13 Christian Neumair <cneumair@gnome.org> * libnautilus-private/nautilus-dnd.c (nautilus_drag_uri_array_from_selection_list), (nautilus_drag_uri_list_from_selection_list), (nautilus_drag_uri_array_from_list), (nautilus_drag_uri_list_from_array), (slot_proxy_drag_motion), (drag_info_clear), (slot_proxy_drag_leave), (slot_proxy_drag_drop), (slot_proxy_handle_drop), (slot_proxy_drag_data_received), (nautilus_drag_slot_proxy_init): * libnautilus-private/nautilus-dnd.h: Add simple slot drop proxy API to libnautilus-private, centered around nautilus_drag_slot_proxy_init(). The notebook tab label drop targets will later be ported to this API. Add API for converting URI lists to URI arrays, and for constructing URI lists and arrays from selection lists. * src/nautilus-notebook.c (notebook_tab_drag_data_received): Use nautilus_drag_uri_array_from_selection_list(). * src/nautilus-pathbar.c (slider_timeout), (nautilus_path_bar_slider_drag_motion), (nautilus_path_bar_slider_drag_leave), (nautilus_path_bar_init), (nautilus_path_bar_finalize), (button_data_free), (button_drag_data_get_cb), (setup_button_drag_source), (make_directory_button): * src/nautilus-pathbar.h: Add path bar drop targets, use nautilus_drag_slot_proxy_init() for setup. Also offer GNOME icon lists as drag target. Reveal hidden paths when hovering over the up/down sliders for some time. Fixes #309842. svn path=/trunk/; revision=14356
Diffstat (limited to 'src')
-rw-r--r--src/nautilus-notebook.c16
-rw-r--r--src/nautilus-pathbar.c179
-rw-r--r--src/nautilus-pathbar.h3
3 files changed, 160 insertions, 38 deletions
diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c
index 97912fe31..9f29c97e3 100644
--- a/src/nautilus-notebook.c
+++ b/src/nautilus-notebook.c
@@ -255,8 +255,7 @@ notebook_tab_drag_data_received (GtkWidget *widget,
NautilusWindow *window;
NautilusNavigationWindow *navigation_window;
GtkWidget *notebook;
- GList *uri_list, *selection_list, *l;
- NautilusDragSelectionItem *selection_item;
+ GList *uri_list, *selection_list;
char **uris;
int i;
@@ -285,18 +284,7 @@ notebook_tab_drag_data_received (GtkWidget *widget,
return;
}
- i = 0;
-
- uris = g_new0 (char *, g_list_length (selection_list));
- for (l = selection_list; l != NULL; l = l->next) {
- selection_item = (NautilusDragSelectionItem *) l->data;
-
- uris[i] = g_strdup (selection_item->uri);
- if (uris[i] != NULL) {
- i++;
- }
- }
- uris[i] = NULL;
+ uris = nautilus_drag_uri_array_from_selection_list (selection_list);
nautilus_drag_destroy_selection_list (selection_list);
} else {
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index c8b8a7541..78076cd98 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -32,7 +32,13 @@
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus-private/nautilus-icon-names.h>
#include <libnautilus-private/nautilus-trash-monitor.h>
+#include <libnautilus-private/nautilus-marshal.h>
+#include <libnautilus-private/nautilus-dnd.h>
+#include <libnautilus-private/nautilus-icon-dnd.h>
#include "nautilus-pathbar.h"
+#include "nautilus-window.h"
+#include "nautilus-window-private.h"
+#include "nautilus-window-slot.h"
enum {
PATH_CLICKED,
@@ -78,6 +84,8 @@ struct _ButtonData
GtkWidget *label;
guint ignore_changes : 1;
guint file_is_hidden : 1;
+
+ NautilusDragSlotProxyInfo drag_info;
};
/* This macro is used to check if a button can be used as a fake root.
@@ -217,6 +225,70 @@ trash_state_changed_cb (NautilusTrashMonitor *monitor,
g_object_unref (file);
}
+static gboolean
+slider_timeout (gpointer user_data)
+{
+ NautilusPathBar *path_bar;
+
+ path_bar = NAUTILUS_PATH_BAR (user_data);
+
+ path_bar->drag_slider_timeout = 0;
+
+ if (GTK_WIDGET_VISIBLE (GTK_WIDGET (path_bar))) {
+ if (path_bar->drag_slider_timeout_for_up_button) {
+ nautilus_path_bar_scroll_up (path_bar->up_slider_button, path_bar);
+ } else {
+ nautilus_path_bar_scroll_down (path_bar->down_slider_button, 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->drag_slider_timeout == 0) {
+ settings = gtk_widget_get_settings (widget);
+
+ g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+ path_bar->drag_slider_timeout =
+ g_timeout_add (timeout,
+ slider_timeout,
+ path_bar);
+
+ path_bar->drag_slider_timeout_for_up_button =
+ widget == path_bar->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->drag_slider_timeout != 0) {
+ g_source_remove (path_bar->drag_slider_timeout);
+ path_bar->drag_slider_timeout = 0;
+ }
+}
+
static void
nautilus_path_bar_init (NautilusPathBar *path_bar)
{
@@ -250,6 +322,30 @@ nautilus_path_bar_init (NautilusPathBar *path_bar)
g_signal_connect (path_bar->down_slider_button, "button_press_event", G_CALLBACK (nautilus_path_bar_slider_button_press), path_bar);
g_signal_connect (path_bar->down_slider_button, "button_release_event", G_CALLBACK (nautilus_path_bar_slider_button_release), path_bar);
+ gtk_drag_dest_set (GTK_WIDGET (path_bar->up_slider_button),
+ 0, NULL, 0, 0);
+ gtk_drag_dest_set_track_motion (GTK_WIDGET (path_bar->up_slider_button), TRUE);
+ g_signal_connect (path_bar->up_slider_button,
+ "drag-motion",
+ G_CALLBACK (nautilus_path_bar_slider_drag_motion),
+ path_bar);
+ g_signal_connect (path_bar->up_slider_button,
+ "drag-leave",
+ G_CALLBACK (nautilus_path_bar_slider_drag_leave),
+ path_bar);
+
+ gtk_drag_dest_set (GTK_WIDGET (path_bar->down_slider_button),
+ 0, NULL, 0, 0);
+ gtk_drag_dest_set_track_motion (GTK_WIDGET (path_bar->up_slider_button), TRUE);
+ g_signal_connect (path_bar->down_slider_button,
+ "drag-motion",
+ G_CALLBACK (nautilus_path_bar_slider_drag_motion),
+ path_bar);
+ g_signal_connect (path_bar->down_slider_button,
+ "drag-leave",
+ G_CALLBACK (nautilus_path_bar_slider_drag_leave),
+ path_bar);
+
g_signal_connect (nautilus_trash_monitor_get (),
"trash_state_changed",
G_CALLBACK (trash_state_changed_cb),
@@ -314,6 +410,11 @@ nautilus_path_bar_finalize (GObject *object)
nautilus_path_bar_stop_scrolling (path_bar);
+ if (path_bar->drag_slider_timeout != 0) {
+ g_source_remove (path_bar->drag_slider_timeout);
+ path_bar->drag_slider_timeout = 0;
+ }
+
g_list_free (path_bar->button_list);
if (path_bar->root_path) {
g_object_unref (path_bar->root_path);
@@ -1121,6 +1222,9 @@ button_data_free (ButtonData *button_data)
g_object_unref (button_data->custom_icon);
}
g_free (button_data);
+
+ g_object_unref (button_data->drag_info.target_location);
+ button_data->drag_info.target_location = NULL;
}
static const char *
@@ -1281,22 +1385,53 @@ button_drag_data_get_cb (GtkWidget *widget,
GtkSelectionData *selection_data,
guint info,
guint time_,
- gpointer data)
+ gpointer user_data)
{
ButtonData *button_data;
- char *uri_list;
- char *uri;
-
- button_data = data;
- uri = g_file_get_uri (button_data->path);
- uri_list = g_strconcat (uri, "\r\n", NULL);
- g_free (uri);
- gtk_selection_data_set (selection_data,
- selection_data->target,
- 8,
- uri_list,
- strlen (uri_list));
- g_free (uri_list);
+ 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, selection_data->target,
+ 8, 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,
+ 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 ButtonData *
@@ -1307,10 +1442,6 @@ make_directory_button (NautilusPathBar *path_bar,
gboolean base_dir,
gboolean file_is_hidden)
{
- const GtkTargetEntry targets[] = {
- { "text/uri-list", 0, 0 }
- };
-
GtkWidget *child;
GtkWidget *label_alignment;
ButtonData *button_data;
@@ -1325,6 +1456,8 @@ make_directory_button (NautilusPathBar *path_bar,
button_data->type = find_button_type (path_bar, path, button_data);
button_data->button = gtk_toggle_button_new ();
gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
+
+ button_data->drag_info.target_location = g_object_ref (path);
switch (button_data->type) {
case ROOT_BUTTON:
@@ -1391,12 +1524,10 @@ make_directory_button (NautilusPathBar *path_bar,
g_signal_connect (button_data->button, "clicked", G_CALLBACK (button_clicked_cb), button_data);
g_object_weak_ref (G_OBJECT (button_data->button), (GWeakNotify) button_data_free, button_data);
- gtk_drag_source_set (button_data->button,
- GDK_BUTTON1_MASK,
- targets,
- G_N_ELEMENTS (targets),
- GDK_ACTION_COPY);
- g_signal_connect (button_data->button, "drag-data-get",G_CALLBACK (button_drag_data_get_cb), button_data);
+ setup_button_drag_source (button_data);
+
+ nautilus_drag_slot_proxy_init (button_data->button,
+ &(button_data->drag_info));
return button_data;
}
diff --git a/src/nautilus-pathbar.h b/src/nautilus-pathbar.h
index 549016a71..26a1a73b3 100644
--- a/src/nautilus-pathbar.h
+++ b/src/nautilus-pathbar.h
@@ -61,6 +61,9 @@ struct _NautilusPathBar
guint slider_visible : 1;
guint need_timer : 1;
guint ignore_click : 1;
+
+ unsigned int drag_slider_timeout;
+ gboolean drag_slider_timeout_for_up_button;
};
struct _NautilusPathBarClass