X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=ApplicationController.m;h=61910a6e247ddd8280770715e8a607e83324c114;hp=dd3832367854af3fe0c8472987539074a6650aec;hb=19f40be5b645e44ffb55bdce0b6cc5c5615f68e7;hpb=60710a84810cfbfa39ada9a9e44f61ceb2f144c5 diff --git a/ApplicationController.m b/ApplicationController.m index dd38323..61910a6 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -44,39 +44,43 @@ - (IBAction)toggleActivity:(id)sender { BOOL sendRealEvents = !self.jsController.sendingRealEvents; self.jsController.sendingRealEvents = sendRealEvents; - activeButton.label = sendRealEvents ? @"Stop" : @"Start"; activeButton.image = [NSImage imageNamed:sendRealEvents ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"]; activeMenuItem.state = sendRealEvents; } -- (NSUInteger)firstConfigMenuIndex { - NSUInteger count = dockMenuBase.numberOfItems; - for (int i = 0; i < count; ++i) +- (NSInteger)firstConfigMenuIndex { + for (NSInteger i = dockMenuBase.numberOfItems - 1; i >= 0; --i) if ([dockMenuBase itemAtIndex:i].isSeparatorItem) return i + 1; - return count; + return dockMenuBase.numberOfItems; } - (void)configsChanged { - NSUInteger removeFrom = [self firstConfigMenuIndex]; + NSInteger removeFrom = [self firstConfigMenuIndex]; while (dockMenuBase.numberOfItems > removeFrom) [dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1]; - for (Config *config in self.configsController.configs) - [dockMenuBase addItemWithTitle:config.name action:@selector(chooseConfig:) keyEquivalent:@""]; + int added = 0; + for (Config *config in self.configsController.configs) { + NSString *keyEquiv = ++added < 10 ? @(added).stringValue : @""; + [dockMenuBase addItemWithTitle:config.name + action:@selector(chooseConfig:) + keyEquivalent:keyEquiv]; + + } [_targetController refreshConfigs]; [self configChanged]; } - (void)configChanged { - NSUInteger firstConfig = [self firstConfigMenuIndex]; + NSInteger firstConfig = [self firstConfigMenuIndex]; Config *current = self.configsController.currentConfig; NSArray *configs = self.configsController.configs; - for (int i = 0; i < configs.count; ++i) + for (NSUInteger i = 0; i < configs.count; ++i) [dockMenuBase itemAtIndex:i + firstConfig].state = configs[i] == current; } - (void)chooseConfig:(id)sender { - int idx = [dockMenuBase indexOfItem:sender] - [self firstConfigMenuIndex]; + NSInteger idx = [dockMenuBase indexOfItem:sender] - [self firstConfigMenuIndex]; Config *chosen = self.configsController.configs[idx]; [_configsController activateConfig:chosen]; }