Mercurial > octave-antonio
comparison scripts/plot/util/close.m @ 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 | 4197fc428c7d |
children | 3797df921988 |
comparison
equal
deleted
inserted
replaced
20114:5f0cb9bb6a50 | 20115:7e0e8fb16201 |
---|---|
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Command} {} close | 20 ## @deftypefn {Command} {} close |
21 ## @deftypefnx {Command} {} close (@var{h}) | 21 ## @deftypefnx {Command} {} close (@var{h}) |
22 ## @deftypefnx {Command} {} close @var{h} | |
22 ## @deftypefnx {Command} {} close all | 23 ## @deftypefnx {Command} {} close all |
23 ## @deftypefnx {Command} {} close all hidden | 24 ## @deftypefnx {Command} {} close all hidden |
25 ## @deftypefnx {Command} {} close all force | |
24 ## Close figure window(s). | 26 ## Close figure window(s). |
25 ## | 27 ## |
26 ## When called with no arguments, close the current figure. This is equivalent | 28 ## When called with no arguments, close the current figure. This is equivalent |
27 ## to @code{close (gcf)}. If the input @var{h} is a graphic handle, or vector | 29 ## to @code{close (gcf)}. If the input @var{h} is a graphic handle, or vector |
28 ## of graphics handles, then close each figure in @var{h}. | 30 ## of graphics handles, then close each figure in @var{h}. |
30 ## If the argument @qcode{"all"} is given then all figures with visible handles | 32 ## If the argument @qcode{"all"} is given then all figures with visible handles |
31 ## (HandleVisibility = @qcode{"on"}) are closed. | 33 ## (HandleVisibility = @qcode{"on"}) are closed. |
32 ## | 34 ## |
33 ## If the argument @qcode{"all hidden"} is given then all figures, including | 35 ## If the argument @qcode{"all hidden"} is given then all figures, including |
34 ## hidden ones, are closed. | 36 ## hidden ones, are closed. |
37 ## | |
38 ## If the argument @qcode{"all force"} is given then all figures are closed | |
39 ## even when @qcode{"closerequestfcn"} has been altered to prevent closing | |
40 ## the window. | |
35 ## | 41 ## |
36 ## Implementation Note: @code{close} operates by calling the function specified | 42 ## Implementation Note: @code{close} operates by calling the function specified |
37 ## by the @qcode{"closerequestfcn"} property for each figure. By default, the | 43 ## by the @qcode{"closerequestfcn"} property for each figure. By default, the |
38 ## function @code{closereq} is used. It is possible that the function invoked | 44 ## function @code{closereq} is used. It is possible that the function invoked |
39 ## will delay or abort removing the figure. To remove a figure without | 45 ## will delay or abort removing the figure. To remove a figure without |
61 endif | 67 endif |
62 elseif (nargin == 1) | 68 elseif (nargin == 1) |
63 if (ischar (arg1) && strcmpi (arg1, "all")) | 69 if (ischar (arg1) && strcmpi (arg1, "all")) |
64 figs = (get (0, "children"))'; | 70 figs = (get (0, "children"))'; |
65 figs = figs(isfigure (figs)); | 71 figs = figs(isfigure (figs)); |
66 elseif (isfigure (arg1)) | 72 elseif (any (isfigure (arg1))) |
67 figs = arg1; | 73 figs = arg1(isfigure (arg1)); |
68 elseif (isempty (arg1)) | |
69 figs = []; | |
70 else | 74 else |
71 error ('close: first argument must be "all" or a figure handle'); | 75 error ('close: first argument must be "all" or a figure handle'); |
72 endif | 76 endif |
73 elseif ( ischar (arg1) && strcmpi (arg1, "all") | 77 elseif (ischar (arg2) |
74 && ischar (arg2) && strcmpi (arg2, "hidden")) | 78 && (strcmpi (arg2, "hidden") || strcmpi (arg2, "force"))) |
75 figs = (allchild (0))'; | 79 if (ischar (arg1) && strcmpi (arg1, "all")) |
76 figs = figs(isfigure (figs)); | 80 figs = (allchild (0))'; |
81 figs = figs(isfigure (figs)); | |
82 else | |
83 error ('close: first argument must be "all" with "hidden" or "force"'); | |
84 endif | |
85 if (strcmpi (arg2, "force")) | |
86 delete (figs); | |
87 return; | |
88 endif | |
77 else | 89 else |
78 error ('close: expecting argument to be "all hidden"'); | 90 error ('close: second argument must be "hidden" or "force"'); |
79 endif | 91 endif |
80 | 92 |
81 for h = figs | 93 for h = figs |
82 __go_execute_callback__ (h, "closerequestfcn"); | 94 __go_execute_callback__ (h, "closerequestfcn"); |
83 endfor | 95 endfor |
99 %! if (isfigure (hf)) | 111 %! if (isfigure (hf)) |
100 %! close (hf); | 112 %! close (hf); |
101 %! endif | 113 %! endif |
102 %! end_unwind_protect | 114 %! end_unwind_protect |
103 | 115 |
116 ## Test input validation | |
104 %!error close (1,2,3) | 117 %!error close (1,2,3) |
105 %!error <first argument must be "all" or a figure> close ({"all"}) | 118 %!error <first argument must be "all" or a figure> close ({"all"}) |
106 %!error <first argument must be "all" or a figure> close ("all_and_more") | 119 %!error <first argument must be "all" or a figure> close ("all_and_more") |
107 %!error <first argument must be "all" or a figure> close (-1) | 120 %!error <first argument must be "all" or a figure> close (-1) |
108 %!error <expecting argument to be "all hidden"> close all hid | 121 %!error <first argument must be "all" with "hidden"> close foo hidden |
122 %!error <first argument must be "all" with "hidden"> close foo force | |
123 %!error <second argument must be "hidden"> close all hid | |
124 %!error <second argument must be "hidden"> close all for | |
125 |