MOExtendedMenuItem


MOExtendedMenuItem is a subclass of NSMenuItem that adds support for a "default" state.
Superclass: NSMenuItem



MOExtendedMenuItem is a subclass of NSMenuItem that adds support for a "default" state. This helps to solve the problem of what happens to menus that change title or other properties via validation methods when there's sometimes no valid target for the items.

For example, you might have a "Save" command that sends a -saveDocument: action to the first responder. Wouldn't it be cool if the menu item actually said "Save "? You can easily do this by adding a -validateMenuItem: method to your document class that sets the menu item's title. The problem is that when there is no active document, the menu item will be disabled, but it will still say "Save " with the document name of the last active document!

MOExtendedMenuItem and MOExtendedMenu cooperate to prevent this. MOExtendedMenuItem has a -defaultTitle (as well as other default state). MOExtendedMenu will revert each item in it to the default state at the beginning of its -update method. If a -validateMenuItem: changes it again, cool, but if not, the default state sticks.

MOExtendedMenuItem will automatically set its default state during awakeFromNib. So all you have to do is make sure that your menu items have their generic default state in your main nib.

You can use MOExtendedMenuItem in a couple ways. You could individually mark your menus and items in a nib file as being the MOExtendedMenuItem and MOExtendedMenu subclasses. Or you can simply call +[MOExtendedMenuItem enableRevertToDefaultItemState] in your application's main() before calling NSApplicationMain and it will arrange to have everything work automatically.



(Last Updated 3/20/2005)
HTML documentation generated by HeaderDoc