How know if windowWillClose: is invoked by X button click

Is there any way to tell if the user clicked X button in windowWillClose delegate method?

- (void)windowWillClose:(NSNotification *)notification

Did you try changing the action of the close button ? And set a global variable closedByUser to true

https://stackoverflow.com/questions/7237445/override-nswindow-close-button

Then you can use closedByUser in windoWillClose to do what you want (and reset closedByUser to false)

You can also implement the method windowShouldClose: which tells the delegate that the user has attempted to close a window or the window has received a performClose: message.

It's not called when a user quits an application, just when they close it.

How know if windowWillClose: is invoked by X button click
 
 
Q