Re: NSToolbar experience?
Re: NSToolbar experience?
- Subject: Re: NSToolbar experience?
- From: Matthew Formica <email@hidden>
- Date: Mon, 30 Apr 2001 11:15:40 -0700
This list just recently went live. It'll take a little time before everyone
finds out about it and joins. Yes, this list is the right place for your
question.
Regards,
Matthew Formica
Apple DTS Engineer - Dev Tools and Cocoa
email@hidden
on 4/30/01 11:07 AM, Andreas Wolf at email@hidden remarked:
>
Thanx! That rocks!
>
Looks like, I didn't implement the delegate methods correctly.
>
Anyway, it works with Chucks sample code!
>
>
This list seems a little deserted - maybe I am wrong.
>
There is no archive on the web and the daily digest contained my posting
>
only.
>
Hopefully it'll become more alive, soon.
>
Was my kind of question right in place on this list?
>
-Andy
>
>
>
>
>
On Monday, April 30, 2001, at 09:08 AM, Chuck Pisula wrote:
>
>
> The release notes has some good information, and there is quite a bit
>
> of documentation in the headers, but.... nothing helps like an
>
> example. In your code, at a minimum, you'd probably do something like
>
> the code snippets I've attached.
>
>
>
> HTH,
>
> chuck
>
>
>
> // Probably called from awakeFromNib, or - windowControllerDidLoadNib:
>
> - (void) setupToolbar {
>
> // Create a new toolbar instance, and attach it to our document
>
> window
>
> NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:
>
> MyDocToolbarIdentifier] autorelease];
>
>
>
> // Set up toolbar properties: Allow customization, give a default
>
> display mode, and remember state in user defaults
>
> [toolbar setAllowsUserCustomization: YES];
>
> [toolbar setAutosavesConfiguration: YES];
>
> [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
>
>
>
> // We are the delegate
>
> [toolbar setDelegate: self];
>
>
>
> // Attach the toolbar to the document window
>
> [documentWindow setToolbar: toolbar];
>
> }
>
>
>
>
>
> - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {
>
> // Required delegate method Returns the ordered list of items to
>
> be shown in the toolbar by default
>
> // If during the toolbar's initialization, no overriding values are
>
> found in the user defaults, or if the
>
> // user chooses to revert to the default items self set will be used
>
> return [NSArray arrayWithObjects: SaveDocToolbarItemIdentifier,
>
> NSToolbarPrintItemIdentifier, NSToolbarSeparatorItemIdentifier,
>
> NSToolbarShowColorsItemIdentifier,
>
> NSToolbarShowFontsItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
>
> NSToolbarSpaceItemIdentifier, nil];
>
> }
>
>
>
> - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
>
> // Required delegate method Returns the list of all allowed items
>
> by identifier By default, the toolbar
>
> // does not assume any items are allowed, even the separator So,
>
> every allowed item must be explicitly listed
>
> // The set of allowed items is used to construct the customization
>
> palette
>
> return [NSArray arrayWithObjects: SaveDocToolbarItemIdentifier,
>
> NSToolbarPrintItemIdentifier,
>
> NSToolbarShowColorsItemIdentifier,
>
> NSToolbarShowFontsItemIdentifier,
>
> NSToolbarCustomizeToolbarItemIdentifier,
>
> NSToolbarFlexibleSpaceItemIdentifier,
>
> NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
>
> }
>
>
>
> - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar
>
> itemForItemIdentifier: (NSString *) itemIdent
>
> willBeInsertedIntoToolbar:(BOOL) willBeInserted {
>
> // Required delegate method Given an item identifier, self method
>
> returns an item
>
> // The toolbar will use self method to obtain toolbar items that
>
> can be displayed in the customization sheet, or in the toolbar itself
>
> // Note that the toolbar knows how to make the standard NS supplied
>
> items all on its own, we don't have to do that.
>
> NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc]
>
> initWithItemIdentifier: itemIdent] autorelease];
>
>
>
> if ([itemIdent isEqual: SaveDocToolbarItemIdentifier]) {
>
> // Set the text label to be displayed in the toolbar and
>
> customization palette
>
> [toolbarItem setLabel: @"Save"];
>
> [toolbarItem setPaletteLabel: @"Save"];
>
>
>
> // Set up a reasonable tooltip, and image Note, these aren't
>
> localized, but you will likely want to localize many of the item's
>
> properties
>
> [toolbarItem setToolTip: @"Save Your Document"];
>
> [toolbarItem setImage: [NSImage imageNamed:
>
> @"SaveDocumentItemImage"]];
>
>
>
> // Tell the item what message to send when it is clicked
>
> [toolbarItem setTarget: self];
>
> [toolbarItem setAction: @selector(saveDocument:)];
>
> }
>
> else {
>
> // itemIdent refered to a toolbar item that is not provide or
>
> supported by us or cocoa
>
> // Returning nil will inform the toolbar this kind of item is not
>
> supported
>
> toolbarItem = nil;
>
> }
>
> return toolbarItem;
>
> }
>
>
>
>
>
> On Saturday, April 28, 2001, at 08:01 PM, Andreas Wolf wrote:
>
>
>
>> Hi cocoa-dev,
>
>>
>
>> has anybody experience using NSToolbar and NSToolbarItems and
>
>> can he/she provide some sample code or a path to code using these
>
>> classes?
>
>>
>
>> I've read the AppKit Release Notes and believe that I did all that
>
>> was required to
>
>> get a toolbar on my window, but still I don't see much more than a
>
>> horizontal line.
>
>> How can get items on that toolbar (predefined or custom made)?
>
>>
>
>> Thanx,
>
>> -A
>
>> _______________________________________________
>
>> cocoa-dev mailing list
>
>> email@hidden
>
>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
_______________________________________________
>
cocoa-dev mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev