Closing window

Hello, quick question: when the user clicks on the “close” window button, it is not equivalent to a “close” menu command. How can I make these actions equivalent? That is, send a “close” menu command when the user clicks on the button?
I guess it’s trivial.

Something like that (after declaring my app as window’s delegate):

    on windowShouldClose_(sender)
        if sender is myMainWindow then closeMainWindow_(sender)
        return true
    end windowShouldClose_

?

When closing a window from the menu it will be closed by the performClose: method of the front most window of your application. So pressing the button or choosing from menu is the same action. They both are a performClose: method. So I don’t really understand your question.

And which object receives this performClose_ command? The window? When you make the application the delegate of the window (if it makes sense to do so) will the app receive a message? a notification?

To make it clear: my app performs automatic saving of the window’s contents when the user choose “Close” or “Quit” menu command – but if he closes the window by clicking the red button on the window’s bar, my handlers are not called. How make this happen? The lines I wrote above do the trick, but is there another way?

The window receives the performClose:

Also the window’s delegate ‘should close window’ will be called (only when the user presses the red button or performClose: method is called). If you’re telling the window to close (don’t know if you coded that somewhere) this delegate is not handled. If you quit the application a close is send and not the performClose:. Here you should use the delegate ‘application should terminate’ or to save states of a window ‘window will close’ should be used.

should delegates should be used when you want to give the user a change to cancel the operation like ‘there are some unsaved changes, do you wish to save?’. When the user has confirmed everything, in other words there is no going back, you should use the will delegates to save your last bits.

Ok - so my handler is correct: I don’t present to the user the “Save?” dialog, but I save the contents automatically (it’s a feature of my app, as the users are 12-13 year old)…

I read somewhere that a click on the button makes the window send a preformClose_ to itself, this way seemed a bit selfish to me :slight_smile:

Thanks for your answers, anyway. Read you soon.

Regards