How can I organize the window menu?

I have a document based application. Each document can have several windows. Each window is automatically added to the Window menu. However, they are added in a more or less random and useless manner. I would like the window headers to be organized according to the NSDocument to which they belong, just like Xcode or Photoshop do.

How can i do this? How can I prevent the default behavior of AppKit to add all the windows to this special menu, and where should I put code that adds menu items in the β€œcorrect” way? I do not want to put handlers in every window controller!

+4
source share
1 answer

Of course, it looks like this is what Cocoa should do automatically. I do not know if this does, but the first thing to check is whether the window controllers are correctly connected to their documents. windowControllers property of your subclass of the document windowControllers contain all the necessary objects?

If this is not good, then from the NSWindow link it looks like the only way to prevent the appearance of a window whose name was added from the Windows menu -[NSWindow setExcludedFromWindowsMenu:] . It looks like you want to call it on all of your windows, and then set up an object (possibly in MainMenu nib) that takes care of all the positions and grouping of windows in the Windows menu (via NSApplication ). You may need to add special elements, etc., so that the group looks right. I hope that windows can be added manually, even if you previously requested to exclude them.

+1
source

All Articles