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!