nautilus r14181 - in trunk: . libnautilus-private src/file-manager



Author: cosimoc
Date: Mon May 19 23:20:58 2008
New Revision: 14181
URL: http://svn.gnome.org/viewvc/nautilus?rev=14181&view=rev

Log:
2008-05-20  Cosimo Cecchi  <cosimoc gnome org>

	* libnautilus-private/nautilus-clipboard.c:
	(convert_lines_to_str_list),
	(nautilus_clipboard_get_uri_list_from_selection_data),
	(nautilus_clipboard_get),
	(nautilus_clipboard_clear_if_colliding_uris):
	* libnautilus-private/nautilus-clipboard.h:
	* src/file-manager/fm-directory-view.c:
	(fm_directory_view_get_copied_files_atom), (copy_or_cut_files),
	(paste_clipboard_data), (action_paste_files_callback),
	(paste_into), (real_update_paste_menu):
	* src/file-manager/fm-directory-view.h:
	* src/file-manager/fm-icon-view.c: (icon_view_move_copy_items):
	* src/file-manager/fm-list-view.c: (move_copy_items_callback):
	* src/file-manager/fm-tree-view.c: (move_copy_items_callback),
	(button_pressed_callback), (copy_or_cut_files),
	(paste_clipboard_data), (fm_tree_view_paste_cb):
	Empty the clipboard when copying/moving with DnD a file contained
	in it. Also, refactor some clipboard code from fm-directory-view.c and
	fm-tree-view.c into nautilus-clipboard.c. (#532850).


Modified:
   trunk/ChangeLog
   trunk/libnautilus-private/nautilus-clipboard.c
   trunk/libnautilus-private/nautilus-clipboard.h
   trunk/src/file-manager/fm-directory-view.c
   trunk/src/file-manager/fm-directory-view.h
   trunk/src/file-manager/fm-icon-view.c
   trunk/src/file-manager/fm-list-view.c
   trunk/src/file-manager/fm-tree-view.c

Modified: trunk/libnautilus-private/nautilus-clipboard.c
==============================================================================
--- trunk/libnautilus-private/nautilus-clipboard.c	(original)
+++ trunk/libnautilus-private/nautilus-clipboard.c	Mon May 19 23:20:58 2008
@@ -39,6 +39,7 @@
 #include <gtk/gtksignal.h>
 #include <gtk/gtktext.h>
 #include <gtk/gtktextview.h>
+#include <eel/eel-glib-extensions.h>
 #include <string.h>
 
 typedef struct _TargetCallbackData TargetCallbackData;
@@ -553,4 +554,100 @@
 					text_view_disconnect_callbacks);
 }
 
+static GList *
+convert_lines_to_str_list (char **lines, gboolean *cut)
+{
+	int i;
+	GList *result;
+
+	if (cut) {
+		*cut = FALSE;
+	}
+
+	if (lines[0] == NULL) {
+		return NULL;
+	}
 
+	if (strcmp (lines[0], "cut") == 0) {
+		if (cut) {
+			*cut = TRUE;
+		}
+	} else if (strcmp (lines[0], "copy") != 0) {
+		return NULL;
+	}
+
+	result = NULL;
+	for (i = 1; lines[i] != NULL; i++) {
+		result = g_list_prepend (result, g_strdup (lines[i]));
+	}
+	return g_list_reverse (result);
+}
+
+GList*
+nautilus_clipboard_get_uri_list_from_selection_data (GtkSelectionData *selection_data,
+						     gboolean *cut,
+						     GdkAtom copied_files_atom)
+{
+	GList *items;
+	char **lines;
+
+	if (selection_data->type != copied_files_atom
+	    || selection_data->length <= 0) {
+		items = 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);
+		items = convert_lines_to_str_list (lines, cut);
+		g_strfreev (lines);
+	}
+	
+	return items;
+}
+
+GtkClipboard *
+nautilus_clipboard_get (GtkWidget *widget)
+{
+	return gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (widget)),
+					      GDK_SELECTION_CLIPBOARD);
+}
+
+void
+nautilus_clipboard_clear_if_colliding_uris (GtkWidget *widget,
+					    const GList *item_uris,
+					    GdkAtom copied_files_atom)
+{
+	GtkSelectionData *data;
+	GList *clipboard_item_uris, *l;
+	gboolean collision;
+
+	collision = FALSE;
+	data = gtk_clipboard_wait_for_contents (nautilus_clipboard_get (widget),
+						copied_files_atom);
+	if (data == NULL) {
+		return;
+	}
+
+	clipboard_item_uris = nautilus_clipboard_get_uri_list_from_selection_data (data, NULL,
+										   copied_files_atom);
+
+	for (l = (GList *) item_uris; l; l = l->next) {
+		if (g_list_find_custom ((GList *) item_uris, l->data,
+					(GCompareFunc) g_strcmp0)) {
+			collision = TRUE;
+			break;
+		}
+	}
+	
+	if (collision) {
+		gtk_clipboard_clear (nautilus_clipboard_get (widget));
+	}
+	
+	if (clipboard_item_uris) {
+		eel_g_list_free_deep (clipboard_item_uris);
+	}
+}

Modified: trunk/libnautilus-private/nautilus-clipboard.h
==============================================================================
--- trunk/libnautilus-private/nautilus-clipboard.h	(original)
+++ trunk/libnautilus-private/nautilus-clipboard.h	Mon May 19 23:20:58 2008
@@ -44,6 +44,13 @@
 						    gboolean            shares_selection_changes);
 void nautilus_clipboard_set_up_text_view           (GtkTextView        *target,
 						    GtkUIManager       *ui_manager);
-
+void nautilus_clipboard_clear_if_colliding_uris    (GtkWidget          *widget,
+						    const GList        *item_uris,
+						    GdkAtom             copied_files_atom);
+GtkClipboard* nautilus_clipboard_get                (GtkWidget          *widget);
+GList* nautilus_clipboard_get_uri_list_from_selection_data
+						   (GtkSelectionData   *selection_data,
+						    gboolean           *cut,
+						    GdkAtom             copied_files_atom);
 
 #endif /* NAUTILUS_CLIPBOARD_H */

Modified: trunk/src/file-manager/fm-directory-view.c
==============================================================================
--- trunk/src/file-manager/fm-directory-view.c	(original)
+++ trunk/src/file-manager/fm-directory-view.c	Mon May 19 23:20:58 2008
@@ -71,6 +71,7 @@
 #include <libgnomeui/gnome-help.h>
 #include <libnautilus-private/nautilus-recent.h>
 #include <libnautilus-extension/nautilus-menu-provider.h>
+#include <libnautilus-private/nautilus-clipboard.h>
 #include <libnautilus-private/nautilus-clipboard-monitor.h>
 #include <libnautilus-private/nautilus-debug-log.h>
 #include <libnautilus-private/nautilus-desktop-icon-file.h>
@@ -3481,6 +3482,14 @@
 	return view->details->model;
 }
 
+GdkAtom
+fm_directory_view_get_copied_files_atom (FMDirectoryView *view)
+{
+	g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), GDK_NONE);
+	
+	return copied_files_atom;
+}
+
 static void
 prepend_uri_one (gpointer data, gpointer callback_data)
 {
@@ -5572,13 +5581,6 @@
 	g_free (info);
 }
 
-static GtkClipboard *
-get_clipboard (FMDirectoryView *view)
-{
-	return gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (view)),
-					      GDK_SELECTION_CLIPBOARD);
-}
-
 static GList *
 convert_file_list_to_uri_list (GList *files)
 {
@@ -5606,7 +5608,7 @@
 	info->file_uris = convert_file_list_to_uri_list (clipboard_contents);
 	info->cut = cut;
 	
-	gtk_clipboard_set_with_data (get_clipboard (view),
+	gtk_clipboard_set_with_data (nautilus_clipboard_get (GTK_WIDGET (view)),
 				     clipboard_targets, G_N_ELEMENTS (clipboard_targets),
 				     get_clipboard_callback, clear_clipboard_callback,
 				     info);
@@ -5677,55 +5679,17 @@
 	nautilus_file_list_free (selection);
 }
 
-static GList *
-convert_lines_to_str_list (char **lines, gboolean *cut)
-{
-	int i;
-	GList *result;
-
-	*cut = FALSE;
-
-	if (lines[0] == NULL) {
-		return NULL;
-	}
-
-	if (strcmp (lines[0], "cut") == 0) {
-		*cut = TRUE;
-	} else if (strcmp (lines[0], "copy") != 0) {
-		return NULL;
-	}
-
-	result = NULL;
-	for (i = 1; lines[i] != NULL; i++) {
-		result = g_list_prepend (result, g_strdup (lines[i]));
-	}
-	return g_list_reverse (result);
-}
-
 static void
 paste_clipboard_data (FMDirectoryView *view,
 		      GtkSelectionData *selection_data,
 		      char *destination_uri)
 {
-	char **lines;
 	gboolean cut;
 	GList *item_uris;
 
 	cut = FALSE;
-	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);
-	}
+	item_uris = nautilus_clipboard_get_uri_list_from_selection_data (selection_data, &cut,
+									 copied_files_atom);
 
 	if (item_uris == NULL|| destination_uri == NULL) {
 		nautilus_window_info_set_status (view->details->window,
@@ -5738,7 +5702,7 @@
 
 		/* If items are cut then remove from clipboard */
 		if (cut) {
-			gtk_clipboard_clear (get_clipboard (view));
+			gtk_clipboard_clear (nautilus_clipboard_get (GTK_WIDGET (view)));
 		}
 
 		eel_g_list_free_deep (item_uris);
@@ -5806,7 +5770,7 @@
 	view = FM_DIRECTORY_VIEW (callback_data);
 	
 	g_object_ref (view);
-	gtk_clipboard_request_contents (get_clipboard (view),
+	gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
 					copied_files_atom,
 					paste_clipboard_received_callback,
 					callback_data);
@@ -5826,7 +5790,7 @@
 	data->view = g_object_ref (view);
 	data->target = nautilus_file_ref (target);
 
-	gtk_clipboard_request_contents (get_clipboard (view),
+	gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
 					copied_files_atom,
 					paste_into_clipboard_received_callback,
 					data);
@@ -7191,7 +7155,7 @@
 
 	/* Ask the clipboard */
 	g_object_ref (view); /* Need to keep the object alive until we get the reply */
-	gtk_clipboard_request_contents (get_clipboard (view),
+	gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
 					gdk_atom_intern ("TARGETS", FALSE),
 					clipboard_targets_received,
 					view);

Modified: trunk/src/file-manager/fm-directory-view.h
==============================================================================
--- trunk/src/file-manager/fm-directory-view.h	(original)
+++ trunk/src/file-manager/fm-directory-view.h	Mon May 19 23:20:58 2008
@@ -373,6 +373,7 @@
 									int               x,
 									int               y,
 									FMDirectoryView  *view);
+GdkAtom	            fm_directory_view_get_copied_files_atom            (FMDirectoryView  *view);
 
 /* Wrappers for signal emitters. These are normally called 
  * only by FMDirectoryView itself. They have corresponding signals

Modified: trunk/src/file-manager/fm-icon-view.c
==============================================================================
--- trunk/src/file-manager/fm-icon-view.c	(original)
+++ trunk/src/file-manager/fm-icon-view.c	Mon May 19 23:20:58 2008
@@ -2540,6 +2540,9 @@
 			   int x, int y,
 			   FMDirectoryView *view)
 {
+	nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
+						    item_uris,
+						    fm_directory_view_get_copied_files_atom (view));
 	fm_directory_view_move_copy_items (item_uris, relative_item_points, target_dir,
 		copy_action, x, y, view);
 }

Modified: trunk/src/file-manager/fm-list-view.c
==============================================================================
--- trunk/src/file-manager/fm-list-view.c	(original)
+++ trunk/src/file-manager/fm-list-view.c	Mon May 19 23:20:58 2008
@@ -1152,12 +1152,17 @@
 			  gpointer user_data)
 
 {
+	FMDirectoryView *view = user_data;
+
+	nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
+						    item_uris,
+						    fm_directory_view_get_copied_files_atom (view));
 	fm_directory_view_move_copy_items (item_uris,
 					   NULL,
 					   target_uri,
 					   action,
 					   x, y,
-					   FM_DIRECTORY_VIEW (user_data));
+					   view);
 }
 
 static void

Modified: trunk/src/file-manager/fm-tree-view.c
==============================================================================
--- trunk/src/file-manager/fm-tree-view.c	(original)
+++ trunk/src/file-manager/fm-tree-view.c	Mon May 19 23:20:58 2008
@@ -59,6 +59,7 @@
 #include <gio/gio.h>
 #include <libgnomeui/gnome-uidefs.h>
 #include <libgnomeui/gnome-popup-menu.h>
+#include <libnautilus-private/nautilus-clipboard.h>
 #include <libnautilus-private/nautilus-clipboard-monitor.h>
 #include <libnautilus-private/nautilus-desktop-icon-file.h>
 #include <libnautilus-private/nautilus-debug-log.h>
@@ -572,7 +573,10 @@
 	FMTreeView *view;
 
 	view = FM_TREE_VIEW (user_data);
-
+	
+	nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
+						    item_uris,
+						    copied_files_atom);
 	nautilus_file_operations_copy_move
 		(item_uris,
 		 NULL,
@@ -647,13 +651,6 @@
 	g_object_unref (view);
 }
 
-static GtkClipboard *
-get_clipboard (GtkWidget *widget)
-{
-	return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
-					      GDK_SELECTION_CLIPBOARD);
-}
-
 static gboolean
 is_parent_writable (NautilusFile *file)
 {
@@ -713,7 +710,7 @@
 		gtk_widget_set_sensitive (view->details->popup_paste, FALSE);
 		if (nautilus_file_is_directory (view->details->popup_file) &&
 			nautilus_file_can_write (view->details->popup_file)) {
-			gtk_clipboard_request_contents (get_clipboard (GTK_WIDGET (view->details->tree_widget)),
+			gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view->details->tree_widget)),
 							copied_files_atom,
 							clipboard_contents_received_callback, g_object_ref (view));
 		}
@@ -887,7 +884,7 @@
 	
 	clipboard_string = convert_file_to_string (view->details->popup_file, cut);
 	
-	gtk_clipboard_set_with_data (get_clipboard (GTK_WIDGET (view->details->tree_widget)),
+	gtk_clipboard_set_with_data (nautilus_clipboard_get (GTK_WIDGET (view->details->tree_widget)),
 				     clipboard_targets, G_N_ELEMENTS (clipboard_targets),
 				     get_clipboard_callback, clear_clipboard_callback,
 				     clipboard_string);
@@ -924,55 +921,17 @@
 	copy_or_cut_files (view, FALSE);
 }
 
-static GList *
-convert_lines_to_str_list (char **lines, gboolean *cut)
-{
-	int i;
-	GList *result;
-
-	*cut = FALSE;
-
-	if (lines[0] == NULL) {
-		return NULL;
-	}
-
-	if (strcmp (lines[0], "cut") == 0) {
-		*cut = TRUE;
-	} else if (strcmp (lines[0], "copy") != 0) {
-		return NULL;
-	}
-
-	result = NULL;
-	for (i = 1; lines[i] != NULL; i++) {
-		result = g_list_prepend (result, g_strdup (lines[i]));
-	}
-	return g_list_reverse (result);
-}
-
 static void
 paste_clipboard_data (FMTreeView *view,
 		      GtkSelectionData *selection_data,
 		      char *destination_uri)
 {
-	char **lines;
 	gboolean cut;
 	GList *item_uris;
 
 	cut = FALSE;
-	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);
-	}
+	item_uris = nautilus_clipboard_get_uri_list_from_selection_data (selection_data, &cut,
+									 copied_files_atom);
 
 	if (item_uris == NULL|| destination_uri == NULL) {
 		nautilus_window_info_set_status (view->details->window,
@@ -983,6 +942,13 @@
 			 cut ? GDK_ACTION_MOVE : GDK_ACTION_COPY,
 			 GTK_WIDGET (view->details->tree_widget),
 			 NULL, NULL);
+
+		/* If items are cut then remove from clipboard */
+		if (cut) {
+			gtk_clipboard_clear (nautilus_clipboard_get (GTK_WIDGET (view)));
+		}
+		
+		eel_g_list_free_deep (item_uris);
 	}
 }
 
@@ -1007,7 +973,7 @@
 fm_tree_view_paste_cb (GtkWidget *menu_item,
 		       FMTreeView *view)
 {
-	gtk_clipboard_request_contents (get_clipboard (GTK_WIDGET (view->details->tree_widget)),
+	gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view->details->tree_widget)),
 					copied_files_atom,
 					paste_into_clipboard_received_callback, view);
 }



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