closeRequestFcn: how do I distinguish if it is called by a mouse click to window's close button vs a close() command??
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2014-8-10
编辑:Jan
2014-8-10
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!