(informal protocol)
Framework | /System/Library/Frameworks/AppKit.framework |
Companion guide | |
Declared in | NSToolbarItem.h |
A toolbar item with a valid target and action is enabled by default. To allow a toolbar item to be disabled in certain situations, a toolbar item’s target can implement the validateToolbarItem:
method.
Note: NSToolbarItem’s validate
method calls this method only if the item’s target has a valid action defined on its target and if the item is not a custom view item. If you want to validate a custom view item, then you have to subclass NSToolbarItem and override validate
.
If this method is implemented and returns NO
, NSToolbar will disable theItem; returning YES
causes theItem to be enabled.
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
NSToolbar only calls this method for image items.
If the receiver is the target
for the actions of multiple toolbar items, it’s necessary to determine which toolbar item theItem refers to by testing the itemIdentifier
.
-(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem |
{ |
BOOL enable = NO; |
if ([[toolbarItem itemIdentifier] isEqual:SaveDocToolbarItemIdentifier]) { |
// We will return YES (enable the save item) |
// only when the document is dirty and needs saving |
enable = [self isDocumentEdited]; |
} else if ([[toolbarItem itemIdentifier] isEqual:NSToolbarPrintItemIdentifier]) { |
// always enable print for this window |
enable = YES; |
} |
return enable; |
} |
– validateVisibleItems
(NSToolbar)– validate
(NSToolbarItem)– target
(NSToolbarItem)– action
(NSToolbarItem)NSToolbarItem.h
© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-05-23)