]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Make sure Escape in a message box always does something.
authorSimon Tatham <anakin@pobox.com>
Sat, 26 Sep 2015 12:57:12 +0000 (13:57 +0100)
committerSimon Tatham <anakin@pobox.com>
Sat, 26 Sep 2015 12:57:12 +0000 (13:57 +0100)
The askalg() dialog, and several one-button things like the licence
box, have no button labelled 'cancel'. But in all cases we do want
Escape to terminate the box, with as negative an answer as is
available. So now we assign the 'iscancel' flag to any button whose
numeric value is the smallest of the ones given as input to
messagebox().

(In a one-button box, this leads to isdefault and iscancel _both_
being set for that button. That's fine; it works.)

unix/gtkdlg.c

index a4dbb0e56f51ddc4b1f0c58f1faa2914044a5231..9c16235095f0c089bc9667e36bbbceaeeed2e7ed 100644 (file)
@@ -3320,7 +3320,7 @@ int messagebox(GtkWidget *parentwin, const char *title, const char *msg,
     union control *c;
     struct dlgparam dp;
     struct Shortcuts scs;
-    int index, ncols;
+    int index, ncols, min_type;
     va_list ap;
 
     dlg_init(&dp);
@@ -3331,13 +3331,23 @@ int messagebox(GtkWidget *parentwin, const char *title, const char *msg,
 
     ctrlbox = ctrl_new_box();
 
+    /*
+     * Preliminary pass over the va_list, to count up the number of
+     * buttons and find out what kinds there are.
+     */
     ncols = 0;
     va_start(ap, minwid);
+    min_type = +1;
     while (va_arg(ap, char *) != NULL) {
-       ncols++;
+        int type;
+
        (void) va_arg(ap, int);        /* shortcut */
-       (void) va_arg(ap, int);        /* normal/default/cancel */
+       type = va_arg(ap, int);        /* normal/default/cancel */
        (void) va_arg(ap, int);        /* end value */
+
+       ncols++;
+        if (min_type > type)
+            min_type = type;
     }
     va_end(ap);
 
@@ -3362,7 +3372,17 @@ int messagebox(GtkWidget *parentwin, const char *title, const char *msg,
        c->generic.column = index++;
        if (type > 0)
            c->button.isdefault = TRUE;
-       else if (type < 0)
+
+        /* We always arrange that _some_ button is labelled as
+         * 'iscancel', so that pressing Escape will always cause
+         * win_key_press to do something. The button we choose is
+         * whichever has the smallest type value: this means that real
+         * cancel buttons (labelled -1) will be picked if one is
+         * there, or in cases where the options are yes/no (1,0) then
+         * no will be picked, and if there's only one option (a box
+         * that really is just showing a _message_ and not even asking
+         * a question) then that will be picked. */
+       if (type == min_type)
            c->button.iscancel = TRUE;
     }
     va_end(ap);