Skip navigation.
 
mlRe: validateToolbarItem and multiple documents
FROM : Arvid Nilsson
DATE : Sun Dec 12 17:32:10 2004

Howdy!

I also have a document based Cocoa app with a toolbar, but I do not
have the problem you describe. The toolbar is created and my document
is set as the toolbar delegate in [CanvasDocument
windowControllerDidLoadNib]. I also include the code for my
validateToolbarItem, which disables the "remove item" toolbar button if
there are no items selected. That code is implemented in a category of
my document class.

@implementation CanvasDocument

- (void)windowControllerDidLoadNib:(NSWindowController *) aController {
    [super windowControllerDidLoadNib:aController];

   [[NSColorPanel sharedColorPanel] setShowsAlpha:YES];

   // Toolbar
   NSToolbar *toolbar = [[NSToolbar alloc]
initWithIdentifier:@"CanvasDocumentToolbar"];
   [toolbar setDelegate:self];
   [toolbar setAllowsUserCustomization:YES];
   [toolbar setAutosavesConfiguration:YES];
   [[_canvasView window] setToolbar:toolbar];
   
   // Bindings for CanvasView
   [_canvasView bind:@"graphics" toObject:_graphicsController
         withKeyPath:@"arrangedObjects" options:nil];
   [_canvasView bind:@"selectionIndexes" toObject:_graphicsController
         withKeyPath:@"selectionIndexes" options:nil];
}

...

@end


@implementation CanvasDocument (CanvasDocumentToolbarController)

static NSString *ToolbarRemoveItemIdentifier = @"RemoveItem";

- (BOOL)validateToolbarItem:(NSToolbarItem *)item {
   if([[item itemIdentifier] isEqual:ToolbarRemoveItemIdentifier]) {
       if(!_graphicsController) return NO;
       NSArray *sel = [_graphicsController selectedObjects];
       if(!sel) return NO;
       return [sel count]?YES:NO;
   }
   
   return YES;
}

...

@end

On Dec 7, 2004, at 20:02, Joe Esch wrote:

> I have a document based Cocoa application that has a toolbar on the
> main document window.  In the controller, I implement
> validateToolbarItem to enable or disable some of the toolbar items
> depending on the state of the document.  The problem is that this
> seems to affect the state of the items on all toolbars - not just the
> one that is associated with the controller that is validating them. 
> I.e. when I enable the toolbar item it is enabled in the toolbar of
> all document windows - not just the one for the controller that is
> doing the validation.  This is for simple image toolbar items.
>
> Is there a way to get this validation to apply only to the toolbar
> associated with the current document without using a custom view
> toolbar item and some other kind of validation?
>
> _______________________________________________
> MacOSX-dev mailing list
> <email_removed>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>

Related mailsAuthorDate
mlvalidateToolbarItem and multiple documents Joe Esch Dec 7, 20:02
mlRe: validateToolbarItem and multiple documents Arvid Nilsson Dec 12, 17:32