X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=ApplicationController.m;h=a3ad5ed24955f095252f004086bf8835f1532761;hp=8fed5d61f3d047ce6d46586f86e7ba41811a47ed;hb=62aa5b73be6ec1e499e6b155cd0e7687c338cbaa;hpb=c6fb77859e508aaef686b7a5a6a12abe29178708 diff --git a/ApplicationController.m b/ApplicationController.m index 8fed5d6..a3ad5ed 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -16,10 +16,6 @@ BOOL active; } -@synthesize jsController; -@synthesize targetController; -@synthesize configsController; - - (void)didSwitchApplication:(NSNotification *)notification { NSRunningApplication *currentApp = notification.userInfo[NSWorkspaceApplicationKey]; [self.configsController activateConfigForProcess:currentApp.localizedName]; @@ -28,7 +24,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification { [drawer open]; self.targetController.enabled = NO; - self.active = NO; [self.jsController setup]; [self.configsController load]; [[NSWorkspace sharedWorkspace].notificationCenter @@ -39,35 +34,23 @@ } - (void)applicationWillTerminate:(NSNotification *)aNotification { - // TODO: Save immediately / shortly after changing and then enable - // sudden termination support. - [configsController save]; + [[NSUserDefaults standardUserDefaults] synchronize]; [[NSWorkspace sharedWorkspace].notificationCenter removeObserver:self name:NSWorkspaceDidActivateApplicationNotification object:nil]; } -// TODO: Active state should probably be in the ConfigsController or -// JoystickController, not here. - -- (BOOL)active { - return active; -} - -- (void)setActive:(BOOL)newActive { - activeButton.label = newActive ? @"Stop" : @"Start"; - activeButton.image = [NSImage imageNamed:newActive ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"]; - activeMenuItem.state = newActive; - active = newActive; -} - - (IBAction)toggleActivity:(id)sender { - self.active = !self.active; + 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; +- (NSInteger)firstConfigMenuIndex { + NSInteger count = dockMenuBase.numberOfItems; for (int i = 0; i < count; ++i) if ([dockMenuBase itemAtIndex:i].isSeparatorItem) return i + 1; @@ -75,16 +58,17 @@ } - (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:@""]; + [_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) @@ -92,8 +76,8 @@ } - (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]; + [_configsController activateConfig:chosen]; } @end