• 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: a simple task for Simula based languages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a simple task for Simula based languages


  • Subject: Re: a simple task for Simula based languages
  • From: Vlad Alexa <email@hidden>
  • Date: Sun, 18 Nov 2007 15:11:24 +0200

Kudos for that , your pseudocode was very good , below is how i implemented it , excluding the function which is basically identical to yours ...

Now can anyone tell me if it is possible to further optimize/shrink this code here , maybe it should be done in another way ? it looks a bit overkill to me for its scope.

And is it possible to generate dictionaries with automatic generated numerical indexes , i supply the indexes "one" and "two" but i do not actually use them.

//init array with icon params and start adding
params=[[NSMutableDictionary alloc] init];

[params setObject:[NSDictionary dictionaryWithObjectsAndKeys:
                   @"Refresh", @"Name",
                   @"Refresh the list", @"Tip",
                   @"refresh", @"Icon",
                   @"toolbaritemclicked:", @"Act",
                   nil] forKey:@"one"];

[params setObject:[NSDictionary dictionaryWithObjectsAndKeys:
                   @"Website", @"Name",
                   @"Visit us on the web", @"Tip",
                   @"refresh", @"Icon",
                   @"toolbaritemclicked1:", @"Act",
				   nil] forKey:@"two"];

//create icons from params
items=[[NSMutableDictionary alloc] init];
id key;
NSEnumerator *loop = [params keyEnumerator];
while ((key = [loop nextObject])) {
NSDictionary *dict = [params objectForKey:key];
[items setObject:[self configureToolbarItem: dict] forKey:[dict objectForKey: @"Name"]];
}


On Nov 17, 2007, at 7:55 PM, Bill Bumgarner wrote:

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


  • Follow-Ups:
    • Re: a simple task for Simula based languages
      • From: Charles Steinman <email@hidden>
References: 
 >a simple task for Simula based languages (From: Vlad Alexa <email@hidden>)
 >Re: a simple task for Simula based languages (From: John Stiles <email@hidden>)
 >Re: a simple task for Simula based languages (From: Vlad Alexa <email@hidden>)
 >Re: a simple task for Simula based languages (From: Raffael Cavallaro <email@hidden>)
 >Re: a simple task for Simula based languages (From: Vlad Alexa <email@hidden>)
 >Re: a simple task for Simula based languages (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: NSXML and element parsing
  • Next by Date: Re: CATextLayer and CAConstraint
  • Previous by thread: Re: a simple task for Simula based languages
  • Next by thread: Re: a simple task for Simula based languages
  • Index(es):
    • Date
    • Thread