X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=ApplicationController.m;h=9a2db2af3c1d31a5034f7cae19c235516b8ae03c;hp=b86a5f2067f8ebc36e09e8bdc58bd90eda2b70ff;hb=0238d141f06420e1a73eccd14ca73a7e29ad2a69;hpb=5de694150d275d27119d344cbb1d61bc31d75268 diff --git a/ApplicationController.m b/ApplicationController.m index b86a5f2..9a2db2a 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -26,7 +26,7 @@ self.targetController.enabled = NO; [self.jsController setup]; [self.configsController load]; - [[NSWorkspace sharedWorkspace].notificationCenter + [NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(didSwitchApplication:) name:NSWorkspaceDidActivateApplicationNotification @@ -34,8 +34,8 @@ } - (void)applicationWillTerminate:(NSNotification *)aNotification { - [[NSUserDefaults standardUserDefaults] synchronize]; - [[NSWorkspace sharedWorkspace].notificationCenter + [NSUserDefaults.standardUserDefaults synchronize]; + [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:NSWorkspaceDidActivateApplicationNotification object:nil]; @@ -44,21 +44,19 @@ - (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; } - (NSInteger)firstConfigMenuIndex { - NSInteger count = dockMenuBase.numberOfItems; - for (int i = 0; i < count; ++i) + for (NSInteger i = dockMenuBase.numberOfItems - 1; i >= 0; --i) if ([dockMenuBase itemAtIndex:i].isSeparatorItem) return i + 1; - return count; + return dockMenuBase.numberOfItems; } - (void)configsChanged { - NSInteger removeFrom = [self firstConfigMenuIndex]; + NSInteger removeFrom = self.firstConfigMenuIndex; while (dockMenuBase.numberOfItems > removeFrom) [dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1]; int added = 0; @@ -74,15 +72,15 @@ } - (void)configChanged { - NSInteger 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 { - NSInteger idx = [dockMenuBase indexOfItem:sender] - [self firstConfigMenuIndex]; + NSInteger idx = [dockMenuBase indexOfItem:sender] - self.firstConfigMenuIndex; Config *chosen = self.configsController.configs[idx]; [_configsController activateConfig:chosen]; }