diff options
author | William Jon McCann <jmccann@redhat.com> | 2012-07-15 12:39:21 -0400 |
---|---|---|
committer | William Jon McCann <jmccann@redhat.com> | 2012-07-15 13:32:49 -0400 |
commit | 556d51aad615bbcbceb6607cd8f28367111c334c (patch) | |
tree | bff4978fa3c2e981ff24b22bc53e03e83c5c4d69 | |
parent | 5a3481b8c3c78b2ad04a605c2ebf142373f64de7 (diff) | |
download | nautilus-556d51aad615bbcbceb6607cd8f28367111c334c.tar.gz |
Don't allow moving files on top of themselves
Desensitize the select button when the cwd is the parent of the source files.
-rw-r--r-- | 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 fe42875ea..49e60c9f4 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); |