gnome-terminal r2775 - trunk/src



Author: chpe
Date: Thu May 29 19:53:02 2008
New Revision: 2775
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=2775&view=rev

Log:
gtk_dialog_run is evil, rework the code to avoid using it.


Modified:
   trunk/src/terminal-window.c

Modified: trunk/src/terminal-window.c
==============================================================================
--- trunk/src/terminal-window.c	(original)
+++ trunk/src/terminal-window.c	Thu May 29 19:53:02 2008
@@ -1508,7 +1508,7 @@
                               GdkEvent *event,
                               gpointer data)
 {
-   return !confirm_close_window (TERMINAL_WINDOW (widget));
+   return confirm_close_window (TERMINAL_WINDOW (widget));
 }
 
 static void
@@ -2348,28 +2348,41 @@
                              NULL, NULL, -1);
 }
 
+static void
+confirm_close_window_response_cb (GtkWidget *dialog,
+                                  int response,
+                                  GtkWidget *window)
+{
+  gtk_widget_destroy (dialog);
+
+  if (response == GTK_RESPONSE_ACCEPT)
+    gtk_widget_destroy (window);
+}
+
+/* Returns TRUE if closing needs to wait until user confirmation;
+ * FALSE if the window can close immediately
+ */
 static gboolean
 confirm_close_window (TerminalWindow *window)
 {
   TerminalWindowPrivate *priv = window->priv;
   GtkWidget *dialog;
   GConfClient *client;
-  gboolean result, do_confirm;
+  gboolean do_confirm;
   int n;
 
   n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
-
   if (n <= 1)
-    return TRUE;
+    return FALSE;
 
   client = gconf_client_get_default ();
   do_confirm = gconf_client_get_bool (client, CONF_GLOBAL_PREFIX "/confirm_window_close", NULL);
   g_object_unref (client);
   if (!do_confirm)
-    return TRUE;
+    return FALSE;
 
   dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                   GTK_DIALOG_DESTROY_WITH_PARENT,
+                                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_WARNING,
                                    GTK_BUTTONS_CANCEL,
                                    "%s", _("Close all tabs?"));
@@ -2386,18 +2399,18 @@
   gtk_dialog_add_button (GTK_DIALOG (dialog), _("Close All _Tabs"), GTK_RESPONSE_ACCEPT);
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
 
-  result = gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT;
-  gtk_widget_destroy (dialog);
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (confirm_close_window_response_cb), window);
+  gtk_window_present (GTK_WINDOW (dialog));
 
-  return result;
+  return TRUE;
 }
 
 static void
 file_close_window_callback (GtkAction *action,
                             TerminalWindow *window)
 {
-  if (confirm_close_window (window))
-    gtk_widget_destroy (GTK_WIDGET (window));
+  confirm_close_window (window);
 }
 
 static void



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