[nautilus] Disallow selecting source dirs for target dir



commit 249d46e905cfdaeeb10253376b9b700af2e41122
Author: William Jon McCann <jmccann redhat com>
Date:   Sun Jul 8 03:30:05 2012 -0400

    Disallow selecting source dirs for target dir
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679579

 src/nautilus-view.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 5233906..f90452e 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -5973,6 +5973,40 @@ on_destination_dialog_response (GtkDialog *dialog,
 	gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
+static gboolean
+destination_dialog_filter_cb (const GtkFileFilterInfo *filter_info,
+			      gpointer                 user_data)
+{
+	GList *selection = user_data;
+	GList *l;
+
+	for (l = selection; l != NULL; l = l->next) {
+		char *uri;
+		uri = nautilus_file_get_uri (l->data);
+		if (strcmp (uri, filter_info->uri) == 0) {
+			g_free (uri);
+			return FALSE;
+		}
+		g_free (uri);
+	}
+
+	return TRUE;
+}
+
+static GList *
+get_selected_folders (GList *selection)
+{
+	GList *folders;
+	GList *l;
+
+	folders = NULL;
+	for (l = selection; l != NULL; l = l->next) {
+		if (nautilus_file_is_directory (l->data))
+			folders = g_list_prepend (folders, nautilus_file_ref (l->data));
+	}
+	return g_list_reverse (folders);
+}
+
 static void
 add_window_location_bookmarks (CopyCallbackData *data)
 {
@@ -6020,6 +6054,21 @@ copy_or_move_selection (NautilusView *view,
 
 	add_window_location_bookmarks (copy_data);
 
+	if (selection != NULL) {
+		GtkFileFilter *filter;
+		GList *folders;
+
+		folders = get_selected_folders (selection);
+
+		filter = gtk_file_filter_new ();
+		gtk_file_filter_add_custom (filter,
+					    GTK_FILE_FILTER_URI,
+					    destination_dialog_filter_cb,
+					    folders,
+					    (GDestroyNotify)nautilus_file_list_free);
+		gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
+	}
+
 	uri = nautilus_directory_get_uri (view->details->model);
 	gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
 	g_free (uri);



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