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



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.

> use the real icon for the file at the right size gotten from NautilusIconFactor.
> [...]
> Don't hardcode the format of the gnome icon list [...], instead use
> nautilus_drag_data_get. The data you hardcode is wrong too, the icon is
> not 1x1 pixels.
> [...]
> We normally use the drag_begin and drag_data_get form of signal names in
> Nautilus.

Would you mind reviewing this new version of the patch as well?
Thanks for your suggestions and efforts!

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-icon-factory.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-factory.c,v
retrieving revision 1.312
diff -u -p -r1.312 nautilus-icon-factory.c
--- libnautilus-private/nautilus-icon-factory.c	11 Jan 2005 12:14:12 -0000	1.312
+++ libnautilus-private/nautilus-icon-factory.c	21 Feb 2005 13:29:53 -0000
@@ -989,6 +989,9 @@ get_larger_icon_size (guint size)
 	if (size < NAUTILUS_ICON_SIZE_SMALLER) {
 		return NAUTILUS_ICON_SIZE_SMALLER;
 	}
+	if (size < NAUTILUS_ICON_SIZE_DND) {
+		return NAUTILUS_ICON_SIZE_DND;
+	}
 	if (size < NAUTILUS_ICON_SIZE_SMALL) {
 		return NAUTILUS_ICON_SIZE_SMALL;
 	}
@@ -1021,6 +1024,9 @@ get_smaller_icon_size (guint size)
 	}
 	if (size > NAUTILUS_ICON_SIZE_SMALL) {
 		return NAUTILUS_ICON_SIZE_SMALL;
+	}
+	if (size > NAUTILUS_ICON_SIZE_DND) {
+		return NAUTILUS_ICON_SIZE_DND;
 	}
 	if (size > NAUTILUS_ICON_SIZE_SMALLER) {
 		return NAUTILUS_ICON_SIZE_SMALLER;
Index: libnautilus-private/nautilus-icon-factory.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-factory.h,v
retrieving revision 1.51
diff -u -p -r1.51 nautilus-icon-factory.h
--- libnautilus-private/nautilus-icon-factory.h	29 Nov 2004 16:39:31 -0000	1.51
+++ libnautilus-private/nautilus-icon-factory.h	21 Feb 2005 13:29:54 -0000
@@ -83,6 +83,9 @@ typedef enum {
  */
 #define NAUTILUS_ICON_SIZE_FOR_MENUS	20
 
+/* matches size associated with GTK_ICON_SIZE_DND */
+#define NAUTILUS_ICON_SIZE_DND          32
+
 /* here's a structure to hold the emblem attach points */
 
 #define MAX_ATTACH_POINTS 12
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	21 Feb 2005 13:30:22 -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, 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]