changeset 20115:7e0e8fb16201

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.
author Rik <rik@octave.org>
date Wed, 22 Apr 2015 08:41:50 -0700
parents 5f0cb9bb6a50
children 33e706b6b7be
files scripts/plot/util/close.m
diffstat 1 files changed, 27 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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 <first argument must be "all" or a figure> close ({"all"})
 %!error <first argument must be "all" or a figure> close ("all_and_more")
 %!error <first argument must be "all" or a figure> close (-1)
-%!error <expecting argument to be "all hidden"> close all hid
+%!error <first argument must be "all" with "hidden"> close foo hidden
+%!error <first argument must be "all" with "hidden"> close foo force
+%!error <second argument must be "hidden"> close all hid
+%!error <second argument must be "hidden"> close all for
+