Re: [PATCH] Allow to use move/copy/link operations on open folder (was: Re: [Usability] Interacting with open folders)



Am Dienstag, den 22.02.2005, 10:07 +0100 schrieb Alexander Larsson:
> On Mon, 2005-02-21 at 14:38 +0100, Christian Neumair wrote:
> > Am Montag, den 14.02.2005, 10:55 +0100 schrieb Alexander Larsson:
> > > On Thu, 2005-02-10 at 20:11 +0100, Christian Neumair wrote:
> > > > After applying this patch, you should be able to drag any focused
> > > > folder's spatial window through it's location button located on the
> > > > bottom left of the window. It will allow you to move, copy or link the
> > > > dragged folder to any other folder, including the trash.
> > 
> > Would you mind reviewing this new version of the patch as well?
> > Thanks for your suggestions and efforts!
> 
> It also needs GDK_BUTTON2_MASK as martin pointed out.

OK, here comes the slightly modified version. It works like a charm,
both for middle and for left-click DND :).
Maybe you could approve it as well, so that I can offer the release team
can this patch together with your approval.

-- 
Christian Neumair <chris gnome-de org>
Index: src/nautilus-spatial-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window.c,v
retrieving revision 1.436
diff -u -p -r1.436 nautilus-spatial-window.c
--- src/nautilus-spatial-window.c	27 Jan 2005 12:35:47 -0000	1.436
+++ src/nautilus-spatial-window.c	23 Feb 2005 18:39:30 -0000
@@ -48,6 +48,7 @@
 #include <eel/eel-string.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk/gdkx.h>
+#include <gtk/gtkdnd.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtkmenubar.h>
 #include <gtk/gtkmenuitem.h>
@@ -63,6 +64,7 @@
 #include <libgnomeui/gnome-window-icon.h>
 #include <libgnomevfs/gnome-vfs-uri.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
+#include <libnautilus-private/nautilus-dnd.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-ui-utilities.h>
 #include <libnautilus-private/nautilus-file-attributes.h>
@@ -91,6 +93,10 @@ struct _NautilusSpatialWindowDetails {
 	GnomeVFSURI *location;
 };
 
+static GtkTargetEntry location_button_drag_types[] = {
+	{ NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST }
+};
+
 GNOME_CLASS_BOILERPLATE (NautilusSpatialWindow, nautilus_spatial_window,
 			 NautilusWindow, NAUTILUS_TYPE_WINDOW)
 
@@ -536,6 +542,60 @@ location_button_clicked_callback (GtkWid
  	gtk_object_sink (GTK_OBJECT (popup));
 }
 
+static void
+location_button_drag_begin_callback (GtkWidget             *widget,
+				     GdkDragContext        *context,
+				     NautilusSpatialWindow *window)
+{
+	GdkPixbuf *pixbuf;
+
+	pixbuf = nautilus_icon_factory_get_pixbuf_for_file (NAUTILUS_WINDOW (window)->details->viewed_file,
+							    "open", NAUTILUS_ICON_SIZE_DND);
+
+	gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
+
+	g_object_unref (pixbuf);
+}
+
+/* build GNOME icon list, which only contains the window's URI.
+ * If we just used URIs, moving the folder to trash
+ * wouldn't work */
+static void
+get_data_binder (NautilusDragEachSelectedItemDataGet iteratee,
+		 gpointer                            iterator_context,
+		 gpointer                            data)
+{
+	NautilusSpatialWindow *window;
+	gchar                 *uri;
+
+	g_assert (NAUTILUS_IS_SPATIAL_WINDOW (iterator_context));
+	window = NAUTILUS_SPATIAL_WINDOW (iterator_context);
+
+	uri = gnome_vfs_uri_to_string (window->details->location,
+				       GNOME_VFS_URI_HIDE_NONE);
+
+	iteratee (uri,
+		  0,
+		  0,
+		  NAUTILUS_ICON_SIZE_DND,
+		  NAUTILUS_ICON_SIZE_DND,
+		  data);
+
+	g_free (uri);
+}
+
+static void
+location_button_drag_data_get_callback (GtkWidget             *widget,
+					GdkDragContext        *context,
+					GtkSelectionData      *selection_data,
+					guint                  info,
+					guint                  time,
+					NautilusSpatialWindow *window)
+{
+	nautilus_drag_drag_data_get (widget, context, selection_data,
+				     info, time, window, get_data_binder); 
+}
+
 void
 nautilus_spatial_window_set_location_button  (NautilusSpatialWindow *window,
 					      const char            *location)
@@ -642,6 +702,18 @@ nautilus_spatial_window_instance_init (N
 	gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
 	gtk_widget_show (arrow);
 
+	gtk_drag_source_set (window->details->location_button,
+			     GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, location_button_drag_types,
+			     G_N_ELEMENTS (location_button_drag_types),
+			     GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK);
+	g_signal_connect (window->details->location_button,
+			  "drag_begin",
+			  G_CALLBACK (location_button_drag_begin_callback),
+			  window);
+	g_signal_connect (window->details->location_button,
+			  "drag_data_get",
+			  G_CALLBACK (location_button_drag_data_get_callback),
+			  window);
 	
 	gtk_widget_set_sensitive (window->details->location_button, FALSE);
 	g_signal_connect (window->details->location_button, 


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