X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FEnjoyableApplicationDelegate.m;h=c66cf6b9aecb6d47a465a0c528599c7cf9399887;hp=634f3621ab9ce5f4eaeb02d65d6534971dbb5f24;hb=3fae21830d647cf9c208fc8f96e23efedccdbd0e;hpb=93c9d4bc39c6addbab6dbc7878d3684e42bbdc01 diff --git a/Classes/EnjoyableApplicationDelegate.m b/Classes/EnjoyableApplicationDelegate.m index 634f362..c66cf6b 100644 --- a/Classes/EnjoyableApplicationDelegate.m +++ b/Classes/EnjoyableApplicationDelegate.m @@ -124,10 +124,13 @@ [self.mappingsController mappingPressed:sender]; } -- (void)addMappingsToMenu:(NSMenu *)menu withKeys:(BOOL)withKeys atIndex:(NSInteger)index { +- (void)addMappings:(NSArray *)mappings + toMenu:(NSMenu *)menu + withKeys:(BOOL)withKeys + atIndex:(NSInteger)index { static const NSUInteger MAXIMUM_ITEMS = 15; int added = 0; - for (NJMapping *mapping in self.mappingsController) { + for (NJMapping *mapping in mappings) { NSString *keyEquiv = (++added < 10 && withKeys) ? @(added).stringValue : @""; NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name action:@selector(chooseMapping:) @@ -143,7 +146,7 @@ keyEquivalent:@""]; // There must be a represented object here so the item gets // removed correctly when the menus are regenerated. - end.representedObject = self.mappingsController.mappings; + end.representedObject = mappings; end.target = self; [menu insertItem:end atIndex:index++]; break; @@ -152,16 +155,20 @@ } - (void)mappingListDidChange:(NSNotification *)note { + NSArray *mappings = note.userInfo[@"mappings"]; while (mappingsMenu.lastItem.representedObject) [mappingsMenu removeLastItem]; - [self addMappingsToMenu:mappingsMenu withKeys:YES atIndex:mappingsMenu.numberOfItems]; + [self addMappings:mappings + toMenu:mappingsMenu + withKeys:YES + atIndex:mappingsMenu.numberOfItems]; while ([statusItemMenu itemAtIndex:2].representedObject) [statusItemMenu removeItemAtIndex:2]; - [self addMappingsToMenu:statusItemMenu withKeys:NO atIndex:2]; + [self addMappings:mappings toMenu:statusItemMenu withKeys:NO atIndex:2]; } - (void)mappingDidChange:(NSNotification *)note { - NJMapping *current = note.object; + NJMapping *current = note.userInfo[@"mapping"]; for (NSMenuItem *item in mappingsMenu.itemArray) if (item.representedObject) item.state = item.representedObject == current; @@ -184,7 +191,10 @@ - (NSMenu *)applicationDockMenu:(NSApplication *)sender { while (dockMenu.lastItem.representedObject) [dockMenu removeLastItem]; - [self addMappingsToMenu:dockMenu withKeys:NO atIndex:dockMenu.numberOfItems]; + [self addMappings:self.mappingsController.mappings + toMenu:dockMenu + withKeys:NO + atIndex:dockMenu.numberOfItems]; return dockMenu; }