[nautilus] Switch location on canvas view hover
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Switch location on canvas view hover
- Date: Mon, 21 Jan 2013 16:09:09 +0000 (UTC)
commit 161b8424b59f66aad527ce47827bca74bf850f81
Author: William Jon McCann <jmccann redhat com>
Date: Sat Jan 19 14:49:20 2013 -0500
Switch location on canvas view hover
https://bugzilla.gnome.org/show_bug.cgi?id=692097
libnautilus-private/nautilus-canvas-container.c | 11 ++++
libnautilus-private/nautilus-canvas-container.h | 2 +
libnautilus-private/nautilus-canvas-dnd.c | 66 +++++++++++++++++++++++
libnautilus-private/nautilus-canvas-dnd.h | 4 +-
src/nautilus-canvas-view.c | 10 ++++
5 files changed, 92 insertions(+), 1 deletions(-)
---
diff --git a/libnautilus-private/nautilus-canvas-container.c b/libnautilus-private/nautilus-canvas-container.c
index 3fffae5..8024962 100644
--- a/libnautilus-private/nautilus-canvas-container.c
+++ b/libnautilus-private/nautilus-canvas-container.c
@@ -241,6 +241,7 @@ enum {
HANDLE_URI_LIST,
HANDLE_TEXT,
HANDLE_RAW,
+ HANDLE_HOVER,
SELECTION_CHANGED,
ICON_ADDED,
ICON_REMOVED,
@@ -4935,6 +4936,16 @@ nautilus_canvas_container_class_init (NautilusCanvasContainerClass *class)
GDK_TYPE_DRAG_ACTION,
G_TYPE_INT,
G_TYPE_INT);
+ signals[HANDLE_HOVER] =
+ g_signal_new ("handle_hover",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ handle_hover),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
signals[GET_CONTAINER_URI]
= g_signal_new ("get_container_uri",
G_TYPE_FROM_CLASS (class),
diff --git a/libnautilus-private/nautilus-canvas-container.h b/libnautilus-private/nautilus-canvas-container.h
index 5ad6d52..d5ec7a0 100644
--- a/libnautilus-private/nautilus-canvas-container.h
+++ b/libnautilus-private/nautilus-canvas-container.h
@@ -123,6 +123,8 @@ typedef struct {
GdkDragAction action,
int x,
int y);
+ void (* handle_hover) (NautilusCanvasContainer *container,
+ const char *target_uri);
/* Queries on the container for subclass/client.
* These must be implemented. The default "do nothing" is not good enough.
diff --git a/libnautilus-private/nautilus-canvas-dnd.c b/libnautilus-private/nautilus-canvas-dnd.c
index 5329d9b..efa71d8 100644
--- a/libnautilus-private/nautilus-canvas-dnd.c
+++ b/libnautilus-private/nautilus-canvas-dnd.c
@@ -1243,6 +1243,15 @@ nautilus_canvas_dnd_update_drop_target (NautilusCanvasContainer *container,
}
static void
+remove_hover_timer (NautilusCanvasDndInfo *dnd_info)
+{
+ if (dnd_info->hover_id != 0) {
+ g_source_remove (dnd_info->hover_id);
+ dnd_info->hover_id = 0;
+ }
+}
+
+static void
nautilus_canvas_container_free_drag_data (NautilusCanvasContainer *container)
{
NautilusCanvasDndInfo *dnd_info;
@@ -1265,6 +1274,11 @@ nautilus_canvas_container_free_drag_data (NautilusCanvasContainer *container)
g_free (dnd_info->drag_info.direct_save_uri);
dnd_info->drag_info.direct_save_uri = NULL;
}
+
+ g_free (dnd_info->target_uri);
+ dnd_info->target_uri = NULL;
+
+ remove_hover_timer (dnd_info);
}
static void
@@ -1456,6 +1470,51 @@ stop_dnd_highlight (GtkWidget *widget)
}
static gboolean
+hover_timer (gpointer user_data)
+{
+ NautilusCanvasContainer *container = user_data;
+ NautilusCanvasDndInfo *dnd_info;
+
+ dnd_info = container->details->dnd_info;
+
+ dnd_info->hover_id = 0;
+
+ g_signal_emit_by_name (container, "handle_hover", dnd_info->target_uri);
+
+ return FALSE;
+}
+
+static void
+check_hover_timer (NautilusCanvasContainer *container,
+ const char *uri)
+{
+ NautilusCanvasDndInfo *dnd_info;
+ GtkSettings *settings;
+ guint timeout;
+
+ dnd_info = container->details->dnd_info;
+
+ if (g_strcmp0 (uri, dnd_info->target_uri) == 0) {
+ return;
+ }
+ remove_hover_timer (dnd_info);
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (container));
+ g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+
+ g_free (dnd_info->target_uri);
+ dnd_info->target_uri = NULL;
+
+ if (uri != NULL) {
+ dnd_info->target_uri = g_strdup (uri);
+ dnd_info->hover_id =
+ gdk_threads_add_timeout (timeout,
+ hover_timer,
+ container);
+ }
+}
+
+static gboolean
drag_motion_callback (GtkWidget *widget,
GdkDragContext *context,
int x, int y,
@@ -1474,7 +1533,14 @@ drag_motion_callback (GtkWidget *widget,
nautilus_canvas_container_get_drop_action (NAUTILUS_CANVAS_CONTAINER (widget), context, x, y,
&action);
if (action != 0) {
+ char *uri;
+ uri = nautilus_canvas_container_find_drop_target (NAUTILUS_CANVAS_CONTAINER (widget),
+ context, x, y, NULL, TRUE);
+ check_hover_timer (NAUTILUS_CANVAS_CONTAINER (widget), uri);
+ g_free (uri);
start_dnd_highlight (widget);
+ } else {
+ remove_hover_timer (NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info);
}
gdk_drag_status (context, action, time);
diff --git a/libnautilus-private/nautilus-canvas-dnd.h b/libnautilus-private/nautilus-canvas-dnd.h
index 00d8719..f7068b0 100644
--- a/libnautilus-private/nautilus-canvas-dnd.h
+++ b/libnautilus-private/nautilus-canvas-dnd.h
@@ -37,9 +37,11 @@ typedef struct {
NautilusDragInfo drag_info;
gboolean highlighted;
-
+ char *target_uri;
+
/* Shadow for the icons being dragged. */
EelCanvasItem *shadow;
+ guint hover_id;
} NautilusCanvasDndInfo;
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index cc5e0e1..e25d327 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -2007,6 +2007,14 @@ canvas_view_handle_raw (NautilusCanvasContainer *container, const char *raw_data
raw_data, length, target_uri, direct_save_uri, action, x, y);
}
+static void
+canvas_view_handle_hover (NautilusCanvasContainer *container,
+ const char *target_uri,
+ NautilusCanvasView *view)
+{
+ nautilus_view_handle_hover (NAUTILUS_VIEW (view), target_uri);
+}
+
static char *
canvas_view_get_first_visible_file (NautilusView *view)
{
@@ -2228,6 +2236,8 @@ nautilus_canvas_view_init (NautilusCanvasView *canvas_view)
G_CALLBACK (canvas_view_handle_text), canvas_view, 0);
g_signal_connect_object (canvas_container, "handle_raw",
G_CALLBACK (canvas_view_handle_raw), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "handle_hover",
+ G_CALLBACK (canvas_view_handle_hover), canvas_view, 0);
canvas_view->details->clipboard_handler_id =
g_signal_connect (nautilus_clipboard_monitor_get (),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]