From e27e251c89f7d685deae647d6583caa3c4f80d69 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 15 Jun 2017 16:48:19 +0200 Subject: [PATCH] Allow dialog boxes to be cancelled by hitting the Escape key. Closes bug #51225 --- NEWS | 2 ++ src/ui/gui/psppire-buttonbox.c | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 07274cfeab..492dc678ac 100644 --- a/NEWS +++ b/NEWS @@ -35,6 +35,8 @@ Changes from 0.10.2 to 0.10.5pre1: ** The Non Parametric Statistics Menu has a new item: "K Independent Samples". + ** Dialog boxes can now be canceled using the key. + * The AUTORECODE command now accepts an optional / before INTO. * The short form of the VECTOR command can now create string variables. diff --git a/src/ui/gui/psppire-buttonbox.c b/src/ui/gui/psppire-buttonbox.c index 87989cf12b..087c105587 100644 --- a/src/ui/gui/psppire-buttonbox.c +++ b/src/ui/gui/psppire-buttonbox.c @@ -301,19 +301,37 @@ on_validity_change (GtkWidget *toplevel, gboolean valid, gpointer data) gtk_widget_set_sensitive (GTK_WIDGET (bb->button[PSPPIRE_BUTTON_CONTINUE]), valid); } +static gboolean +on_key_press (GtkWidget *w, GdkEventKey *e, gpointer ud) +{ + PsppireButtonbox *bb = PSPPIRE_BUTTONBOX (ud); + if (e->keyval == GDK_KEY_Escape) + { + g_signal_emit_by_name (bb->button[PSPPIRE_BUTTON_CANCEL], "activate"); + g_signal_emit_by_name (bb->button[PSPPIRE_BUTTON_CLOSE], "activate"); + } + return FALSE; +} + + static void on_realize (GtkWidget *buttonbox, gpointer data) { GtkWidget *toplevel = gtk_widget_get_toplevel (buttonbox); - if ( PSPPIRE_IS_DIALOG (toplevel)) + if (PSPPIRE_IS_DIALOG (toplevel)) { g_signal_connect (toplevel, "validity-changed", G_CALLBACK (on_validity_change), buttonbox); + + g_signal_connect (toplevel, "key-press-event", + G_CALLBACK (on_key_press), buttonbox); } + set_default (PSPPIRE_BUTTONBOX (buttonbox)); } + static void psppire_button_box_init (PsppireButtonbox *bb) { -- 2.30.2