Allow clicking on the key field directly.
[enjoyable.git] / ApplicationController.m
index 8fed5d6..dd38323 100644 (file)
     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
 }
 
 - (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 {
@@ -80,6 +63,7 @@
         [dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1];
     for (Config *config in self.configsController.configs)
         [dockMenuBase addItemWithTitle:config.name action:@selector(chooseConfig:) keyEquivalent:@""];
+    [_targetController refreshConfigs];
     [self configChanged];
 }
 
@@ -94,6 +78,6 @@
 - (void)chooseConfig:(id)sender {
     int idx = [dockMenuBase indexOfItem:sender] - [self firstConfigMenuIndex];
     Config *chosen = self.configsController.configs[idx];
-    [configsController activateConfig:chosen];
+    [_configsController activateConfig:chosen];
 }
 @end