Mac Developer Library

Developer

AppKit Framework Reference NSToolbarItemValidation Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSToolbarItemValidation

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.

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.
  • If this method is implemented and returns NOfalse, NSToolbar will disable theItem; returning YEStrue causes theItem to be enabled.

    Declaration

    Swift

    func validateToolbarItem(_ theItem: NSToolbarItem) -> Bool

    Objective-C

    - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – validateVisibleItems (NSToolbar)
    – validate (NSToolbarItem)
    – target (NSToolbarItem)
    – action (NSToolbarItem)