closeRequestFcn: how do I distinguish if it is called by a mouse click to window's close button vs a close() command??
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
John Iversen
am 8 Aug. 2014
Kommentiert: John Iversen
am 11 Apr. 2015
I am writing a custom closeRequestFcn
I would like it to do different things depending if it is called because the user
1) clicked the close button on the figure -- clearly they want to close this figure, so let them
2) called e.g. close all to close all figures -- in this case do not close this figure
Note I can't use the handle visibility property, as the figure needs to be accessible for other reasons.
What I've tried: the event argument passed to the callback is the same in these cases the figures CurrentPoint property is the same in both cases
Any ideas? Java magic? some other property to test?
Thanks!
0 Kommentare
Akzeptierte Antwort
Jan
am 10 Aug. 2014
Bearbeitet: Jan
am 10 Aug. 2014
The most direct solution would be to avoid the brute close all, when you do not want to close all figures. The idea of calling "close all except for the one I do not mean" is magic.
Checking the value of gcbf does not help, because it is set by close all also.
But you can check if one of the calling function is close by dbstack:
Stack = dbstack;
Caller = {Stack.name};
calledByClose = any(strcmp(Caller, 'close'))
But I repeat that this is magic, because the CloseRequest function tries to guess, what the user really wants instead of the commands he types. This is beyond an intuition and other users of your code will tend to desperate when they try to close the figure.
What about setting a flag e.g. in the figure's Application data and create a personal function for closing all figures, which do not contain this flag?
function smartCloseAll % Choose a more convenient name...
FigList = allchild(0);
for iFig = 1:length(FigList)
aFig = FigList(iFig);
AppData = getappdata(aFig);
kill = true;
if isfield(AppData, 'myCloseRejectFlag')
kill = not(AppData.myCloseRejectFlag)
end
if kill
close(aFig);
end
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!