Mercurial > octave
changeset 24429:127110fc42c6
linkprop.m: Overhaul function.
* linkprop.m: Add "addlistener" to seealso link. Don't bother to make
column vector of input handles. Rename all callbacks to start with "cb_".
* linkprop.m (unlink_linkprop): Trim list of valid handles outside of
for loop for performance.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 18 Dec 2017 19:21:12 -0800 |
parents | 3472c6760ad2 |
children | e1651094f68b |
files | scripts/plot/util/linkprop.m |
diffstat | 1 files changed, 12 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/util/linkprop.m Mon Dec 18 17:30:48 2017 -0800 +++ b/scripts/plot/util/linkprop.m Mon Dec 18 19:21:12 2017 -0800 @@ -30,10 +30,10 @@ ## the first object in the list @var{h}. ## ## The function returns @var{hlink} which is a special object describing the -## link. As long as the reference @var{hlink} exists the link between graphic +## link. As long as the reference @var{hlink} exists, the link between graphic ## objects will be active. This means that @var{hlink} must be preserved in ## a workspace variable, a global variable, or otherwise stored using a -## function such as @code{setappdata}, @code{guidata}. To unlink properties, +## function such as @code{setappdata} or @code{guidata}. To unlink properties, ## execute @code{clear @var{hlink}}. ## ## An example of the use of @code{linkprop} is @@ -51,7 +51,7 @@ ## @end group ## @end example ## -## @seealso{linkaxes} +## @seealso{linkaxes, addlistener} ## @end deftypefn function hlink = linkprop (h, prop) @@ -72,7 +72,7 @@ error ("linkprop: PROP must be a string or cell string array"); endif - h = h(:)'; # set() prefers column vectors + h = h(:); ## Match all objects to the first one in the list before linking for j = 1 : numel (prop) set (h(2:end), prop{j}, get (h(1), prop{j})); @@ -82,15 +82,15 @@ for i = 1 : numel (h) for j = 1 : numel (prop) addlistener (h(i), prop{j}, - {@update_prop, [h(1:i-1),h(i+1:end)], prop{j}}); + {@cb_sync_prop, [h(1:i-1), h(i+1:end)], prop{j}}); endfor endfor - hlink = onCleanup (@() delete_linkprop (h, prop)); + hlink = onCleanup (@() unlink_linkprop (h, prop)); endfunction -function update_prop (h, ~, hlist, prop) +function cb_sync_prop (h, ~, hlist, prop) persistent recursion = false; ## Don't allow recursion @@ -105,14 +105,13 @@ endfunction -function delete_linkprop (hlist, prop) +function unlink_linkprop (hlist, prop) + hlist = hlist(ishghandle (hlist)); for i = 1 : numel (hlist) - if (ishghandle (hlist(i))) - for j = 1 : numel (prop) - dellistener (hlist(i), prop{j}); - endfor - endif + for j = 1 : numel (prop) + dellistener (hlist(i), prop{j}); + endfor endfor endfunction