Re: [PATCH] Drop text in Nautilus window, new file created



Am Freitag, den 01.07.2005, 12:07 +0200 schrieb Alexander Larsson: 
> On Thu, 2005-06-30 at 14:31 +0200, Christian Neumair wrote:
> > Am Donnerstag, den 23.06.2005, 22:07 +0200 schrieb Christian Neumair:
> > > Am Dienstag, den 07.06.2005, 11:36 +0200 schrieb Alexander Larsson:
> > > > On Thu, 2005-06-02 at 11:33 +0200, Christian Neumair wrote:
> > > > > One thing that bugged me for ages in Nautilus is that one can not drop
> > > > > text (from gedit, Epiphany) to Nautilus to create a new file. After
> > > > > applying the attached patch, this works.
> > > 
> > > > [patch review]
> > > 
> > > Thanks for your review! The attached patch should fix all the issues you pointed out.
> > 
> > OK, new version. I've now also fixed the handle_* method declarations
> > and the odd
> > nautilus_file_operations_new_file_from_template/target_filename variable
> > usage.
> 
> I tested this, and it doesn't seem to handle dnd of non-ascii. I tried
> to drop "åäö" into a file and got: "\u00e5\u00e4\u00f6".

OK, I've fixed this. We should have received the dropped text by
gtk_selection_data_get_text instead of simply using the raw data. I've
also redefined NAUTILUS_ICON_DND_TEXT_TYPE to "UTF8_STRING" instead of
"text/plain". Without the latter it didn't work. If it turns out that
"UTF8_STRING" isn't enough for our needs, we can also use
gtk_drag_dest_add_text_targets and friends.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-dnd.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-dnd.h,v
retrieving revision 1.11
diff -u -p -r1.11 nautilus-dnd.h
--- libnautilus-private/nautilus-dnd.h	13 Jan 2005 13:27:51 -0000	1.11
+++ libnautilus-private/nautilus-dnd.h	1 Jul 2005 20:37:09 -0000
@@ -32,7 +32,7 @@
 /* Drag & Drop target names. */
 #define NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE  "x-special/gnome-icon-list"
 #define NAUTILUS_ICON_DND_URI_LIST_TYPE         "text/uri-list"
-#define NAUTILUS_ICON_DND_TEXT_TYPE             "text/plain"
+#define NAUTILUS_ICON_DND_TEXT_TYPE             "UTF8_STRING"
 #define NAUTILUS_ICON_DND_URL_TYPE	        "_NETSCAPE_URL"
 #define NAUTILUS_ICON_DND_COLOR_TYPE            "application/x-color"
 #define NAUTILUS_ICON_DND_BGIMAGE_TYPE          "property/bgimage"
Index: libnautilus-private/nautilus-file-operations.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations.c,v
retrieving revision 1.191
diff -u -p -r1.191 nautilus-file-operations.c
--- libnautilus-private/nautilus-file-operations.c	1 Jul 2005 15:39:07 -0000	1.191
+++ libnautilus-private/nautilus-file-operations.c	1 Jul 2005 20:37:11 -0000
@@ -26,6 +26,7 @@
 
 #include <config.h>
 #include <string.h>
+#include <stdio.h>
 #include "nautilus-file-operations.h"
 
 #include "nautilus-file-operations-progress.h"
@@ -38,6 +39,7 @@
 #include <eel/eel-vfs-extensions.h>
 
 #include <gnome.h>
+#include <gdk/gdkdnd.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtkmessagedialog.h>
 #include <libgnomevfs/gnome-vfs-async-ops.h>
@@ -2231,7 +2233,6 @@ typedef struct {
 	NautilusNewFileCallback done_callback;
 	gpointer data;
 	GtkWidget *parent_view;
-	char *empty_file;
 	GHashTable *debuting_uris;
 } NewFileTransferState;
 
@@ -2298,11 +2299,6 @@ new_file_transfer_callback (GnomeVFSAsyn
 
 		(* state->done_callback) (uri, state->data);
 		/* uri is owned by hashtable, don't free */
-
-		if (state->empty_file != NULL) {
-			unlink (state->empty_file);
-			g_free (state->empty_file);
-		}
 		eel_remove_weak_pointer (&state->parent_view);
 		g_hash_table_destroy (state->debuting_uris);
 		g_free (state);
@@ -2351,61 +2347,48 @@ new_file_transfer_callback (GnomeVFSAsyn
 }
 
 void 
-nautilus_file_operations_new_file (GtkWidget *parent_view, 
-				   const char *parent_dir,
-				   const char *source_uri_text,
-				   NautilusNewFileCallback done_callback,
-				   gpointer data)
+nautilus_file_operations_new_file_from_template (GtkWidget *parent_view, 
+						 const char *parent_dir,
+						 const char *target_filename,
+						 const char *template_uri,
+						 gboolean move_template,
+						 NautilusNewFileCallback done_callback,
+						 gpointer data)
 {
 	GList *target_uri_list;
 	GList *source_uri_list;
 	GnomeVFSURI *target_uri, *parent_uri, *source_uri;
-	char *filename;
+	GnomeVFSXferOptions options;
 	NewFileTransferState *state;
 	SyncTransferInfo *sync_transfer_info;
+	char *tmp;
+
+	g_assert (parent_dir != NULL);
+	g_assert (template_uri != NULL);
 
 	state = g_new (NewFileTransferState, 1);
 	state->done_callback = done_callback;
 	state->data = data;
 	state->parent_view = parent_view;
-	state->empty_file = NULL;
 
 	/* pass in the target directory and the new folder name as a destination URI */
 	parent_uri = gnome_vfs_uri_new (parent_dir);
 
-	if (source_uri_text != NULL) {
-		source_uri = gnome_vfs_uri_new (source_uri_text);
-		if (source_uri == NULL) {
-			(*done_callback) (NULL, data);
-			g_free (state);
-			return;
-		}
-		filename = gnome_vfs_uri_extract_short_path_name (source_uri);
-		target_uri = gnome_vfs_uri_append_string (parent_uri, filename);
-		g_free (filename);
+	source_uri = gnome_vfs_uri_new (template_uri);
+	if (source_uri == NULL) {
+		(*done_callback) (NULL, data);
+		g_free (state);
+		return;
+	}
+
+	if (target_filename != NULL) {
+		target_uri = gnome_vfs_uri_append_file_name (parent_uri, target_filename);
 	} else {
-		char empty_file[] = "/tmp/emptyXXXXXX";
-		char *empty_uri;
-		int fd;
-
-		fd = mkstemp (empty_file);
-		if (fd == -1) {
-			(*done_callback) (NULL, data);
-			g_free (state);
-		}
-		close (fd);
-
-		empty_uri = gnome_vfs_get_uri_from_local_path (empty_file);
-		source_uri = gnome_vfs_uri_new (empty_uri);
-		g_free (empty_uri);
-		
-		state->empty_file = g_strdup (empty_file);
-		
-		filename = g_filename_from_utf8 (_("new file"), -1, NULL, NULL, NULL);
-		target_uri = gnome_vfs_uri_append_file_name (parent_uri, filename);
-		g_free (filename);
+		tmp = gnome_vfs_uri_extract_short_name (source_uri);
+		target_uri = gnome_vfs_uri_append_file_name (parent_uri, tmp);
+		g_free (tmp);
 	}
-	
+
 	state->debuting_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 	eel_add_weak_pointer (&state->parent_view);
 
@@ -2415,9 +2398,14 @@ nautilus_file_operations_new_file (GtkWi
 	sync_transfer_info = g_new (SyncTransferInfo, 1);
 	sync_transfer_info->iterator = NULL;
 	sync_transfer_info->debuting_uris = state->debuting_uris;
-	
+
+	options = GNOME_VFS_XFER_USE_UNIQUE_NAMES;
+	if (move_template) {
+		options |= GNOME_VFS_XFER_REMOVESOURCE;
+	}
+
 	gnome_vfs_async_xfer (&state->handle, source_uri_list, target_uri_list,
-	      		      GNOME_VFS_XFER_USE_UNIQUE_NAMES,
+	      		      options,
 	      		      GNOME_VFS_XFER_ERROR_MODE_QUERY, 
 	      		      GNOME_VFS_XFER_OVERWRITE_MODE_QUERY,
 			      GNOME_VFS_PRIORITY_DEFAULT,
@@ -2427,6 +2415,50 @@ nautilus_file_operations_new_file (GtkWi
 	gnome_vfs_uri_list_free (target_uri_list);
 	gnome_vfs_uri_list_free (source_uri_list);
 	gnome_vfs_uri_unref (parent_uri);
+}
+
+void 
+nautilus_file_operations_new_file (GtkWidget *parent_view, 
+				   const char *parent_dir,
+				   const char *initial_contents,
+				   NautilusNewFileCallback done_callback,
+				   gpointer data)
+{
+	char source_file_str[] = "/tmp/nautilus-sourceXXXXXX";
+	char *source_file_uri;
+	FILE *source_file;
+	char *target_filename;
+	int fd;
+
+	fd = mkstemp (source_file_str);
+	if (fd == -1) {
+		(*done_callback) (NULL, data);
+		return;
+	}
+
+	if (initial_contents != NULL) {
+		source_file = fdopen (fd, "a+");
+
+		fprintf (source_file, "%s", initial_contents);
+		fclose (source_file);
+	}
+
+	close (fd);
+
+	target_filename = g_filename_from_utf8 (_("new file"), -1, NULL, NULL, NULL);
+
+	source_file_uri = gnome_vfs_get_uri_from_local_path (source_file_str);
+
+	nautilus_file_operations_new_file_from_template (parent_view, 
+							 parent_dir,
+							 target_filename,
+							 source_file_uri,
+							 TRUE,
+							 done_callback,
+							 data);
+
+	g_free (source_file_uri);
+	g_free (target_filename);
 }
 
 void 
Index: libnautilus-private/nautilus-file-operations.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations.h,v
retrieving revision 1.19
diff -u -p -r1.19 nautilus-file-operations.h
--- libnautilus-private/nautilus-file-operations.h	12 Dec 2003 17:55:45 -0000	1.19
+++ libnautilus-private/nautilus-file-operations.h	1 Jul 2005 20:37:11 -0000
@@ -27,6 +27,7 @@
 #ifndef NAUTILUS_FILE_OPERATIONS_H
 #define NAUTILUS_FILE_OPERATIONS_H
 
+#include <gdk/gdkdnd.h>
 #include <gtk/gtkwidget.h>
 #include <libgnomevfs/gnome-vfs-types.h>
 
@@ -53,9 +54,17 @@ void nautilus_file_operations_new_folder
 					   gpointer                   done_callback_data);
 void nautilus_file_operations_new_file    (GtkWidget                 *parent_view,
 					   const char                *parent_dir,
-					   const char                *source_uri_text,
+					   const char                *initial_contents,
 					   NautilusNewFileCallback    done_callback,
 					   gpointer                   data);
+void nautilus_file_operations_new_file_from_template (GtkWidget               *parent_view,
+						      const char              *parent_dir,
+						      const char              *target_filename,
+						      const char              *template_uri,
+						      gboolean                 move_template,
+						      NautilusNewFileCallback  done_callback,
+						      gpointer                 data);
+
 void nautilus_file_operations_delete      (const GList               *item_uris,
 					   GtkWidget                 *parent_view);
 
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.389
diff -u -p -r1.389 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	20 Jun 2005 08:58:04 -0000	1.389
+++ libnautilus-private/nautilus-icon-container.c	1 Jul 2005 20:37:14 -0000
@@ -231,6 +231,7 @@ enum {
 	MOVE_COPY_ITEMS,
 	HANDLE_URL,
 	HANDLE_URI_LIST,
+	HANDLE_TEXT,
 	PREVIEW,
 	SELECTION_CHANGED,
 	ICON_ADDED,
@@ -4117,12 +4118,12 @@ nautilus_icon_container_class_init (Naut
 		                G_STRUCT_OFFSET (NautilusIconContainerClass, 
 						 move_copy_items),
 		                NULL, NULL,
-		                nautilus_marshal_VOID__POINTER_POINTER_POINTER_INT_INT_INT,
+		                nautilus_marshal_VOID__POINTER_POINTER_POINTER_ENUM_INT_INT,
 		                G_TYPE_NONE, 6,
 				G_TYPE_POINTER,
 				G_TYPE_POINTER,
 				G_TYPE_POINTER,
-				G_TYPE_INT,
+				GDK_TYPE_DRAG_ACTION,
 				G_TYPE_INT,
 				G_TYPE_INT);
 	signals[HANDLE_URL]
@@ -4132,10 +4133,10 @@ nautilus_icon_container_class_init (Naut
 		                G_STRUCT_OFFSET (NautilusIconContainerClass, 
 						     handle_url),
 		                NULL, NULL,
-		                nautilus_marshal_VOID__STRING_INT_INT_INT,
+		                nautilus_marshal_VOID__STRING_ENUM_INT_INT,
 		                G_TYPE_NONE, 4,
 				G_TYPE_STRING,
-				G_TYPE_INT,
+				GDK_TYPE_DRAG_ACTION,
 				G_TYPE_INT,
 				G_TYPE_INT);
 	signals[HANDLE_URI_LIST] 
@@ -4145,13 +4146,25 @@ nautilus_icon_container_class_init (Naut
 		                G_STRUCT_OFFSET (NautilusIconContainerClass, 
 						     handle_uri_list),
 		                NULL, NULL,
-		                nautilus_marshal_VOID__STRING_INT_INT_INT,
+		                nautilus_marshal_VOID__STRING_ENUM_INT_INT,
 		                G_TYPE_NONE, 4,
 				G_TYPE_STRING,
+				GDK_TYPE_DRAG_ACTION,
 				G_TYPE_INT,
+				G_TYPE_INT);
+	signals[HANDLE_TEXT]
+		= g_signal_new ("handle_text",
+		                G_TYPE_FROM_CLASS (class),
+		                G_SIGNAL_RUN_LAST,
+		                G_STRUCT_OFFSET (NautilusIconContainerClass, 
+						 handle_text),
+		                NULL, NULL,
+		                nautilus_marshal_VOID__STRING_ENUM_INT_INT,
+		                G_TYPE_NONE, 4,
+				G_TYPE_STRING,
+				GDK_TYPE_DRAG_ACTION,
 				G_TYPE_INT,
 				G_TYPE_INT);
-
 	signals[GET_CONTAINER_URI] 
 		= g_signal_new ("get_container_uri",
 		                G_TYPE_FROM_CLASS (class),
Index: libnautilus-private/nautilus-icon-container.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.h,v
retrieving revision 1.86
diff -u -p -r1.86 nautilus-icon-container.h
--- libnautilus-private/nautilus-icon-container.h	2 Jun 2005 10:48:55 -0000	1.86
+++ libnautilus-private/nautilus-icon-container.h	1 Jul 2005 20:37:15 -0000
@@ -97,15 +97,22 @@ typedef struct {
 						   GList *item_uris,
 						   GdkPoint *relative_item_points,
 						   const char *target_uri,
-						   int copy_action,
+						   GdkDragAction action,
 						   int x,
 						   int y);
 	void	     (* handle_url)		  (NautilusIconContainer *container,
 						   char *url,
+						   GdkDragAction action,
 						   int x,
 						   int y);
 	void	     (* handle_uri_list)    	  (NautilusIconContainer *container,
 						   char *uri_list,
+						   GdkDragAction action,
+						   int x,
+						   int y);
+	void	     (* handle_text)		  (NautilusIconContainer *container,
+						   char *text,
+						   GdkDragAction action,
 						   int x,
 						   int y);
 
Index: libnautilus-private/nautilus-icon-dnd.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-dnd.c,v
retrieving revision 1.144
diff -u -p -r1.144 nautilus-icon-dnd.c
--- libnautilus-private/nautilus-icon-dnd.c	15 Jun 2005 18:04:16 -0000	1.144
+++ libnautilus-private/nautilus-icon-dnd.c	1 Jul 2005 20:37:21 -0000
@@ -72,6 +72,7 @@ static const GtkTargetEntry drop_types [
 	{ NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
 	{ NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
 	{ NAUTILUS_ICON_DND_URL_TYPE, 0, NAUTILUS_ICON_DND_URL },
+	{ NAUTILUS_ICON_DND_TEXT_TYPE, 0, NAUTILUS_ICON_DND_TEXT },
 	{ NAUTILUS_ICON_DND_COLOR_TYPE, 0, NAUTILUS_ICON_DND_COLOR },
 	{ NAUTILUS_ICON_DND_BGIMAGE_TYPE, 0, NAUTILUS_ICON_DND_BGIMAGE },
 	{ NAUTILUS_ICON_DND_KEYWORD_TYPE, 0, NAUTILUS_ICON_DND_KEYWORD },
@@ -643,6 +644,20 @@ receive_dropped_uri_list (NautilusIconCo
 				 x, y);
 }
 
+/* handle dropped text */
+static void
+receive_dropped_text (NautilusIconContainer *container, const char *text, GdkDragAction action, int x, int y)
+{	
+	if (text == NULL) {
+		return;
+	}
+	
+	g_signal_emit_by_name (container, "handle_text",
+			       text,
+			       action,
+			       x, y);
+}
+
 static int
 auto_scroll_timeout_callback (gpointer data)
 {
@@ -1131,6 +1146,7 @@ nautilus_icon_container_get_drop_action 
 		break;
 
 	case NAUTILUS_ICON_DND_TEXT:
+		*action = GDK_ACTION_COPY;
 		break;
 	}
 }
@@ -1551,6 +1567,7 @@ drag_data_received_callback (GtkWidget *
 {
     	NautilusDragInfo *drag_info;
 	EelBackground *background;
+	char *tmp;
 	gboolean success;
 
 	drag_info = &(NAUTILUS_ICON_CONTAINER (widget)->details->dnd_info->drag_info);
@@ -1566,6 +1583,7 @@ drag_data_received_callback (GtkWidget *
 	case NAUTILUS_ICON_DND_BGIMAGE:	
 	case NAUTILUS_ICON_DND_KEYWORD:
 	case NAUTILUS_ICON_DND_URI_LIST:
+	case NAUTILUS_ICON_DND_TEXT:
 	case NAUTILUS_ICON_DND_RESET_BACKGROUND:
 		/* Save the data so we can do the actual work on drop. */
 		if (drag_info->selection_data != NULL) {
@@ -1627,6 +1645,14 @@ drag_data_received_callback (GtkWidget *
 				(NAUTILUS_ICON_CONTAINER (widget),
 				 (char *) data->data, context->action, x, y);
 			success = TRUE;
+			break;
+		case NAUTILUS_ICON_DND_TEXT:
+			tmp = gtk_selection_data_get_text (data);
+			receive_dropped_text
+				(NAUTILUS_ICON_CONTAINER (widget),
+				 (char *) tmp, context->action, x, y);
+			success = TRUE;
+			g_free (tmp);
 			break;
 		case NAUTILUS_ICON_DND_RESET_BACKGROUND:
 			background = eel_get_widget_background (widget);
Index: libnautilus-private/nautilus-marshal.list
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-marshal.list,v
retrieving revision 1.8
diff -u -p -r1.8 nautilus-marshal.list
--- libnautilus-private/nautilus-marshal.list	13 Jan 2005 13:27:51 -0000	1.8
+++ libnautilus-private/nautilus-marshal.list	1 Jul 2005 20:37:21 -0000
@@ -6,11 +6,11 @@ INT:POINTER,BOOLEAN
 INT:POINTER,POINTER
 POINTER:VOID
 VOID:DOUBLE
-VOID:STRING,INT,INT,INT
+VOID:STRING,ENUM,INT,INT
 VOID:POINTER,POINTER
 VOID:POINTER,POINTER
 VOID:POINTER,STRING
+VOID:POINTER,STRING,ENUM,INT,INT
 VOID:STRING,STRING
-VOID:POINTER,POINTER,POINTER,INT,INT,INT
-VOID:POINTER,STRING,UINT,INT,INT
+VOID:POINTER,POINTER,POINTER,ENUM,INT,INT
 VOID:POINTER,ENUM
Index: libnautilus-private/nautilus-tree-view-drag-dest.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-tree-view-drag-dest.c,v
retrieving revision 1.9
diff -u -p -r1.9 nautilus-tree-view-drag-dest.c
--- libnautilus-private/nautilus-tree-view-drag-dest.c	16 Jun 2005 13:43:10 -0000	1.9
+++ libnautilus-private/nautilus-tree-view-drag-dest.c	1 Jul 2005 20:37:21 -0000
@@ -65,6 +65,7 @@ enum {
 	MOVE_COPY_ITEMS,
 	HANDLE_URL,
 	HANDLE_URI_LIST,
+	HANDLE_TEXT,
 	LAST_SIGNAL
 };
 
@@ -80,7 +81,8 @@ GNOME_CLASS_BOILERPLATE (NautilusTreeVie
 static const GtkTargetEntry drag_types [] = {
 	{ NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
 	{ NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
-	{ NAUTILUS_ICON_DND_URL_TYPE, 0, NAUTILUS_ICON_DND_URL }
+	{ NAUTILUS_ICON_DND_URL_TYPE, 0, NAUTILUS_ICON_DND_URL },
+	{ NAUTILUS_ICON_DND_TEXT_TYPE, 0, NAUTILUS_ICON_DND_TEXT }
 	/* FIXME: Should handle emblems once the list view supports them */
 };
 
@@ -384,6 +386,17 @@ get_drop_action (NautilusTreeViewDragDes
 		
 	case NAUTILUS_ICON_DND_URI_LIST :
 		return context->suggested_action;
+
+	case NAUTILUS_ICON_DND_TEXT:
+		drop_target = get_drop_target (dest, path);
+
+		if (!drop_target) {
+			return 0;
+		}
+
+		g_free (drop_target);
+
+		return GDK_ACTION_COPY;
 	}
 
 	return 0;
@@ -580,6 +593,26 @@ receive_dropped_uri_list (NautilusTreeVi
 }
 
 static void
+receive_dropped_text (NautilusTreeViewDragDest *dest,
+		      GdkDragContext *context,
+		      int x, int y)
+{
+	char *text;
+
+	if (!dest->details->drag_data) {
+		return;
+	}
+
+	text = gtk_selection_data_get_text (dest->details->drag_data);
+	g_signal_emit (dest, signals[HANDLE_TEXT], 0,
+		       (char *) text,
+		       context->action,
+		       x, y);
+	g_free (text);
+}
+
+
+static void
 receive_dropped_url (NautilusTreeViewDragDest *dest,
 		     GdkDragContext *context,
 		     int x, int y)
@@ -620,6 +653,8 @@ drag_data_received_callback (GtkWidget *
 		}
 	}
 
+	g_warning ("teest: %s", gtk_selection_data_get_text (selection_data));
+
 	if (dest->details->drop_occurred) {
 		success = FALSE;
 		switch (info) {
@@ -635,6 +670,10 @@ drag_data_received_callback (GtkWidget *
 			receive_dropped_uri_list (dest, context, x, y);
 			success = TRUE;
 			break;
+		case NAUTILUS_ICON_DND_TEXT:
+			receive_dropped_text (dest, context, x, y);
+			success = TRUE;
+			break;
 		}
 
 		dest->details->drop_occurred = FALSE;
@@ -762,11 +801,11 @@ nautilus_tree_view_drag_dest_class_init 
 					       move_copy_items),
 			      NULL, NULL,
 			      
-			      nautilus_marshal_VOID__POINTER_STRING_UINT_INT_INT,
+			      nautilus_marshal_VOID__POINTER_STRING_ENUM_INT_INT,
 			      G_TYPE_NONE, 5,
 			      G_TYPE_POINTER,
 			      G_TYPE_STRING,
-			      G_TYPE_UINT,
+			      GDK_TYPE_DRAG_ACTION,
 			      G_TYPE_INT,
 			      G_TYPE_INT);
 	signals[HANDLE_URL] =
@@ -776,10 +815,10 @@ nautilus_tree_view_drag_dest_class_init 
 			      G_STRUCT_OFFSET (NautilusTreeViewDragDestClass, 
 					       handle_url),
 			      NULL, NULL,
-			      nautilus_marshal_VOID__STRING_INT_INT_INT,
+			      nautilus_marshal_VOID__STRING_ENUM_INT_INT,
 			      G_TYPE_NONE, 4,
 			      G_TYPE_STRING,
-			      G_TYPE_INT,
+			      GDK_TYPE_DRAG_ACTION,
 			      G_TYPE_INT,
 			      G_TYPE_INT);
 	signals[HANDLE_URI_LIST] =
@@ -789,10 +828,23 @@ nautilus_tree_view_drag_dest_class_init 
 			      G_STRUCT_OFFSET (NautilusTreeViewDragDestClass, 
 					       handle_uri_list),
 			      NULL, NULL,
-			      nautilus_marshal_VOID__STRING_INT_INT_INT,
+			      nautilus_marshal_VOID__STRING_ENUM_INT_INT,
 			      G_TYPE_NONE, 4,
 			      G_TYPE_STRING,
+			      GDK_TYPE_DRAG_ACTION,
 			      G_TYPE_INT,
+			      G_TYPE_INT);
+	signals[HANDLE_TEXT] =
+		g_signal_new ("handle_text",
+			      G_TYPE_FROM_CLASS (class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (NautilusTreeViewDragDestClass, 
+					       handle_text),
+			      NULL, NULL,
+			      nautilus_marshal_VOID__STRING_ENUM_INT_INT,
+			      G_TYPE_NONE, 4,
+			      G_TYPE_STRING,
+			      GDK_TYPE_DRAG_ACTION,
 			      G_TYPE_INT,
 			      G_TYPE_INT);
 }
Index: libnautilus-private/nautilus-tree-view-drag-dest.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-tree-view-drag-dest.h,v
retrieving revision 1.2
diff -u -p -r1.2 nautilus-tree-view-drag-dest.h
--- libnautilus-private/nautilus-tree-view-drag-dest.h	13 Jan 2005 13:27:51 -0000	1.2
+++ libnautilus-private/nautilus-tree-view-drag-dest.h	1 Jul 2005 20:37:21 -0000
@@ -61,15 +61,22 @@ struct _NautilusTreeViewDragDestClass {
 	void (*move_copy_items) (NautilusTreeViewDragDest *dest,
 				 const GList *item_uris,
 				 const char *target_uri,
-				 guint action,
+				 GdkDragAction action,
 				 int x,
 				 int y);
 	void (* handle_url)     (NautilusTreeViewDragDest *dest,
 				 char *url,
+				 GdkDragAction action,
 				 int x,
 				 int y);
 	void (* handle_uri_list) (NautilusTreeViewDragDest *dest,
 				  char *uri_list,
+				  GdkDragAction action,
+				  int x,
+				  int y);
+	void (* handle_text)    (NautilusTreeViewDragDest *dest,
+				  char *text,
+				  GdkDragAction action,
 				  int x,
 				  int y);
 };
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.698
diff -u -p -r1.698 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	1 Jul 2005 10:30:33 -0000	1.698
+++ src/file-manager/fm-directory-view.c	1 Jul 2005 20:37:25 -0000
@@ -1,5 +1,4 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ 
 /* fm-directory-view.c
  *
  * Copyright (C) 1999, 2000  Free Software Foundation
@@ -3677,12 +3676,9 @@ fm_directory_view_new_folder (FMDirector
 	g_free (parent_uri);
 }
 
-void
-fm_directory_view_new_file (FMDirectoryView *directory_view,
-			    NautilusFile *source)
+static NewFolderData *
+setup_new_folder_data (FMDirectoryView *directory_view)
 {
-	char *parent_uri;
-	char *source_uri;
 	NewFolderData *data;
 
 	data = new_folder_data_new (directory_view);
@@ -3694,20 +3690,58 @@ fm_directory_view_new_file (FMDirectoryV
 			       (GClosureNotify)NULL,
 			       G_CONNECT_AFTER);
 
-	
-	source_uri = NULL;
-	if (source != NULL) {
-		source_uri = nautilus_file_get_uri (source);
-	}
+	return data;
+}
+
+static void
+fm_directory_view_new_file_with_initial_contents (FMDirectoryView *directory_view,
+						  const char *initial_contents)
+{
+	NewFolderData *data;
+	char *parent_uri;
+
+	data = setup_new_folder_data (directory_view);
+
 	parent_uri = fm_directory_view_get_backing_uri (directory_view);
+
 	nautilus_file_operations_new_file (GTK_WIDGET (directory_view),
 					   parent_uri,
-					   source_uri,
+					   initial_contents,
 					   new_folder_done, data);
+
 	g_free (parent_uri);
-	g_free (source_uri);
 }
 
+void
+fm_directory_view_new_file (FMDirectoryView *directory_view,
+			    NautilusFile *source)
+{
+	NewFolderData *data;
+	char *parent_uri;
+	char *source_uri;
+
+	if (source == NULL) {
+		fm_directory_view_new_file_with_initial_contents (directory_view, NULL);
+		return;
+	}
+
+	g_return_if_fail (nautilus_file_is_local (source));
+
+	data = setup_new_folder_data (directory_view);
+
+	source_uri = nautilus_file_get_uri (source);
+	parent_uri = fm_directory_view_get_backing_uri (directory_view);
+
+	nautilus_file_operations_new_file_from_template (GTK_WIDGET (directory_view),
+							 parent_uri,
+							 NULL,
+							 source_uri,
+							 FALSE,
+							 new_folder_done, data);
+
+	g_free (parent_uri);
+	g_free (source_uri);
+}
 
 /* handle the open command */
 
@@ -8558,6 +8592,31 @@ fm_directory_view_handle_uri_list_drop (
 
 	g_free (container_uri);
 }
+
+void
+fm_directory_view_handle_text_drop (FMDirectoryView  *view,
+				    const char       *text,
+				    GdkDragAction     action,
+				    int               x,
+				    int               y)
+{
+	char *container_uri;
+
+	if (text == NULL) {
+		return;
+	}
+
+	g_return_if_fail (action == GDK_ACTION_COPY);
+
+	container_uri = fm_directory_view_get_backing_uri (view);
+	g_return_if_fail (container_uri != NULL);
+
+	fm_directory_view_new_file_with_initial_contents (
+		view, text);
+
+	g_free (container_uri);
+}
+
 
 static void
 real_sort_files (FMDirectoryView *view, GList **files)
Index: src/file-manager/fm-directory-view.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.h,v
retrieving revision 1.140
diff -u -p -r1.140 fm-directory-view.h
--- src/file-manager/fm-directory-view.h	16 Jun 2005 08:40:47 -0000	1.140
+++ src/file-manager/fm-directory-view.h	1 Jul 2005 20:37:26 -0000
@@ -400,6 +400,11 @@ void                fm_directory_view_ha
 									GdkDragAction     action,
 									int               x,
 									int               y);
+void                fm_directory_view_handle_text_drop                 (FMDirectoryView  *view,
+									const char       *text,
+									GdkDragAction     action,
+									int               x,
+									int               y);
 void                fm_directory_view_freeze_updates                   (FMDirectoryView  *view);
 void                fm_directory_view_unfreeze_updates                 (FMDirectoryView  *view);
 void                fm_directory_view_add_subdirectory                (FMDirectoryView  *view,
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.310
diff -u -p -r1.310 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	16 Jun 2005 08:40:47 -0000	1.310
+++ src/file-manager/fm-icon-view.c	1 Jul 2005 20:37:27 -0000
@@ -2477,6 +2477,14 @@ icon_view_handle_uri_list (NautilusIconC
 						item_uris, action, x, y);
 }
 
+static void
+icon_view_handle_text (NautilusIconContainer *container, const char *text,
+		       GdkDragAction action, int x, int y, FMIconView *view)
+{
+	fm_directory_view_handle_text_drop (FM_DIRECTORY_VIEW (view),
+					    text, action, x, y);
+}
+
 static char *
 icon_view_get_first_visible_file (NautilusView *view)
 {
@@ -2643,6 +2651,8 @@ fm_icon_view_init (FMIconView *icon_view
 				 G_CALLBACK (icon_view_handle_url), icon_view, 0);
 	g_signal_connect_object (get_icon_container (icon_view), "handle_uri_list",
 				 G_CALLBACK (icon_view_handle_uri_list), icon_view, 0);
+	g_signal_connect_object (get_icon_container (icon_view), "handle_text",
+				 G_CALLBACK (icon_view_handle_text), icon_view, 0);
 }
 
 static NautilusView *
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.250
diff -u -p -r1.250 fm-list-view.c
--- src/file-manager/fm-list-view.c	20 Jun 2005 10:12:38 -0000	1.250
+++ src/file-manager/fm-list-view.c	1 Jul 2005 20:37:29 -0000
@@ -1071,6 +1071,13 @@ list_view_handle_uri_list (NautilusTreeV
 						item_uris, action, x, y);
 }
 
+static void
+list_view_handle_text (NautilusTreeViewDragDest *dest, const char *text,
+		       GdkDragAction action, int x, int y, FMListView *view)
+{
+	fm_directory_view_handle_text_drop (FM_DIRECTORY_VIEW (view),
+					    text, action, x, y);
+}
 
 static void
 move_copy_items_callback (NautilusTreeViewDragDest *dest,
@@ -1187,6 +1194,8 @@ create_and_set_up_tree_view (FMListView 
 				 G_CALLBACK (list_view_handle_url), view, 0);
 	g_signal_connect_object (view->details->drag_dest, "handle_uri_list",
 				 G_CALLBACK (list_view_handle_uri_list), view, 0);
+	g_signal_connect_object (view->details->drag_dest, "handle_text",
+				 G_CALLBACK (list_view_handle_text), view, 0);
 
 	g_signal_connect_object (gtk_tree_view_get_selection (view->details->tree_view),
 				 "changed",
Index: src/file-manager/fm-tree-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-tree-view.c,v
retrieving revision 1.14
diff -u -p -r1.14 fm-tree-view.c
--- src/file-manager/fm-tree-view.c	1 Jul 2005 14:13:49 -0000	1.14
+++ src/file-manager/fm-tree-view.c	1 Jul 2005 20:37:29 -0000
@@ -547,7 +547,7 @@ static void
 move_copy_items_callback (NautilusTreeViewDragDest *dest,
 			  const GList *item_uris,
 			  const char *target_uri,
-			  guint action,
+			  GdkDragAction action,
 			  int x,
 			  int y,
 			  gpointer user_data)

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



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