Commit 161b8424 authored by William Jon McCann's avatar William Jon McCann
Browse files

Switch location on canvas view hover

https://bugzilla.gnome.org/show_bug.cgi?id=692097
parent 0d635bda
......@@ -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),
......
......@@ -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.
......
......@@ -1242,6 +1242,15 @@ nautilus_canvas_dnd_update_drop_target (NautilusCanvasContainer *container,
set_drop_target (container, icon);
}
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)
{
......@@ -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
......@@ -1455,6 +1469,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,
......@@ -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);
......
......@@ -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;
......
......@@ -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 (),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment