[evolution/gnome-3-2] Bug 659486 - EAlert default response is ignored by EAlertDialog



commit 20fc87485e564bc6befdda6eef89688c16ff12f3
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Sep 30 12:28:29 2011 -0400

    Bug 659486 - EAlert default response is ignored by EAlertDialog
    
    (cherry picked from commit 75be8d77019b08759864d4405dbdbcbfef98ced5)

 composer/mail-composer.error.xml |    2 +-
 e-util/e-alert-dialog.c          |   28 ++++++++++++++++++++++------
 2 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/composer/mail-composer.error.xml b/composer/mail-composer.error.xml
index 7398f17..0f6f11d 100644
--- a/composer/mail-composer.error.xml
+++ b/composer/mail-composer.error.xml
@@ -35,7 +35,7 @@
   <button _label="_Send" response="GTK_RESPONSE_YES"/>
  </error>
 
- <error id="exit-unsaved" type="warning" default="GTK_RESPONSE_YES">
+ <error id="exit-unsaved" type="warning" default="GTK_RESPONSE_CANCEL">
   <_primary>Are you sure you want to discard the message, titled '{0}', you are composing?</_primary>
   <_secondary>Closing this composer window will discard the message permanently, unless you choose to save the message in your Drafts folder. This will allow you to continue the message at a later date.</_secondary>
   <button _label="_Discard Changes" response="GTK_RESPONSE_NO"/>
diff --git a/e-util/e-alert-dialog.c b/e-util/e-alert-dialog.c
index 8696588..70e5343 100644
--- a/e-util/e-alert-dialog.c
+++ b/e-util/e-alert-dialog.c
@@ -120,6 +120,7 @@ alert_dialog_constructed (GObject *object)
 	PangoAttrList *list;
 	GList *actions;
 	const gchar *primary, *secondary;
+	gint default_response;
 	gint min_width = -1, prefer_width = -1;
 	gint height;
 
@@ -129,6 +130,8 @@ alert_dialog_constructed (GObject *object)
 	dialog = E_ALERT_DIALOG (object);
 	alert = e_alert_dialog_get_alert (dialog);
 
+	default_response = e_alert_get_default_response (alert);
+
 	gtk_window_set_title (GTK_WINDOW (dialog), " ");
 
 	action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
@@ -149,15 +152,19 @@ alert_dialog_constructed (GObject *object)
 	actions = e_alert_peek_actions (alert);
 	while (actions != NULL) {
 		GtkWidget *button;
+		gpointer data;
 
 		/* These actions are already wired to trigger an
 		 * EAlert::response signal when activated, which
 		 * will in turn call to gtk_dialog_response(),
 		 * so we can add buttons directly to the action
-		 * area without knowing their response IDs. */
+		 * area without knowing their response IDs.
+		 * (XXX Well, kind of.  See below.) */
 
 		button = gtk_button_new ();
 
+		gtk_widget_set_can_default (button, TRUE);
+
 		gtk_activatable_set_related_action (
 			GTK_ACTIVATABLE (button),
 			GTK_ACTION (actions->data));
@@ -166,14 +173,23 @@ alert_dialog_constructed (GObject *object)
 			GTK_BOX (action_area),
 			button, FALSE, FALSE, 0);
 
+		/* This is set in e_alert_add_action(). */
+		data = g_object_get_data (
+			actions->data, "e-alert-response-id");
+
+		/* Normally GtkDialog sets the initial focus widget to
+		 * the button corresponding to the default response, but
+		 * because the buttons are not directly tied to response
+		 * IDs, we have set both the default widget and the
+		 * initial focus widget ourselves. */
+		if (GPOINTER_TO_INT (data) == default_response) {
+			gtk_widget_grab_default (button);
+			gtk_widget_grab_focus (button);
+		}
+
 		actions = g_list_next (actions);
 	}
 
-	if (e_alert_get_default_response (alert))
-		gtk_dialog_set_default_response (
-			GTK_DIALOG (dialog),
-			e_alert_get_default_response (alert));
-
 	widget = gtk_hbox_new (FALSE, 12);
 	gtk_container_set_border_width (GTK_CONTAINER (widget), 12);
 	gtk_box_pack_start (GTK_BOX (content_area), widget, FALSE, FALSE, 0);



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