Allow dialog boxes to be cancelled by hitting the Escape key.
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 15 Jun 2017 14:48:19 +0000 (16:48 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Thu, 15 Jun 2017 14:48:19 +0000 (16:48 +0200)
Closes bug #51225

NEWS
src/ui/gui/psppire-buttonbox.c

diff --git a/NEWS b/NEWS
index 07274cfeab5ab75782a01baee4f5c011d2ecf76f..492dc678acb238f2fa900d94a58cf6371fe0e040 100644 (file)
--- 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 <Escape> key.
+
  * The AUTORECODE command now accepts an optional / before INTO.
 
  * The short form of the VECTOR command can now create string variables.
index 87989cf12bfc76e4a6ccf8f57714afea41a93437..087c105587f7e2c83b7c237208bd01a8bd8ad0fa 100644 (file)
@@ -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)
 {