Disable automatic termination when simulation is active. This is probably a good...
[enjoyable.git] / Categories / NSMenu+RepresentedObjectAccessors.m
1 //
2 // NSMenu+RepresentedObjectAccessors.m
3 // Enjoyable
4 //
5 // Created by Joe Wreschnig on 3/4/13.
6 //
7 //
8
9 #import "NSMenu+RepresentedObjectAccessors.h"
10
11 @implementation NSMenu (RepresentedObjectAccessors)
12
13 - (NSMenuItem *)itemWithRepresentedObject:(id)object {
14 for (NSMenuItem *item in self.itemArray)
15 if ([item.representedObject isEqual:object])
16 return item;
17 return nil;
18 }
19
20 - (NSMenuItem *)itemWithIdenticalRepresentedObject:(id)object {
21 for (NSMenuItem *item in self.itemArray)
22 if (item.representedObject == object)
23 return item;
24 return nil;
25 }
26
27 - (NSMenuItem *)lastItem {
28 return self.itemArray.lastObject;
29 }
30
31 - (void)removeLastItem {
32 if (self.numberOfItems)
33 [self removeItemAtIndex:self.numberOfItems - 1];
34 }
35
36 @end
37
38 @implementation NSPopUpButton (RepresentedObjectAccessors)
39
40 - (NSMenuItem *)itemWithRepresentedObject:(id)object {
41 return [self.menu itemWithRepresentedObject:object];
42 }
43
44 - (NSMenuItem *)itemWithIdenticalRepresentedObject:(id)object {
45 return [self.menu itemWithIdenticalRepresentedObject:object];
46 }
47
48 - (void)selectItemWithRepresentedObject:(id)object {
49 [self selectItemAtIndex:[self indexOfItemWithRepresentedObject:object]];
50 }
51
52 - (void)selectItemWithIdenticalRepresentedObject:(id)object {
53 NSMenuItem *item = [self.menu itemWithIdenticalRepresentedObject:object];
54 [self selectItem:item];
55 }
56
57
58 @end