changeset 20532:bb09279e5c99

menu.m: Fix bug #45988, return 0 if the dialog is aborted or invalid selection
author Andreas Weber <andy.weber.aw@gmail.com>
date Tue, 22 Sep 2015 11:25:04 +0200
parents bf6c4433ed5f
children 1f330d33388f
files scripts/miscellaneous/menu.m
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/menu.m	Tue Sep 22 01:38:40 2015 -0700
+++ b/scripts/miscellaneous/menu.m	Tue Sep 22 11:25:04 2015 +0200
@@ -30,7 +30,8 @@
 ## or as a cell array of strings.
 ##
 ## The return value @var{choice} is the number of the option selected by the
-## user counting from 1.
+## user counting from 1 or 0 if the user aborts the dialog or makes an invalid
+## selection.
 ##
 ## This function is useful for interactive programs.  There is no limit to the
 ## number of options that may be passed in, but it may be confusing to present
@@ -58,7 +59,7 @@
     [choice, ok] = listdlg ("Name", "menu", "PromptString", title,
                             "ListString", varargin, "SelectionMode", "Single");
     if (! ok)
-      choice = 1;
+      choice = 0;
     endif
   else  # console menu
     ## Force pending output to appear before the menu.
@@ -82,6 +83,7 @@
       choice = sscanf (s, "%d");
       if (! isscalar (choice) || choice < 1 || choice > nopt)
         printf ("\nerror: input invalid or out of range\n\n");
+        choice = 0;
       else
         break;
       endif