[PATCH] Context-sensitive paste



Hello,

Currently when the user selects the "Paste file"/"Paste files" item of
the icon view context menu, the clipboard contents are moved/copied in
the current view, regardless of what is the current selection and
*where* in the view workspace the user is actually right-clicking to
open the context menu.

I think that this behaviour should be corrected to make it
context-sensitive (see also bug #47946). I've made a small patch
against nautilus-1.1.18 to fm-directory-view.c which makes nautilus
behave in the following way (and, I hope, break nothing else):

1) when the current selection involves more than one object, the paste
menu item is accordingly disabled in clipboard_targets_received, since
we can't assign a meaning to trying to paste to more than one
destination at once

2) when the current selection involves only one object, then pick its
uri as the destination for the move/copy action and set the paste menu
item label to "Paste Into" (not sure if "Paste Inside" would be
better; in bug #76952 "Paste Here" is suggested, but see below); note
that clipboard_targets_received again disables the paste menu item if
the selected object is not a directory

3) when the current selection is empty, assume that the user wants to
move/copy the clipboard contents in the current location (which is
what nautilus is always doing right now) and set the paste menu item
label to "Paste Here"

4) the patch also makes a one-line addition in fm-icon-view.c, to
empty the current selection when the user right-clicks on the
background of the view workspace instead of right-clicking on one of
the currently selected objects; this is not strictly needed, but I
think it's more intuitive and click-saving (right now pasting in the
current location requires two clicks if the selection is not empty)

I hope that the patch is good. I've been using it for a few days and
it seems to be ok.

Anyways, even if the patch completely sucks, I would be glad to know
what you think about the issue, and what are your plans about it. I
find the current pasting behaviour very unintuitive and unnecessarily
time-wasting.

Have a good day,
and thank you for nautilus ! :)

-- 
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	Wed May 29 20:50:00 2002
@@ -4085,8 +4085,8 @@ clipboard_received_callback (GtkClipboar
 	FMDirectoryView *view;
 	char **lines;
 	gboolean cut;
-	GList *item_uris;
-	char *view_uri;
+	GList *item_uris, *current_selection;
+	char *destination_uri;
 
 	view = FM_DIRECTORY_VIEW (data);
 	
@@ -4105,13 +4105,41 @@ clipboard_received_callback (GtkClipboar
 		g_strfreev (lines);
 	}
 
-	view_uri = fm_directory_view_get_uri (view);
+	/* Get current view objects selection; if no objects are currently
+	   selected then pick the current view uri as destination; otherwise,
+	   pick the uri of the selected object as destination.
+
+	   NOTE: When the current selection involves more than one object,
+	         pasting is disabled by means of UI in clipboard_targets_received.
+		 Thus we can only get this far if either selection is empty or
+		 it involves only one object.
+	 */
+	current_selection = fm_directory_view_get_selection (view);
 
-	if (item_uris == NULL|| view_uri == NULL) {
+	if (current_selection == NULL) {
+		destination_uri = fm_directory_view_get_uri (view) ;
+	} else {
+		NautilusFile *selected_object;
+		
+		selected_object = NAUTILUS_FILE (current_selection->data);
+
+		/* Modeled after fm-icon-view.c:get_icon_drop_target_uri_callback,
+		   which carries a FIXME bugzilla.gnome.org 43020.
+		 */
+		if (nautilus_file_is_nautilus_link (selected_object) &&
+		    nautilus_file_is_local (selected_object)
+		)
+			destination_uri = nautilus_link_local_get_link_uri
+			    (nautilus_file_get_uri (selected_object));
+		else
+			destination_uri = nautilus_file_get_uri (selected_object);
+	}
+
+	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, view_uri,
+		fm_directory_view_move_copy_items (item_uris, NULL, destination_uri,
 						   cut ? GDK_ACTION_MOVE : GDK_ACTION_COPY,
 						   0, 0,
 						   view);
@@ -4205,6 +4233,7 @@ clipboard_targets_received (GtkClipboard
 	GdkAtom *targets;
 	int n_targets;
 	int i;
+	GList *current_selection;
 
 	view = FM_DIRECTORY_VIEW (user_data);
 	can_paste = FALSE;
@@ -4218,6 +4247,36 @@ clipboard_targets_received (GtkClipboard
 
 		g_free (targets);
 	}
+
+	/* Prevent pasting in any of the following cases:
+	     - the current selection is multiple
+	     - only one object is currently selected, but it's not a
+	       directory
+	 */
+	current_selection = fm_directory_view_get_selection (view);
+
+	if (current_selection != NULL) {
+		int count = g_list_length (current_selection);
+
+		if (count > 1) {
+			can_paste = FALSE;
+		} else {
+			NautilusFile *selected_object = NAUTILUS_FILE (current_selection->data);
+
+			if (!nautilus_file_is_directory (selected_object))
+				can_paste = FALSE;
+		}
+	}
+
+	/* Update paste menu item label according to the destination */
+	nautilus_bonobo_set_label_for_menu_item_and_command
+		(view->details->ui,
+		 FM_DIRECTORY_VIEW_MENU_PATH_PASTE_FILES,
+		 FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES,
+		 current_selection == NULL
+		 ? _("Paste Files Here")
+		 : _("Paste Files Into")
+		 );
 
 	if (view->details->ui != NULL)
 		nautilus_bonobo_set_sensitive (view->details->ui,
diff -pru nautilus-1.1.18.orig/src/file-manager/fm-icon-view.c nautilus-1.1.18/src/file-manager/fm-icon-view.c
--- nautilus-1.1.18.orig/src/file-manager/fm-icon-view.c	Wed May 22 00:30:01 2002
+++ nautilus-1.1.18/src/file-manager/fm-icon-view.c	Wed May 29 20:58:52 2002
@@ -1719,6 +1719,9 @@ icon_container_context_click_background_
 	g_assert (NAUTILUS_IS_ICON_CONTAINER (container));
 	g_assert (FM_IS_ICON_VIEW (icon_view));
 
+	/* Empty the current selection, if any */
+	fm_icon_view_set_selection (FM_DIRECTORY_VIEW (icon_view), NULL);
+
 	fm_directory_view_pop_up_background_context_menu 
 		(FM_DIRECTORY_VIEW (icon_view), event);
 }


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