How can I organize the "Window" menu?
I have a document based application. Every document can have multiple windows. Every window is automatically added to the "Window" menu. However, they are added in a more or less random and useless order. I would like the window titles to be organized according to the NSDocument they belong to, similar to how XCode or Photoshop do it.
How can I best do that? How can I prevent the default behaviour of AppKit to add all windows to开发者_开发问答 this special menu, and where should I put the code that adds the menu items in the "correct" manner? I don't want to put handlers into every window controller!
It sure does seem like this is something Cocoa should do automatically. I don't know whether it does, but the first thing to check is whether the window controllers are properly connected to their documents. Does your document subclass's windowControllers
property contain all the right objects?
If that's no good, then from NSWindow's reference it looks like the only way to prevent a window whose title has been set from being added to the Windows
menu is -[NSWindow setExcludedFromWindowsMenu:]
. It looks like you'll want to call that on all your windows, then set up an object (perhaps in the MainMenu
nib) that takes care of all the windows' positions and grouping in the Windows
menu (via NSApplication
's methods). You may need to put in special disabled items and the like to get the grouping to look right. I would hope that windows could still be manually added even if you've previously asked them to be excluded.
精彩评论