Instance Method

validateToolbarItem(_:)

If this method is implemented and returns false, NSToolbar will disable theItem; returning true causes theItem to be enabled.

Declaration

func validateToolbarItem(_ item: NSToolbarItem) -> Bool

Discussion

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;
}

See Also

Related Symbols

func validateVisibleItems()

Called on window updates to validate the visible items.

var action: Selector?

The receiver’s action.

var target: AnyObject?

The receiver’s target.

func validate()

This method is called by the receiver’s toolbar during validation.