PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Tools/NativeHost/MenuBridge.m

http://github.com/cacaodev/cappuccino
Objective C | 63 lines | 38 code | 18 blank | 7 comment | 5 complexity | 59488bd4a177407809de895f88eb2eac MD5 | raw file
 1//
 2//  MenuBridge.m
 3//  NativeHost
 4//
 5//  Created by Francisco Tolmasky on 9/2/09.
 6//  Copyright 2009 280 North, Inc.. All rights reserved.
 7//
 8
 9#import "WebScripObject+Objective-J.h"
10#import "MenuItemBridge.h"
11#import "MenuBridge.h"
12
13
14@implementation MenuBridge
15
16+ (id)menuBridgeWithMenuObject:(WebScriptObject *)aMenuObject
17{
18    if (!aMenuObject)
19        return nil;
20
21    static NSMapTable * cache = nil;
22
23    if (!cache)
24        cache = [[NSMapTable mapTableWithStrongToStrongObjects] retain];
25
26    MenuBridge * menuBridge = [cache objectForKey:aMenuObject];
27
28    if (!menuBridge)
29    {
30        menuBridge = [MenuBridge alloc];
31
32        [cache setObject:menuBridge forKey:aMenuObject];
33
34        [[menuBridge initWithMenuObject:aMenuObject] autorelease];
35    }
36
37    return menuBridge;
38}
39
40- (id)initWithMenuObject:(WebScriptObject *)aMenuObject
41{
42    self = [super initWithTitle:[aMenuObject bridgeSelector:@selector(title)]];
43
44    if (self)
45    {
46        menuObject = aMenuObject;
47
48        NSInteger   index = 0,
49                    count = [[aMenuObject bridgeSelector:@selector(numberOfItems)] intValue];
50
51        for (; index < count; ++index)
52            [self addItem:[[[MenuItemBridge alloc] initWithMenuItemObject:[aMenuObject bridgeSelector:@selector(itemAtIndex:) withObject:[NSNumber numberWithInt:index]]] autorelease]];
53    }
54
55    return self;
56}
57
58- (void)performActionForItemAtIndex:(NSInteger)anIndex
59{
60    [menuObject bridgeSelector:@selector(performActionForItemAtIndex:) withObject:[NSNumber numberWithInt:anIndex]];
61}
62
63@end