From 75be8d77019b08759864d4405dbdbcbfef98ced5 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 30 Sep 2011 12:28:29 -0400 Subject: Bug 659486 - EAlert default response is ignored by EAlertDialog --- e-util/e-alert-dialog.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'e-util/e-alert-dialog.c') diff --git a/e-util/e-alert-dialog.c b/e-util/e-alert-dialog.c index 8696588ab2..70e53432f3 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); -- cgit v1.2.3