• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Have to subclass NSToolbarItem to be able to disable it?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Have to subclass NSToolbarItem to be able to disable it?


  • Subject: Re: Have to subclass NSToolbarItem to be able to disable it?
  • From: Ryan Bates <email@hidden>
  • Date: Wed, 18 Feb 2004 09:46:52 -0800

On Feb 18, 2004, at 9:03 AM, Guy Umbright wrote:
Specifically, I would like to enable/disable a toolbar
item based on the state of the selection in an NSTableView
in the window. I tried using setEnabled to control the
state, but it always get reset to enabled. From what I
can tell, I need to create a subclass of NSToolbarItem
so that I can override validate:, the default of which
always sets enabled?

Enabling/disabling NSToolbarItems works very similar to menus. The object which handles the action also controls the validation. For example, if you have an NSToolbarItem that calls "createItem:" you would validate the toolbar like this (in the same class that handles the "createItem:" method).

- (void)createItem:(id)sender
{
// create an item
}

- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem
{
if ([[toolbarItem itemIdentifier] isEqualTo:@"CreateItem"]) {
// The "CreateItem" toolbar item will always be disabled
// you may want to return YES on certain conditions
return NO;
}

// validate all other toolbar items handled by this object
return YES;
}

See the apple docs for more info:
<http://developer.apple.com/documentation/Cocoa/Conceptual/Toolbars/ index.html>

Ryan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Have to subclass NSToolbarItem to be able to disable it? (From: "Guy Umbright" <email@hidden>)

  • Prev by Date: Re: OCUnit on Xcode .. I'm lost.
  • Next by Date: Re: iTunes header column and Rows selection
  • Previous by thread: Have to subclass NSToolbarItem to be able to disable it?
  • Next by thread: Re: Have to subclass NSToolbarItem to be able to disable it?
  • Index(es):
    • Date
    • Thread