summaryrefslogtreecommitdiff
path: root/gtk/gtkdialog.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2014-04-24 01:32:50 -0400
committerMatthias Clasen <mclasen@redhat.com>2014-04-25 22:11:53 -0400
commit66b6078ae20bfbd0023ec5982cb154a4547ece7b (patch)
treea755982290a95331e28af80d4c9fe31d699da494 /gtk/gtkdialog.c
parent90559a3fc58c50e76a591716264c67f520fba4b6 (diff)
downloadgtk+-66b6078ae20bfbd0023ec5982cb154a4547ece7b.tar.gz
GtkDialog: Update suggested-action more carefully
We were not really handling all cases correctly here. We want the suggested-action style class to only be set on headerbar buttons, and it should be set on the default widget. Ensure this by syncing the suggested-action style class with the default style class. As a side-effect, setting has-default on an action widget in ui files will now have the expected effect. https://bugzilla.gnome.org/show_bug.cgi?id=728846
Diffstat (limited to 'gtk/gtkdialog.c')
-rw-r--r--gtk/gtkdialog.c51
1 files changed, 40 insertions, 11 deletions
diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c
index b8585a137b..73ae618322 100644
--- a/gtk/gtkdialog.c
+++ b/gtk/gtkdialog.c
@@ -441,6 +441,30 @@ add_to_action_area (GtkDialog *dialog,
}
static void
+update_suggested_action (GtkDialog *dialog)
+{
+ GtkDialogPrivate *priv = dialog->priv;
+
+ if (priv->use_header_bar)
+ {
+ GList *children, *l;
+
+ children = gtk_container_get_children (GTK_CONTAINER (priv->headerbar));
+ for (l = children; l != NULL; l = l->next)
+ {
+ GtkWidget *child = l->data;
+ GtkStyleContext *context = gtk_widget_get_style_context (child);
+
+ if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_DEFAULT))
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_SUGGESTED_ACTION);
+ else
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SUGGESTED_ACTION);
+ }
+ g_list_free (children);
+ }
+}
+
+static void
add_action_widgets (GtkDialog *dialog)
{
GtkDialogPrivate *priv = dialog->priv;
@@ -467,12 +491,11 @@ add_action_widgets (GtkDialog *dialog)
g_object_unref (child);
if (has_default)
- {
- gtk_widget_grab_default (child);
- gtk_style_context_add_class (gtk_widget_get_style_context (child), GTK_STYLE_CLASS_SUGGESTED_ACTION);
- }
+ gtk_widget_grab_default (child);
}
g_list_free (children);
+
+ update_suggested_action (dialog);
}
}
static GObject *
@@ -1017,7 +1040,15 @@ gtk_dialog_add_action_widget (GtkDialog *dialog,
add_response_data (dialog, child, response_id);
if (priv->constructed && priv->use_header_bar)
- add_to_header_bar (dialog, child, response_id);
+ {
+ add_to_header_bar (dialog, child, response_id);
+
+ if (gtk_widget_has_default (child))
+ {
+ gtk_widget_grab_default (child);
+ update_suggested_action (dialog);
+ }
+ }
else
add_to_action_area (dialog, child, response_id);
}
@@ -1188,17 +1219,15 @@ gtk_dialog_set_default_response (GtkDialog *dialog,
ResponseData *rd = get_response_data (widget, FALSE);
if (rd && rd->response_id == response_id)
- {
- gtk_widget_grab_default (widget);
- gtk_style_context_add_class (gtk_widget_get_style_context (widget), GTK_STYLE_CLASS_SUGGESTED_ACTION);
- }
- else
- gtk_style_context_remove_class (gtk_widget_get_style_context (widget), GTK_STYLE_CLASS_SUGGESTED_ACTION);
+ gtk_widget_grab_default (widget);
tmp_list = g_list_next (tmp_list);
}
g_list_free (children);
+
+ if (dialog->priv->use_header_bar)
+ update_suggested_action (dialog);
}
/**