[nautilus] Don't allow moving files on top of themselves



commit 556d51aad615bbcbceb6607cd8f28367111c334c
Author: William Jon McCann <jmccann redhat com>
Date:   Sun Jul 15 12:39:21 2012 -0400

    Don't allow moving files on top of themselves
    
    Desensitize the select button when the cwd is the parent of the source files.

 src/nautilus-view.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index fe42875..49e60c9 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -5940,6 +5940,41 @@ copy_data_free (CopyCallbackData *data)
 	g_free (data);
 }
 
+static gboolean
+uri_is_parent_of_selection (GList *selection,
+			    const char *uri)
+{
+	gboolean found;
+	GList *l;
+	GFile *file;
+
+	found = FALSE;
+
+	file = g_file_new_for_uri (uri);
+	for (l = selection; !found && l != NULL; l = l->next) {
+		GFile *parent;
+		parent = nautilus_file_get_parent_location (l->data);
+		found = g_file_equal (file, parent);
+		g_object_unref (parent);
+	}
+	g_object_unref (file);
+	return found;
+}
+
+static void
+on_destination_dialog_folder_changed (GtkFileChooser *chooser,
+				      gpointer        user_data)
+{
+	CopyCallbackData *copy_data = user_data;
+	char *uri;
+	gboolean found;
+
+	uri = gtk_file_chooser_get_current_folder_uri (chooser);
+	found = uri_is_parent_of_selection (copy_data->selection, uri);
+	gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_OK, !found);
+	g_free (uri);
+}
+
 static void
 on_destination_dialog_response (GtkDialog *dialog,
 				gint       response_id,
@@ -6071,7 +6106,9 @@ copy_or_move_selection (NautilusView *view,
 	uri = nautilus_directory_get_uri (view->details->model);
 	gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
 	g_free (uri);
-
+	g_signal_connect (dialog, "current-folder-changed",
+			  G_CALLBACK (on_destination_dialog_folder_changed),
+			  copy_data);
 	g_signal_connect (dialog, "response",
 			  G_CALLBACK (on_destination_dialog_response),
 			  copy_data);



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