# HG changeset patch # User Rik # Date 1461192877 25200 # Node ID 59ebef9680eff6bc1a8893fe9064d53ef97a540e # Parent a3a412dee70450260bf53d305b824a6d1700eb0c More cleanup associated with removing Java dialog boxes (cset b5d9b95d1e1a). * NEWS: List errordlg only once in list of Java functions removed. * errordlg.m: Use a single sentence description of function for first documentation paragraph. Correct misspelling of "occurred". Match variable names in code to those in docstring. * helpdlg.m, warndlg.m: Use a single sentence description of function for first documentation paragraph. Match variable names in code to those in docstring. * inputdlg.m: Match variable names in code to those in docstring. Use function name as prefix to all error messages. Use spaces and line wrapping to make %!demos more readable. * listdlg.m: Re-order and rephrase some of docstring. Add more input validation. Add new BIST tests for input validation. * questdlg.m: Re-order some of docstring. Use function name as prefix to all error messages. Eliminate unreachable otherwise statement in switch block. Add new BIST tests for input validation. diff -r a3a412dee704 -r 59ebef9680ef NEWS --- a/NEWS Wed Apr 20 15:29:35 2016 -0700 +++ b/NEWS Wed Apr 20 15:54:37 2016 -0700 @@ -71,9 +71,9 @@ ** The textscan function is now built-in and is much faster and much more Matlab-compatible than the previous m-file version. - ** Dialog boxes, errordlg, helpdlg, inputdlg, errordlg, listdlg, - msgbox, questdlg, and warndlg, now exclusively use QT. Java based - versions are removed. + ** Dialog boxes--errordlg, helpdlg, inputdlg, listdlg, msgbox, + questdlg, and warndlg--now exclusively use Qt for rendering. + Java based versions have been removed. ** Other new functions added in 4.2: diff -r a3a412dee704 -r 59ebef9680ef scripts/gui/errordlg.m --- a/scripts/gui/errordlg.m Wed Apr 20 15:29:35 2016 -0700 +++ b/scripts/gui/errordlg.m Wed Apr 20 15:54:37 2016 -0700 @@ -21,10 +21,11 @@ ## @deftypefnx {} {@var{h} =} errordlg (@var{msg}) ## @deftypefnx {} {@var{h} =} errordlg (@var{msg}, @var{title}) ## @deftypefnx {} {@var{h} =} errordlg (@var{msg}, @var{title}, @var{createmode}) -## Display an error message @var{msg} using an error dialog box with caption -## @var{title} (character string). The default error message is -## @qcode{"This is the default error string."} and the default caption is -## @qcode{"Error Dialog"}. +## Display an error dialog box with error message @var{msg} and caption +## @var{title}. +## +## The default error message is @qcode{"This is the default error string."} and +## the default caption is @qcode{"Error Dialog"}. ## ## The error message may have multiple lines separated by newline characters ## ("\n"), or it may be a cellstr array with one element for each line. @@ -39,10 +40,10 @@ ## ## @example ## @group -## errordlg ("Some fancy error occured."); +## errordlg ("Some fancy error occurred."); ## errordlg ("Some fancy error\nwith two lines."); ## errordlg (@{"Some fancy error", "with two lines."@}); -## errordlg ("Some fancy error occured.", "Fancy caption"); +## errordlg ("Some fancy error occurred.", "Fancy caption"); ## @end group ## @end example ## @@ -53,24 +54,26 @@ narginchk (0, 3); - box_msg = "This is the default error string."; - box_title = "Error Dialog"; + msg = "This is the default error string."; + title = "Error Dialog"; if (nargin > 0) - box_msg = varargin{1}; + msg = varargin{1}; endif if (nargin > 1) - box_title = varargin{2}; + title = varargin{2}; endif if (nargin < 3) - retval = msgbox (box_msg, box_title, "error"); + retval = msgbox (msg, title, "error"); else - retval = msgbox (box_msg, box_title, "error", varargin{3}); + retval = msgbox (msg, title, "error", varargin{3}); endif endfunction -%!error errordlg (1, 2, 3, 4) -%!error errordlg (1) -%!error errordlg ("msg", 1) + +%!error errordlg (1, 2, 3, 4) +%!error <MSG must be a character string> errordlg (1) +%!error <TITLE must be a character string> errordlg ("msg", 1) + diff -r a3a412dee704 -r 59ebef9680ef scripts/gui/helpdlg.m --- a/scripts/gui/helpdlg.m Wed Apr 20 15:29:35 2016 -0700 +++ b/scripts/gui/helpdlg.m Wed Apr 20 15:54:37 2016 -0700 @@ -20,10 +20,11 @@ ## @deftypefn {} {@var{h} =} helpdlg () ## @deftypefnx {} {@var{h} =} helpdlg (@var{msg}) ## @deftypefnx {} {@var{h} =} helpdlg (@var{msg}, @var{title}) -## Display help message @var{msg} using a help dialog box with caption -## @var{title} (character string). The default help message is -## @qcode{"This is the default help string."} and the default caption is -## @qcode{"Help Dialog"}. +## Display a help dialog box with help message @var{msg} and caption +## @var{title}. +## +## The default help message is @qcode{"This is the default help string."} and +## the default caption is @qcode{"Help Dialog"}. ## ## The help message may have multiple lines separated by newline characters ## ("\n"), or it may be a cellstr array with one element for each line. @@ -48,20 +49,22 @@ narginchk (0, 2); - box_msg = "This is the default help string."; - box_title = "Help Dialog"; + msg = "This is the default help string."; + title = "Help Dialog"; if (nargin > 0) - box_msg = varargin{1}; + msg = varargin{1}; endif if (nargin > 1) - box_title = varargin{2}; + title = varargin{2}; endif - retval = msgbox (box_msg, box_title, "help"); + retval = msgbox (msg, title, "help"); endfunction -%!error<narginchk> helpdlg (1, 2, 3) -%!error<MSG must be a character string> helpdlg (1) -%!error<TITLE must be a character string> helpdlg ("msg", 1) + +%!error helpdlg (1, 2, 3) +%!error <MSG must be a character string> helpdlg (1) +%!error <TITLE must be a character string> helpdlg ("msg", 1) + diff -r a3a412dee704 -r 59ebef9680ef scripts/gui/inputdlg.m --- a/scripts/gui/inputdlg.m Wed Apr 20 15:29:35 2016 -0700 +++ b/scripts/gui/inputdlg.m Wed Apr 20 15:54:37 2016 -0700 @@ -75,15 +75,15 @@ elseif (ischar (prompt)) prompt = {prompt}; else - error ("PROMPT must be a character string or cellstr array"); + error ("inputdlg: PROMPT must be a character string or cellstr array"); endif - dlg_title = "Input Dialog"; + title = "Input Dialog"; if (nargin > 1) - dlg_title = varargin{1}; - if (! ischar (dlg_title)) - error ("TITLE must be a character string"); + if (! ischar (varargin{1})) + error ("inputdlg: TITLE must be a character string"); endif + title = varargin{1}; endif linespec = 1; @@ -104,7 +104,7 @@ ## r2 2 20 second text field is 2x20 ## r3 3 30 third text field is 3x30 if (! isnumeric (linespec)) - error ("ROWSCOLS must be numeric"); + error ("inputdlg: ROWSCOLS must be numeric"); endif if (isscalar (linespec)) @@ -121,18 +121,18 @@ rowscols(:,2) = 25; rowscols(:,1) = linespec(:); else - error ("ROWSCOLS vector does not match size of PROMPT"); + error ("inputdlg: ROWSCOLS vector does not match size of PROMPT"); endif elseif (ismatrix (linespec)) if (rows (linespec) == columns (prompt) && columns (linespec) == 2) ## (rows x columns) match, copy array linespec rowscols = linespec; else - error ("ROWSCOLS matrix does not match size of PROMPT"); + error ("inputdlg: ROWSCOLS matrix does not match size of PROMPT"); endif else ## dunno - error ("unknown form of ROWSCOLS argument"); + error ("inputdlg: unknown form of ROWSCOLS argument"); endif rowscols = ceil (rowscols); @@ -140,7 +140,7 @@ defs = cellfun (@num2str, defaults, "UniformOutput", false); if (__octave_link_enabled__ ()) - cstr = __octave_link_input_dialog__ (prompt, dlg_title, rowscols, defs); + cstr = __octave_link_input_dialog__ (prompt, title, rowscols, defs); else error ("inputdlg is not available in this version of Octave"); endif @@ -150,7 +150,7 @@ %!demo %! disp ('- test inputdlg with prompt and caption only.'); -%! prompt = {'Width','Height','Depth'}; +%! prompt = {'Width', 'Height', 'Depth'}; %! dims = inputdlg (prompt, 'Enter Box Dimensions'); %! if (isempty (dims)) %! helpdlg ('Canceled by user', 'Information'); @@ -159,15 +159,16 @@ %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... %! str2num (dims{2}) * str2num (dims{3}) + ... %! str2num (dims{1}) * str2num (dims{3})); -%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); +%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ... +%! volume, surface), 'Box Dimensions'); %! end %!demo %! disp ('- test inputdlg with prescribed scalar (2 lines per text field) and defaults.'); -%! prompt = {'Width','Height','Depth'}; -%! default = {'1.1','2.2','3.3'}; +%! prompt = {'Width', 'Height', 'Depth'}; +%! default = {'1.1', '2.2', '3.3'}; %! rc = 2; -%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); +%! dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default); %! if (isempty (dims)) %! helpdlg ('Canceled by user', 'Information'); %! else @@ -175,15 +176,16 @@ %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... %! str2num (dims{2}) * str2num (dims{3}) + ... %! str2num (dims{1}) * str2num (dims{3})); -%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); +%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ... +%! volume, surface), 'Box Dimensions'); %! end %!demo %! disp ('- test inputdlg with prescribed vector [1,2,3] for # of lines per text field and defaults.'); -%! prompt = {'Width','Height','Depth'}; +%! prompt = {'Width', 'Height', 'Depth'}; %! default = {'1.10', '2.10', '3.10'}; %! rc = [1,2,3]; % NOTE: must be an array -%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); +%! dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default); %! if (isempty (dims)) %! helpdlg ('Canceled by user', 'Information'); %! else @@ -191,15 +193,16 @@ %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... %! str2num (dims{2}) * str2num (dims{3}) + ... %! str2num (dims{1}) * str2num (dims{3})); -%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); +%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ... +%! volume, surface), 'Box Dimensions'); %! end %!demo %! disp ('- test inputdlg with prescribed row by column sizes and defaults.'); -%! prompt = {'Width','Height','Depth'}; +%! prompt = {'Width', 'Height', 'Depth'}; %! default = {'1.10', '2.20', '3.30'}; %! rc = [1,10; 2,20; 3,30]; % NOTE: must be an array -%! dims = inputdlg (prompt, 'Enter Box Dimensions',rc,default); +%! dims = inputdlg (prompt, 'Enter Box Dimensions', rc, default); %! if (isempty (dims)) %! helpdlg ('Canceled by user', 'Information'); %! else @@ -207,12 +210,14 @@ %! surface = 2 * (str2num (dims{1}) * str2num (dims{2}) + ... %! str2num (dims{2}) * str2num (dims{3}) + ... %! str2num (dims{1}) * str2num (dims{3})); -%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', volume, surface), 'Box Dimensions'); +%! helpdlg (sprintf ('Results:\nVolume = %.3f\nSurface = %.3f', ... +%! volume, surface), 'Box Dimensions'); %! end -%!error<narginchk> inputdlg (1, 2, 3, 4, 5) -%!error<PROMPT must be a character string> inputdlg (1) -%!error<TITLE must be a character string> inputdlg ("msg", 1) -%!error<ROWSCOLS must be numeric> inputdlg ("msg", "title", "1") -%!error<ROWSCOLS vector does not match size> -%! inputdlg ({"a1", "a2"}, "title", [1, 2, 3]) +%!error inputdlg (1, 2, 3, 4, 5) +%!error <PROMPT must be a character string> inputdlg (1) +%!error <TITLE must be a character string> inputdlg ("msg", 1) +%!error <ROWSCOLS must be numeric> inputdlg ("msg", "title", "1") +%!error <ROWSCOLS vector does not match size> +%! inputdlg ({"a1", "a2"}, "title", [1, 2, 3]); + diff -r a3a412dee704 -r 59ebef9680ef scripts/gui/listdlg.m --- a/scripts/gui/listdlg.m Wed Apr 20 15:29:35 2016 -0700 +++ b/scripts/gui/listdlg.m Wed Apr 20 15:54:37 2016 -0700 @@ -19,22 +19,22 @@ ## -*- texinfo -*- ## @deftypefn {} {[@var{sel}, @var{ok}] =} listdlg (@var{key}, @var{value}, @dots{}) ## Return user inputs from a list dialog box in a vector of selection indices -## @var{sel} and a flag @var{ok} indicating how the user closed the dialog -## box. +## (@var{sel}) and a flag indicating how the user closed the dialog box +## (@var{ok}). +## +## The indices in @var{sel} are 1-based. ## ## The value of @var{ok} is 1 if the user closed the box with the OK button, ## otherwise it is 0 and @var{sel} is empty. ## -## The indices in @var{sel} are 1-based. -## -## The arguments are specified in form of @var{key}, @var{value} pairs. +## Input arguments are specified in form of @var{key}, @var{value} pairs. ## The @qcode{"ListString"} argument pair must be specified. ## ## Valid @var{key} and @var{value} pairs are: ## ## @table @asis ## @item @qcode{"ListString"} -## a cell array of strings comprising the content of the list. +## a cell array of strings with the contents of the list. ## ## @item @qcode{"SelectionMode"} ## can be either @qcode{"Single"} or @qcode{"Multiple"} (default). @@ -88,6 +88,10 @@ print_usage (); endif + if (mod (nargin, 2) != 0) + error ("listdlg: KEY/VALUE inputs must occur in pairs"); + endif + listcell = {""}; selmode = "multiple"; listsize = [160, 300]; @@ -115,12 +119,13 @@ okstring = varargin{i+1}; elseif (strcmpi (varargin{i}, "CancelString")) cancelstring = varargin{i+1}; + else + error ("listdlg: invalid KEY <%s>", varargin{i}); endif endfor - ## make sure prompt strings are a cell array - if (! iscell (prompt)) - prompt = {prompt}; + if (isempty (listcell)) + error ("listdlg: ListString must not be empty"); endif ## make sure listcell strings are a cell array @@ -130,7 +135,12 @@ listcell = listcell{1}; endif - ## make sure valid selection mode + ## make sure prompt strings are a cell array + if (! iscell (prompt)) + prompt = {prompt}; + endif + + ## validate selection mode if (! strcmp (selmode, "multiple") && ! strcmp (selmode, "single")) error ("listdlg: invalid SelectionMode"); endif @@ -178,3 +188,13 @@ %! for i=1:1:imax %! disp (["Selected: ", num2str(i), ": ", itemlist{s(i)}]); %! end + +## Test input validation +%!error listdlg () +%!error listdlg ("SelectionMode") +%!error <must occur in pairs> listdlg ("SelectionMode", "multiple", "Name") +%!error <invalid KEY .FooBar.> listdlg ("FooBar", 1) +%!error <ListString must not be empty> listdlg ("ListString", {}) +%!error <invalid SelectionMode> +%! listdlg ("ListString", {"A"}, "SelectionMode", "foobar"); + diff -r a3a412dee704 -r 59ebef9680ef scripts/gui/questdlg.m --- a/scripts/gui/questdlg.m Wed Apr 20 15:29:35 2016 -0700 +++ b/scripts/gui/questdlg.m Wed Apr 20 15:54:37 2016 -0700 @@ -25,13 +25,13 @@ ## Display @var{msg} using a question dialog box and return the caption of ## the activated button. ## -## The dialog may contain two or three buttons which will all close the dialog. -## ## The message may have multiple lines separated by newline characters ("\n"), ## or it may be a cellstr array with one element for each line. ## -## The optional @var{title} (character string) can be used to decorate the -## dialog caption. +## The optional @var{title} (character string) can be used to specify the +## dialog caption. It defaults to @qcode{"Question Dialog"}. +## +## The dialog may contain two or three buttons which will all close the dialog. ## ## The string @var{default} identifies the default button, which is activated ## by pressing the @key{ENTER} key. It must match one of the strings given @@ -64,16 +64,16 @@ endif if (! ischar (msg)) - if (iscell (msg)) - msg = sprintf ("%s\n", msg{:}); - msg(end) = ""; - else + if (! iscell (msg)) error ("questdlg: MSG must be a character string or cellstr array"); endif + + msg = sprintf ("%s\n", msg{:}); + msg(end) = ""; endif if (! ischar (title)) - error ("questdlg: TITLES must be a character string"); + error ("questdlg: TITLE must be a character string"); endif options{1} = "Yes"; # button1 @@ -114,9 +114,6 @@ error (defbtn_error_msg); endif - otherwise - print_usage (); - endswitch if (__octave_link_enabled__ ()) @@ -180,3 +177,15 @@ %! endif %! endif %! endif + +## Test input validation +%!error questdlg () +%!error questdlg (1,2,3,4,5,6,7) +%!error <MSG must be a character string or cellstr array> questdlg (1) +%!error <TITLE must be a character string> questdlg ("msg", 1) +%!error <DEFAULT must match one of the button> questdlg ("msg", "title", "ABC") +%!error <DEFAULT must match one of the button> +%! questdlg ("msg", "title", "btn1", "btn2", "ABC"); +%!error <DEFAULT must match one of the button> +%! questdlg ("msg", "title", "btn1", "btn2", "btn3", "ABC"); + diff -r a3a412dee704 -r 59ebef9680ef scripts/gui/warndlg.m --- a/scripts/gui/warndlg.m Wed Apr 20 15:29:35 2016 -0700 +++ b/scripts/gui/warndlg.m Wed Apr 20 15:54:37 2016 -0700 @@ -21,10 +21,11 @@ ## @deftypefnx {} {@var{h} =} warndlg (@var{msg}) ## @deftypefnx {} {@var{h} =} warndlg (@var{msg}, @var{title}) ## @deftypefnx {} {@var{h} =} warndlg (@var{msg}, @var{title}, @var{createmode}) -## Display warning message @var{msg} using a warning dialog box with caption -## @var{title} (character string). The default warning message is -## @qcode{"This is the default warning string."} and the default caption is -## @qcode{"Warning Dialog"}. +## Display a warning dialog box with warning message @var{msg} and caption +## @var{title}. +## +## The default warning message is @qcode{"This is the default warning string."} +## and the default caption is @qcode{"Warning Dialog"}. ## ## The warning message may have multiple lines separated by newline characters ## ("\n"), or it may be a cellstr array with one element for each line. @@ -53,24 +54,26 @@ narginchk (0, 3); - box_msg = "This is the default warning string."; - box_title = "Warning Dialog"; + msg = "This is the default warning string."; + title = "Warning Dialog"; if (nargin > 0) - box_msg = varargin{1}; + msg = varargin{1}; endif if (nargin > 1) - box_title = varargin{2}; + title = varargin{2}; endif if (nargin < 3) - retval = msgbox (box_msg, box_title, "warn"); + retval = msgbox (msg, title, "warn"); else - retval = msgbox (box_msg, box_title, "warn", varargin{3}); + retval = msgbox (msg, title, "warn", varargin{3}); endif endfunction -%!error<narginchk> warndlg (1, 2, 3, 4) -%!error<MSG must be a character string> warndlg (1) -%!error<TITLE must be a character string> warndlg ("msg", 1) + +%!error warndlg (1, 2, 3, 4) +%!error <MSG must be a character string> warndlg (1) +%!error <TITLE must be a character string> warndlg ("msg", 1) +