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



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.

> Why did you change the general code to take filenames instead of uris?

Good question. I was sure that templates will be only stored on the
local disk, ignoring that we have to pass URIs to GnomeVFS anyway.

> +                                                GdkDragAction copy_action,
> 
> don't pass dnd enum stuff in here. Just take a boolean.

ok. I just wanted to ensure NautilusFileOperations consistency. But this
was obviously an irrelevant consideration here.

> +			      NULL, NULL,
> +			      nautilus_marshal_VOID__STRING_INT_INT_INT,
> +			      G_TYPE_NONE, 4,
> +			      G_TYPE_STRING,
> +			      G_TYPE_INT,
> +			      G_TYPE_INT,
> +			      G_TYPE_INT);
> 
> This looks wrong. There is only two int args. The others seem wrong too.

Right, I've fixed the marshallers to take a GDK_TYPE_ACTION as the first
element of the action/x/y triple.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-file-operations.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations.c,v
retrieving revision 1.189
diff -u -p -r1.189 nautilus-file-operations.c
--- libnautilus-private/nautilus-file-operations.c	17 Jun 2005 10:50:26 -0000	1.189
+++ libnautilus-private/nautilus-file-operations.c	23 Jun 2005 20:05:07 -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,7 @@ typedef struct {
 	NautilusNewFileCallback done_callback;
 	gpointer data;
 	GtkWidget *parent_view;
-	char *empty_file;
+	gboolean move_source_file;
 	GHashTable *debuting_uris;
 } NewFileTransferState;
 
@@ -2298,11 +2300,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 +2348,49 @@ 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;
 
+	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;
+	}
+
+	state->move_source_file = move_template;
+
+	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);
+		target_filename = gnome_vfs_uri_extract_short_name (source_uri);
+		target_uri = gnome_vfs_uri_append_file_name (parent_uri, target_filename);
+		g_free ((char *) target_filename);
 	}
-	
+
 	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 +2400,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 +2417,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	23 Jun 2005 20:05:07 -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	23 Jun 2005 20:05:10 -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	23 Jun 2005 20:05:10 -0000
@@ -108,6 +108,10 @@ typedef struct {
 						   char *uri_list,
 						   int x,
 						   int y);
+	void	     (* handle_text)		  (NautilusIconContainer *container,
+						   char *text,
+						   int x,
+						   int y);
 
 	/* Queries on the container for subclass/client.
 	 * These must be implemented. The default "do nothing" is not good enough.
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	23 Jun 2005 20:05:11 -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;
 	}
 }
@@ -1566,6 +1582,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) {
@@ -1624,6 +1641,12 @@ drag_data_received_callback (GtkWidget *
 			break;
 		case NAUTILUS_ICON_DND_URI_LIST:
 			receive_dropped_uri_list
+				(NAUTILUS_ICON_CONTAINER (widget),
+				 (char *) data->data, context->action, x, y);
+			success = TRUE;
+			break;
+		case NAUTILUS_ICON_DND_TEXT:
+			receive_dropped_text
 				(NAUTILUS_ICON_CONTAINER (widget),
 				 (char *) data->data, context->action, x, y);
 			success = TRUE;
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	23 Jun 2005 20:05:11 -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	23 Jun 2005 20:05:11 -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,22 @@ receive_dropped_uri_list (NautilusTreeVi
 }
 
 static void
+receive_dropped_text (NautilusTreeViewDragDest *dest,
+		      GdkDragContext *context,
+		      int x, int y)
+{
+	if (!dest->details->drag_data) {
+		return;
+	}
+
+	g_signal_emit (dest, signals[HANDLE_TEXT], 0,
+		       (char*)dest->details->drag_data->data,
+		       context->action,
+		       x, y);
+}
+
+
+static void
 receive_dropped_url (NautilusTreeViewDragDest *dest,
 		     GdkDragContext *context,
 		     int x, int y)
@@ -635,6 +664,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 +795,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 +809,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 +822,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	23 Jun 2005 20:05:11 -0000
@@ -72,6 +72,10 @@ struct _NautilusTreeViewDragDestClass {
 				  char *uri_list,
 				  int x,
 				  int y);
+	void (* handle_text)    (NautilusTreeViewDragDest *dest,
+				  char *text,
+				  int x,
+				  int y);
 };
 
 GType                     nautilus_tree_view_drag_dest_get_type (void);
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.696
diff -u -p -r1.696 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	20 Jun 2005 14:36:19 -0000	1.696
+++ src/file-manager/fm-directory-view.c	23 Jun 2005 20:05:14 -0000
@@ -3675,12 +3675,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);
@@ -3692,20 +3689,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 */
 
@@ -8529,6 +8564,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	23 Jun 2005 20:05:15 -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	23 Jun 2005 20:05:16 -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	23 Jun 2005 20:05:17 -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.12
diff -u -p -r1.12 fm-tree-view.c
--- src/file-manager/fm-tree-view.c	20 Jun 2005 08:43:46 -0000	1.12
+++ src/file-manager/fm-tree-view.c	23 Jun 2005 20:05:17 -0000
@@ -545,7 +545,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)


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