# HG changeset patch # User Rik # Date 1429717310 25200 # Node ID 7e0e8fb16201bd7a5888b4bd60add61d864a6a71 # Parent 5f0cb9bb6a50ba1e75300e08643d64d0a6d8b34d Overhaul close.m to add "force" argument (bug #44324) * close.m: Emit an error if there is no figure handle or "all" argument given. Check for "force" argument and delete the requested figure handles rather than calling closereqfcn. Add BIST input validation tests. Add new calling forms and explanation of "force" to docstring. diff -r 5f0cb9bb6a50 -r 7e0e8fb16201 scripts/plot/util/close.m --- a/scripts/plot/util/close.m Wed Apr 22 07:05:23 2015 -0500 +++ b/scripts/plot/util/close.m Wed Apr 22 08:41:50 2015 -0700 @@ -19,8 +19,10 @@ ## -*- texinfo -*- ## @deftypefn {Command} {} close ## @deftypefnx {Command} {} close (@var{h}) +## @deftypefnx {Command} {} close @var{h} ## @deftypefnx {Command} {} close all ## @deftypefnx {Command} {} close all hidden +## @deftypefnx {Command} {} close all force ## Close figure window(s). ## ## When called with no arguments, close the current figure. This is equivalent @@ -33,6 +35,10 @@ ## If the argument @qcode{"all hidden"} is given then all figures, including ## hidden ones, are closed. ## +## If the argument @qcode{"all force"} is given then all figures are closed +## even when @qcode{"closerequestfcn"} has been altered to prevent closing +## the window. +## ## Implementation Note: @code{close} operates by calling the function specified ## by the @qcode{"closerequestfcn"} property for each figure. By default, the ## function @code{closereq} is used. It is possible that the function invoked @@ -63,19 +69,25 @@ if (ischar (arg1) && strcmpi (arg1, "all")) figs = (get (0, "children"))'; figs = figs(isfigure (figs)); - elseif (isfigure (arg1)) - figs = arg1; - elseif (isempty (arg1)) - figs = []; + elseif (any (isfigure (arg1))) + figs = arg1(isfigure (arg1)); else error ('close: first argument must be "all" or a figure handle'); endif - elseif ( ischar (arg1) && strcmpi (arg1, "all") - && ischar (arg2) && strcmpi (arg2, "hidden")) - figs = (allchild (0))'; - figs = figs(isfigure (figs)); + elseif (ischar (arg2) + && (strcmpi (arg2, "hidden") || strcmpi (arg2, "force"))) + if (ischar (arg1) && strcmpi (arg1, "all")) + figs = (allchild (0))'; + figs = figs(isfigure (figs)); + else + error ('close: first argument must be "all" with "hidden" or "force"'); + endif + if (strcmpi (arg2, "force")) + delete (figs); + return; + endif else - error ('close: expecting argument to be "all hidden"'); + error ('close: second argument must be "hidden" or "force"'); endif for h = figs @@ -101,8 +113,13 @@ %! endif %! end_unwind_protect +## Test input validation %!error close (1,2,3) %!error close ({"all"}) %!error close ("all_and_more") %!error close (-1) -%!error close all hid +%!error close foo hidden +%!error close foo force +%!error close all hid +%!error close all for +