[PATCH] bug 75212: empty trash dialog is modal



Attached is a patch which makes the "Empty Trash?" confirmation dialog non-modal, fixing bug 75212. It introduces a new static global variable, confirm_empty_trash_dialog, which holds the dialog box (if open) and is tested to make sure multiple dialogs aren't created.

I'll post to Bugzilla if it looks okay.

--
Simon South
ssouth hamlet dyndns org
Index: nautilus-file-operations.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations.c,v
retrieving revision 1.152
diff -u -r1.152 nautilus-file-operations.c
--- nautilus-file-operations.c	2002/05/13 17:44:14	1.152
+++ nautilus-file-operations.c	2002/05/14 07:49:26
@@ -80,6 +80,9 @@
 	gboolean cancelled;	
 } TransferInfo;
 
+/* dialog to confirm emptying the Trash (there should be at most one) */
+static GtkDialog *confirm_empty_trash_dialog = NULL;
+
 static TransferInfo *
 transfer_info_new (GtkWidget *parent_view)
 {
@@ -2202,56 +2205,64 @@
 	gnome_vfs_uri_list_free (trash_dir_list);
 }
 
-static gboolean
-confirm_empty_trash (GtkWidget *parent_view)
+static void
+confirm_empty_trash_dialog_callback (GtkDialog *dialog,
+				     int response,
+				     GtkWidget *parent_view)
 {
-	GtkDialog *dialog;
-	GtkWindow *parent_window;
-	int response;
+	g_assert (dialog == confirm_empty_trash_dialog);
 
-	/* Just Say Yes if the preference says not to confirm. */
-	if (!eel_preferences_get_boolean (NAUTILUS_PREFERENCES_CONFIRM_TRASH)) {
-		return TRUE;
+	if (response == GTK_RESPONSE_YES) {
+		do_empty_trash(parent_view);
 	}
-	
-	parent_window = GTK_WINDOW (gtk_widget_get_toplevel (parent_view));
 
-	dialog = eel_show_yes_no_dialog (
-		_("Are you sure you want to permanently delete "
-		  "all of the items in the Trash?"),
-		_("Empty Trash?"),
-		_("Empty"),
-		GTK_STOCK_CANCEL,
-		parent_window);
+	if (dialog != NULL) {
+		gtk_object_destroy (GTK_OBJECT (dialog));
+	}
 
-	gtk_dialog_set_default_response (dialog, GTK_RESPONSE_CANCEL);
+	confirm_empty_trash_dialog = NULL;
+}
 
-	response = gtk_dialog_run (dialog);
+static void
+confirm_empty_trash (GtkWidget *parent_view)
+{
+	GtkWindow *parent_window;
 
-	gtk_object_destroy (GTK_OBJECT (dialog));
+	/* if a (non-modal) "Empty Trash?" confirmation dialog is already open,
+	 * do not create another */
+	if (confirm_empty_trash_dialog != NULL) {
+		gtk_window_present (GTK_WINDOW (confirm_empty_trash_dialog));
+	} else {
+		parent_window = GTK_WINDOW (gtk_widget_get_toplevel (parent_view));
 
-	return response == GTK_RESPONSE_YES;
+		confirm_empty_trash_dialog = eel_show_yes_no_dialog (
+			_("Are you sure you want to permanently delete "
+		  	"all of the items in the Trash?"),
+			_("Empty Trash?"),
+			_("Empty"),
+			GTK_STOCK_CANCEL,
+			parent_window);
+
+		gtk_window_set_resizable (GTK_WINDOW (confirm_empty_trash_dialog), FALSE);
+		gtk_dialog_set_default_response (confirm_empty_trash_dialog, GTK_RESPONSE_CANCEL);
+
+		g_signal_connect (confirm_empty_trash_dialog, 
+			  	"response",
+			  	G_CALLBACK (confirm_empty_trash_dialog_callback),
+			  	parent_view);
+	}
 }
-
+				
 void 
 nautilus_file_operations_empty_trash (GtkWidget *parent_view)
 {
 	g_return_if_fail (parent_view != NULL);
 
-	/* 
-	 * I chose to use a modal confirmation dialog here. 
-	 * If we used a modeless dialog, we'd have to do work to
-	 * make sure that no more than one appears on screen at
-	 * a time. That one probably couldn't be parented, because
-	 * otherwise you'd get into weird layer-shifting problems
-	 * selecting "Empty Trash" from one window when there was
-	 * already a modeless "Empty Trash" dialog parented on a 
-	 * different window. And if the dialog were not parented, it
-	 * might show up in some weird place since window manager
-	 * placement is unreliable (i.e., sucks). So modal it is.
-	 */
-	if (confirm_empty_trash (parent_view)) {
+	/* just empty the Trash if the preference says not to confirm */
+	if (!eel_preferences_get_boolean (NAUTILUS_PREFERENCES_CONFIRM_TRASH)) {
 		do_empty_trash (parent_view);
+	} else {
+		confirm_empty_trash (parent_view);
 	}
 }
 


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