[nautilus] Switch location on list view hover



commit 0d635bdab11033b1dfecde908d6c278f0e760291
Author: William Jon McCann <jmccann redhat com>
Date:   Sat Jan 19 14:04:53 2013 -0500

    Switch location on list view hover
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692097

 libnautilus-private/nautilus-tree-view-drag-dest.c |   73 +++++++++++++++++++-
 libnautilus-private/nautilus-tree-view-drag-dest.h |    2 +
 src/nautilus-list-view.c                           |   10 +++
 src/nautilus-view-dnd.c                            |   14 ++++
 src/nautilus-view-dnd.h                            |    2 +
 5 files changed, 100 insertions(+), 1 deletions(-)
---
diff --git a/libnautilus-private/nautilus-tree-view-drag-dest.c b/libnautilus-private/nautilus-tree-view-drag-dest.c
index a338924..df37464 100644
--- a/libnautilus-private/nautilus-tree-view-drag-dest.c
+++ b/libnautilus-private/nautilus-tree-view-drag-dest.c
@@ -56,10 +56,12 @@ struct _NautilusTreeViewDragDestDetails {
 	GtkSelectionData *drag_data;
 	GList *drag_list;
 
+	guint hover_id;
 	guint highlight_id;
 	guint scroll_id;
 
 	char *direct_save_uri;
+	char *target_uri;
 };
 
 enum {
@@ -70,6 +72,7 @@ enum {
 	HANDLE_URI_LIST,
 	HANDLE_TEXT,
 	HANDLE_RAW,
+	HANDLE_HOVER,
 	LAST_SIGNAL
 };
 
@@ -248,6 +251,15 @@ get_drag_data (NautilusTreeViewDragDest *dest,
 }
 
 static void
+remove_hover_timer (NautilusTreeViewDragDest *dest)
+{
+	if (dest->details->hover_id != 0) {
+		g_source_remove (dest->details->hover_id);
+		dest->details->hover_id = 0;
+	}
+}
+
+static void
 free_drag_data (NautilusTreeViewDragDest *dest)
 {
 	dest->details->have_drag_data = FALSE;
@@ -264,6 +276,50 @@ free_drag_data (NautilusTreeViewDragDest *dest)
 
 	g_free (dest->details->direct_save_uri);
 	dest->details->direct_save_uri = NULL;
+
+	g_free (dest->details->target_uri);
+	dest->details->target_uri = NULL;
+
+	remove_hover_timer (dest);
+}
+
+static gboolean
+hover_timer (gpointer user_data)
+{
+	NautilusTreeViewDragDest *dest = user_data;
+
+	dest->details->hover_id = 0;
+
+	g_signal_emit (dest, signals[HANDLE_HOVER], 0, dest->details->target_uri);
+
+	return FALSE;
+}
+
+static void
+check_hover_timer (NautilusTreeViewDragDest *dest,
+		   const char               *uri)
+{
+	GtkSettings *settings;
+	guint timeout;
+
+	if (g_strcmp0 (uri, dest->details->target_uri) == 0) {
+		return;
+	}
+	remove_hover_timer (dest);
+
+	settings = gtk_widget_get_settings (GTK_WIDGET (dest->details->tree_view));
+	g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+
+	g_free (dest->details->target_uri);
+	dest->details->target_uri = NULL;
+
+	if (uri != NULL) {
+		dest->details->target_uri = g_strdup (uri);
+		dest->details->hover_id =
+			gdk_threads_add_timeout (timeout,
+						 hover_timer,
+						 dest);
+	}
 }
 
 static char *
@@ -453,11 +509,16 @@ drag_motion_callback (GtkWidget *widget,
 					 NULL);
 	
 	if (action) {
+		char *uri;
 		set_drag_dest_row (dest, drop_path);
+		uri = get_drop_target_uri_for_path (dest, path);
+		check_hover_timer (dest, uri);
+		g_free (uri);
 	} else {
 		clear_drag_dest_row (dest);
+		remove_hover_timer (dest);
 	}
-	
+
 	if (path) {
 		gtk_tree_path_free (path);
 	}
@@ -1075,6 +1136,16 @@ nautilus_tree_view_drag_dest_class_init (NautilusTreeViewDragDestClass *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 (NautilusTreeViewDragDestClass,
+					       handle_hover),
+			      NULL, NULL,
+			      g_cclosure_marshal_generic,
+			      G_TYPE_NONE, 1,
+			      G_TYPE_STRING);
 }
 
 
diff --git a/libnautilus-private/nautilus-tree-view-drag-dest.h b/libnautilus-private/nautilus-tree-view-drag-dest.h
index 10171ee..40ea1fc 100644
--- a/libnautilus-private/nautilus-tree-view-drag-dest.h
+++ b/libnautilus-private/nautilus-tree-view-drag-dest.h
@@ -90,6 +90,8 @@ struct _NautilusTreeViewDragDestClass {
 				  GdkDragAction action,
 				  int x,
 				  int y);
+	void (* handle_hover)   (NautilusTreeViewDragDest *dest,
+				 const char *target_uri);
 };
 
 GType                     nautilus_tree_view_drag_dest_get_type (void);
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 722e503..e7b7b5e 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -1198,6 +1198,14 @@ list_view_handle_raw (NautilusTreeViewDragDest *dest, const char *raw_data,
 }
 
 static void
+list_view_handle_hover (NautilusTreeViewDragDest *dest,
+			const char *target_uri,
+			NautilusListView *view)
+{
+	nautilus_view_handle_hover (NAUTILUS_VIEW (view), target_uri);
+}
+
+static void
 move_copy_items_callback (NautilusTreeViewDragDest *dest,
 			  const GList *item_uris,
 			  const char *target_uri,
@@ -1400,6 +1408,8 @@ create_and_set_up_tree_view (NautilusListView *view)
 				 G_CALLBACK (list_view_handle_text), view, 0);
 	g_signal_connect_object (view->details->drag_dest, "handle_raw",
 				 G_CALLBACK (list_view_handle_raw), view, 0);
+	g_signal_connect_object (view->details->drag_dest, "handle_hover",
+				 G_CALLBACK (list_view_handle_hover), view, 0);
 
 	g_signal_connect_object (gtk_tree_view_get_selection (view->details->tree_view),
 				 "changed",
diff --git a/src/nautilus-view-dnd.c b/src/nautilus-view-dnd.c
index 863d982..fbae954 100644
--- a/src/nautilus-view-dnd.c
+++ b/src/nautilus-view-dnd.c
@@ -513,3 +513,17 @@ nautilus_view_drop_proxy_received_uris (NautilusView *view,
 
 	g_free (container_uri);
 }
+
+void
+nautilus_view_handle_hover (NautilusView *view,
+			    const char   *target_uri)
+{
+	NautilusWindowSlot *slot;
+	GFile *location;
+
+	slot = nautilus_view_get_nautilus_window_slot (view);
+
+	location = g_file_new_for_uri (target_uri);
+	nautilus_window_slot_open_location (slot, location, 0);
+	g_object_unref (location);
+}
diff --git a/src/nautilus-view-dnd.h b/src/nautilus-view-dnd.h
index 16d0e55..bdfa1f6 100644
--- a/src/nautilus-view-dnd.h
+++ b/src/nautilus-view-dnd.h
@@ -58,6 +58,8 @@ void nautilus_view_handle_raw_drop          (NautilusView  *view,
 					     GdkDragAction  action,
 					     int            x,
 					     int            y);
+void nautilus_view_handle_hover             (NautilusView  *view,
+					     const char    *target_uri);
 
 void nautilus_view_drop_proxy_received_uris (NautilusView  *view,
 					     const GList   *uris,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]