diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-09-08 00:08:01 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-09-08 00:09:55 -0400 |
commit | ffe0ec6883d41241c4966584efa95688ae7ace85 (patch) | |
tree | 2c4051f5dfafc2030ca1ec8ea3fdabfb4d0d84a4 /gtk/gtkassistant.c | |
parent | 145c3e609d6c42545c57fca950c857e48c87c51a (diff) | |
download | gtk+-ffe0ec6883d41241c4966584efa95688ae7ace85.tar.gz |
GtkAssistant: Make Escape cancel the assistant
This is an expected keybinding, and it is not hard to support.
Note that we use a private ::escape signal instead of using
::cancel directly, since we want to be able to suppress the
cancellation when we are on a progress page.
https://bugzilla.gnome.org/show_bug.cgi?id=579625
Diffstat (limited to 'gtk/gtkassistant.c')
-rw-r--r-- | gtk/gtkassistant.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/gtk/gtkassistant.c b/gtk/gtkassistant.c index 0e3f7cb370..64a8089450 100644 --- a/gtk/gtkassistant.c +++ b/gtk/gtkassistant.c @@ -205,6 +205,7 @@ enum PREPARE, APPLY, CLOSE, + ESCAPE, LAST_SIGNAL }; @@ -363,11 +364,27 @@ gtk_assistant_constructed (GObject *object) } static void +escape_cb (GtkAssistant *assistant) +{ + GtkAssistantPrivate *priv = assistant->priv; + + /* Do not allow cancelling in the middle of a progress page */ + if (priv->current_page && + (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS || + priv->current_page->complete)) + g_signal_emit (assistant, signals [CANCEL], 0, NULL); + + /* don't run any user handlers - this is not a public signal */ + g_signal_stop_emission (assistant, signals[ESCAPE], 0); +} + +static void gtk_assistant_class_init (GtkAssistantClass *class) { GObjectClass *gobject_class; GtkWidgetClass *widget_class; GtkContainerClass *container_class; + GtkBindingSet *binding_set; gobject_class = (GObjectClass *) class; widget_class = (GtkWidgetClass *) class; @@ -474,6 +491,18 @@ gtk_assistant_class_init (GtkAssistantClass *class) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + signals[ESCAPE] = + g_signal_new_class_handler (I_("escape"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_CALLBACK (escape_cb), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + binding_set = gtk_binding_set_by_class (class); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "escape", 0); + /** * GtkAssistant:use-header-bar: * |