Re: [PATCH] Context-sensitive paste



On Fri, 31 May 2002 10:10:18 +0200, I wrote:

> The current context-insensitive "Paste file" menu item should be
> renamed to "Paste here" (as short for "Paste in the current location")
> and put somewhere farther in the context menu, beyond a new separator,
> surely not where it is now. It would always do the same thing (that
> is, what nautilus does right now) and would be always enabled, at
> least as far as there's something to paste sitting in the clipboard.

(I forgot that there's always the case in which the directory view is
read only, which obviously disables pasting in the current location.)

So, I think that the "Paste Files Here" menu item would have to belong
to both the Edit menu and the background popup, but not to the
selection popup.

I've modified the patch to implement the "Paste Files Here"
[Shift+Ctrl+V] and the "Paste Files Into Object" [Ctrl+V] (which,
albeit longer, is clearer than "Paste Into" or etc.).

However, as far as the Edit menu is concerned, while "Paste Files Into
Object" took the place of the old paste item, I couldn't manage to
make the newly-added "Paste Files Here" item appear anywhere but at
the bottom of the menu ... changing its position in the .xml
definition does not seem to work. Suggestions ? You surely know how to
fix this. (It must be simple but I can't figure it :-< ...)

I hope that the new patch is ok otherwise.

Bye and thank you for your patience, I hope I'm not stressing you too
much :).

-- 
Marcello Raffa
mrooth @ tiscalinet.it
diff -pru nautilus-1.1.18.orig/src/file-manager/fm-directory-view.c nautilus-1.1.18/src/file-manager/fm-directory-view.c
--- nautilus-1.1.18.orig/src/file-manager/fm-directory-view.c	Sat May 25 20:36:32 2002
+++ nautilus-1.1.18/src/file-manager/fm-directory-view.c	Fri May 31 17:39:13 2002
@@ -121,7 +121,8 @@
 #define FM_DIRECTORY_VIEW_COMMAND_OTHER_VIEWER	   			"/commands/OtherViewer"
 #define FM_DIRECTORY_VIEW_COMMAND_CUT_FILES	    			"/commands/Cut Files"
 #define FM_DIRECTORY_VIEW_COMMAND_COPY_FILES				"/commands/Copy Files"
-#define FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES	   			"/commands/Paste Files"
+#define FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_INTO_OBJECT  		"/commands/Paste Files Into Object"
+#define FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_HERE   			"/commands/Paste Files Here"
 
 #define FM_DIRECTORY_VIEW_MENU_PATH_OPEN_ALTERNATE        		"/menu/File/Open Placeholder/OpenAlternate"
 #define FM_DIRECTORY_VIEW_MENU_PATH_OPEN_WITH				"/menu/File/Open Placeholder/Open With"
@@ -4078,9 +4079,54 @@ convert_lines_to_str_list (char **lines,
 }
 
 static void
-clipboard_received_callback (GtkClipboard     *clipboard,
-			     GtkSelectionData *selection_data,
-			     gpointer          data)
+clipboard_received_into_object_callback (GtkClipboard     *clipboard,
+					 GtkSelectionData *selection_data,
+					 gpointer          data)
+{
+	FMDirectoryView *view;
+	char **lines;
+	gboolean cut;
+	GList *item_uris, *current_selection;
+	char *destination_uri;
+	NautilusFile *file;
+
+	view = FM_DIRECTORY_VIEW (data);
+	
+	if (selection_data->type != copied_files_atom
+	    || selection_data->length <= 0) {
+		item_uris = NULL;
+	} else {
+		/* Not sure why it's legal to assume there's an extra byte
+		 * past the end of the selection data that it's safe to write
+		 * to. But gtk_editable_selection_received does this, so I
+		 * think it is OK.
+		 */
+		selection_data->data[selection_data->length] = '\0';
+		lines = g_strsplit (selection_data->data, "\n", 0);
+		item_uris = convert_lines_to_str_list (lines, &cut);
+		g_strfreev (lines);
+	}
+
+	current_selection = fm_directory_view_get_selection (view);
+
+	file = NAUTILUS_FILE (current_selection->data);
+	destination_uri = nautilus_file_get_uri (file);
+
+	if (item_uris == NULL|| destination_uri == NULL) {
+		nautilus_view_report_status (view->details->nautilus_view,
+					     _("There is nothing on the clipboard to paste."));
+	} else {
+		fm_directory_view_move_copy_items (item_uris, NULL, destination_uri,
+						   cut ? GDK_ACTION_MOVE : GDK_ACTION_COPY,
+						   0, 0,
+						   view);
+	}
+}
+
+static void
+clipboard_received_here_callback (GtkClipboard     *clipboard,
+				  GtkSelectionData *selection_data,
+				  gpointer          data)
 {
 	FMDirectoryView *view;
 	char **lines;
@@ -4119,13 +4165,24 @@ clipboard_received_callback (GtkClipboar
 }
 
 static void
-paste_files_callback (BonoboUIComponent *component,
-		      gpointer callback_data,
-		      const char *verb)
+paste_files_into_object_callback (BonoboUIComponent *component,
+				  gpointer callback_data,
+				  const char *verb)
 {
 	gtk_clipboard_request_contents (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
 					copied_files_atom,
-					clipboard_received_callback,
+					clipboard_received_into_object_callback,
+					callback_data);
+}
+
+static void
+paste_files_here_callback (BonoboUIComponent *component,
+			   gpointer callback_data,
+			   const char *verb)
+{
+	gtk_clipboard_request_contents (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
+					copied_files_atom,
+					clipboard_received_here_callback,
 					callback_data);
 }
 
@@ -4163,7 +4220,8 @@ real_merge_menus (FMDirectoryView *view)
 		BONOBO_UI_VERB ("OpenAlternate", open_alternate_callback),
 		BONOBO_UI_VERB ("OtherApplication", other_application_callback),
 		BONOBO_UI_VERB ("OtherViewer", other_viewer_callback),
-		BONOBO_UI_VERB ("Paste Files", paste_files_callback),
+		BONOBO_UI_VERB ("Paste Files Into Object", paste_files_into_object_callback),
+		BONOBO_UI_VERB ("Paste Files Here", paste_files_here_callback),
 		BONOBO_UI_VERB ("Remove Custom Icons", remove_custom_icons_callback),
 		BONOBO_UI_VERB ("Reset Background", reset_background_callback),
 		BONOBO_UI_VERB ("Reset to Defaults", reset_to_defaults_callback),
@@ -4205,6 +4263,8 @@ clipboard_targets_received (GtkClipboard
 	GdkAtom *targets;
 	int n_targets;
 	int i;
+	GList *current_selection;
+	gboolean can_paste_into_object;
 
 	view = FM_DIRECTORY_VIEW (user_data);
 	can_paste = FALSE;
@@ -4218,11 +4278,26 @@ clipboard_targets_received (GtkClipboard
 
 		g_free (targets);
 	}
+	
+	can_paste_into_object = FALSE;
+	current_selection = fm_directory_view_get_selection (view);
+
+	if (eel_g_list_exactly_one_item (current_selection)) {
+		NautilusFile *file = NAUTILUS_FILE (current_selection->data);
+
+		if (nautilus_file_is_directory (file))
+			can_paste_into_object = TRUE;
+	}
 
-	if (view->details->ui != NULL)
+	if (view->details->ui != NULL) {
 		nautilus_bonobo_set_sensitive (view->details->ui,
-					       FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES,
+					       FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_INTO_OBJECT,
+					       can_paste && can_paste_into_object);
+		nautilus_bonobo_set_sensitive (view->details->ui,
+					       FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_HERE,
 					       can_paste);
+	}
+
 	g_object_unref (view);
 }
 
@@ -4426,7 +4501,7 @@ real_update_menus (FMDirectoryView *view
 
 	if (is_read_only) {
 		nautilus_bonobo_set_sensitive (view->details->ui,
-					       FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES,
+					       FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES_HERE,
 					       FALSE);
 	} else {
 		/* Ask the clipboard */
diff -pru nautilus-1.1.18.orig/src/file-manager/nautilus-directory-view-ui.xml nautilus-1.1.18/src/file-manager/nautilus-directory-view-ui.xml
--- nautilus-1.1.18.orig/src/file-manager/nautilus-directory-view-ui.xml	Thu May  9 01:20:16 2002
+++ nautilus-1.1.18/src/file-manager/nautilus-directory-view-ui.xml	Fri May 31 17:03:46 2002
@@ -48,9 +48,12 @@
 	<cmd name="Copy Files"
          _label="Copy Files"
 	 _tip="Prepare the selected files to be copied with a Paste Files command"/>
-	<cmd name="Paste Files"
-         _label="Paste Files"
-	 _tip="Move or copy files previously selected by a Cut Files or Copy Files command"/>
+	<cmd name="Paste Files Into Object"
+	 _label="Paste Files Into Object"
+	 _tip="Move or copy files previously selected by a Cut Files or Copy Files command into the currently selected object"/>
+	<cmd name="Paste Files Here"
+         _label="Paste Files Here"
+	 _tip="Move or copy files previously selected by a Cut Files or Copy Files command in the current location"/>
 	<cmd name="Select All"
          _label="Select All Files"
 	 _tip="Select all items in this window"/>
@@ -166,10 +169,17 @@
 			  pixtype="stock" pixname="gtk-copy"
 			  verb="Copy Files"/>
 		<menuitem name="Paste"
-			  _label="_Paste Files"
+		          _label="P_aste Files Into Object"
 			  accel="*Control*v"
 			  pixtype="stock" pixname="gtk-paste"
-			  verb="Paste Files"/>
+			  verb="Paste Files Into Object"/>
+		<separator/>
+		<menuitem name="Paste Files Here"
+		          _label="_Paste Files Here"
+			  accel="*Shift**Control*v"
+			  pixtype="stock" pixname="gtk-paste"
+			  verb="Paste Files Here"/>
+		<separator/>
 		<menuitem name="Select All"
 			  _label="Select _All Files"
 			  accel="*Control*a"
@@ -213,9 +223,13 @@
 				<menuitem name="Copy Files" 
 				 pixtype="stock" pixname="gtk-copy"
 				 verb="Copy Files"/>
-				<menuitem name="Paste Files" 
+				<menuitem name="Paste Files Into Object"
+				 pixtype="stock" pixname="gtk-paste"
+				 verb="Paste Files Into Object"/>
+				<separator/>
+				<menuitem name="Paste Files Here"
 				 pixtype="stock" pixname="gtk-paste"
-				 verb="Paste Files"/>
+				 verb="Paste Files Here"/>
 			</placeholder>
 		</placeholder>
 		<placeholder name="After Zoom Items">
@@ -271,9 +285,9 @@
 			<menuitem name="Copy Files" 
 			 pixtype="stock" pixname="gtk-copy"
 			 verb="Copy Files"/>
-			<menuitem name="Paste Files" 
+			<menuitem name="Paste Files Into Object"
 			 pixtype="stock" pixname="gtk-paste"
-			 verb="Paste Files"/>
+			 verb="Paste Files Into Object"/>
 		</placeholder>
 		<placeholder name="Icon Appearance Items" delimit="top">
 			<menuitem name="Remove Custom Icons" verb="Remove Custom Icons"/>


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