Re: a simple task for Simula based languages
Re: a simple task for Simula based languages
- Subject: Re: a simple task for Simula based languages
- From: Bill Bumgarner <email@hidden>
- Date: Sat, 17 Nov 2007 09:55:36 -0800
On Nov 17, 2007, at 8:29 AM, Vlad Alexa wrote:
Trying to be as explicit as i can here is the actual code :
items=[[NSMutableDictionary alloc] init];
NSToolbarItem *item=[[NSToolbarItem alloc]
initWithItemIdentifier:@"Name"];
[item setPaletteLabel:@"Name"];
[item setLabel:@"Name"];
[item setToolTip:@"Tip"];
[item setImage: [NSImage imageNamed:@"icon"]];
[item setTarget:self];
[item setAction:@selector(toolbaritemclick:)];
[items setObject:item forKey:@"Name"];
NSToolbarItem *item=[[NSToolbarItem alloc]
initWithItemIdentifier:@"Name1"];
[item setPaletteLabel:@"Name1"];
[item setLabel:@"Name1"];
[item setToolTip:@"Tip1"];
[item setImage: [NSImage imageNamed:@"icon1"]];
[item setTarget:self];
[item setAction:@selector(toolbaritemclick1:)];
[items setObject:item forKey:@"Name1"];
the obvious scope is to be able to call this code only once for each
button and besides it have only one line of code for each button
that supplies the parameters name,tip,icon and action.
- (NSToolbarItem *) configureToolbarItem: (NSDictionary *)optionsDict
{
NSToolbarItem *item=[[NSToolbarItem alloc] initWithItemIdentifier:
[optionsDict objectForKey: @"Name"]];
[item setPaletteLabel: [optionsDict objectForKey: @"Name"]];
[item setLabel: [optionsDict objectForKey: @"Name"]];
[item setToolTip: [optionsDict objectForKey: @"Tip"]];
[item setImage: [NSImage imageNamed: [optionsDict objectForKey:
@"icon"]]];
[item setTarget:self];
[item setAction: NSSelectorFromString([optionsDict objectForKey:
@"SEL"])];
return item;
}
....
toolbarDict = [NSDictionary dictionaryWithContentsOfFile: [[NSBundle
mainBundle] pathForResource: @"ToolbarDescription" ofType: @"plist"]];
items=[[NSMutableDictionary alloc] init];
dict = [toolbarDict objectForKey: @"Item1 Configuration"];
[items setObject: [self configureToolbarItem: dict] forKey: [dict
objectForKey: @"Name"]];
...
Where ToolbarDescription.plist would be a file containing a plist with
each toolbars description in an array. Something like:
...
<array>
<dict>
<key>Name</key>
<string>Bob The Button</string>
<key>Image</key>
<string>Bob The Image</string>
...
</dict>
<dict>
....
</dict>
...
</array>
...
Consider the above pseudo code -- typed into Mail.
That is how I solve this particular problem. I like to push as much
of the app configuration goop into property lists within the app
wrapper; user defaults, toolbar configurations, etc.
b.bum
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden