on windoe close set MenuItem State

Hi all,

I am running into a little problem with most of my appications:
I have a main window and if a user clicks the red X the window closes, but the application stays open.

So there are 2 ways of dealing with this, none of them worked for me … :frowning:

(1) quit application if you click the red x

on applicationShouldTerminateAfterLastWindowClosed_(sender)
       return true
   end applicationShouldTerminateAfterLastWindowClosed_

→ I have an app with 2 windows → a Window and a Panel if both are open, the application will quit even if I just close one window, but I would actually want it to quit ONLY when pressing close on the main window.

(2) MenuItem to bring main window back

-- action attached to menu item in IB
    on showWin_(sender)
        tell showWinMenu to setState_(true)
        theWindow's orderFront_(me)
    end showWin_

→ I would want to set the state of that MenuItem to false if the user closes the window by pressing the red (X) → where could I do that?

So one of those would be great for me.



connect the delegate of the (main) window to your Appdelegate script and
implement the windowWillClose_(notification) delegate method.
It will be called just before the window closes. There call NSApp’s terminate_(me)
or set the menu item stuff.

The notification object contains the reference to the caller window

The missing connection was where I got stuck.
Thanks! As always works like a charm. :slight_smile: