closing a window

I want to have cmd+w close the front most open window. any help would be appreciated.

  1. I set up the shortcut in the main menu
    MainMenuBar
    FileMenu
    FileQuit
    CloseWindow > cmd+w

  2. I add a menu handler to a window, this works
    about_window
    menu Handler
    closewindow
    about_window.Close()
    Return True

  3. THIS DOES NOT WORK, it closes the about_window in #2 above
    video_window
    menu Handler
    close window
    VideoWindow.Close()
    Return True

the CLOSE event/ menu handler for any window would normally only contain

self.close

using the name of a window … videowindow.close
implies that there is only ever one window of that name. (Implicit instantiation)

But for many apps, you dont use ‘the’ videowindow
You use ‘a’ videowindow, created like this:

MyWindow = new videowindow

The newly created window wont react to videowindow.close
It will close on MyWindow.close
And its close menu handle should just say self.close so it works no matter what you called it

made both windows self.close and ONLY the ‘about’ closed.
just found out by accident that cmd+. closes the ‘video’ window
what the heck, how did it get THAT functionality

I assigned both windows to use the MainMenuBar…still doesn’t work. ©ƒ?´?®?£†¨¨?¨?••´?´?ç?ø

  1. I add a menu handler to a window, this works
    about_window
    menu Handler
    closewindow
    about_window.Close() // This should be Self.Close()
    Return True

  2. THIS DOES NOT WORK, it closes the about_window in #2 above
    video_window
    menu Handler
    close window // This should be closewindow (remove the space between the two words)
    VideoWindow.Close() // This should be Self.Close()
    Return True

I did what you said and it still does not work.
I made both windows have MainMenuBar as the Menu Bar.

video window

about window

Does the App have a closeWindow handler too?
Have you put breakpoints on to check the program flow?

  • Add a WindowMenu to MainMenuBar, title Window (this is conformant to Apple Human Interface Guidelines)
  • In the WindowMenu, add an item WindowClose, Text Close, Key W, Modifier On.
  • Add a WindowClose menu handler to your window. In there :
self.close

That’s it.