Big rename part 1: 'action' to 'input'.
[enjoyable.git] / TargetController.m
index 7a4fd05..2e53917 100644 (file)
@@ -9,9 +9,9 @@
 
 #import "ConfigsController.h"
 #import "Config.h"
-#import "JSAction.h"
-#import "JoystickController.h"
-#import "KeyInputTextView.h"
+#import "NJInput.h"
+#import "NJInputController.h"
+#import "NJKeyInputField.h"
 #import "TargetConfig.h"
 #import "TargetController.h"
 #import "TargetKeyboard.h"
@@ -26,7 +26,7 @@
     NSInteger row = radioButtons.selectedRow;
     
     if (row != 1) {
-        keyInput.vk = -1;
+        keyInput.keyCode = -1;
         [keyInput resignIfFirstResponder];
     }
     
     [self commit];
 }
 
-- (void)keyChanged {
+- (void)keyInputField:(NJKeyInputField *)keyInput didChangeKey:(CGKeyCode)keyCode {
     [radioButtons selectCellAtRow:1 column:0];
     [radioButtons.window makeFirstResponder:radioButtons];
     [self commit];
 }
 
+- (void)keyInputFieldDidClear:(NJKeyInputField *)keyInput {
+    [radioButtons selectCellAtRow:0 column:0];
+    [self commit];
+}
+
 - (void)configChosen:(id)sender {
     [radioButtons selectCellAtRow:2 column:0];
     [configPopup.window makeFirstResponder:configPopup];
@@ -93,7 +98,7 @@
 }
 
 - (Target *)currentTarget {
-    return configsController.currentConfig[joystickController.selectedAction];
+    return configsController.currentConfig[joystickController.selectedInput];
 }
 
 - (Target *)makeTarget {
         case 0:
             return nil;
         case 1:
-            if (keyInput.hasKey) {
+            if (keyInput.hasKeyCode) {
                 TargetKeyboard *k = [[TargetKeyboard alloc] init];
-                k.vk = keyInput.vk;
+                k.vk = keyInput.keyCode;
                 return k;
             } else {
                 return nil;
 
 - (void)commit {
     [self cleanUpInterface];
-    configsController.currentConfig[joystickController.selectedAction] = [self makeTarget];
+    configsController.currentConfig[joystickController.selectedInput] = [self makeTarget];
     [configsController save];
 }
 
     [scrollDirSelect setEnabled:enabled];
 }
 
-- (void)loadTarget:(Target *)target forAction:(JSAction *)action {
-    if (!action) {
+- (void)loadTarget:(Target *)target forInput:(NJInput *)input {
+    if (!input) {
         self.enabled = NO;
         title.stringValue = @"";
     } else {
         self.enabled = YES;
-        NSString *actFullName = action.name;
-        for (JSAction *cur = action.base; cur; cur = cur.base) {
-            actFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, actFullName];
+        NSString *inpFullName = input.name;
+        for (id <NJInputPathElement> cur = input.base; cur; cur = cur.base) {
+            inpFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, inpFullName];
         }
-        title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, actFullName];
+        title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, inpFullName];
     }
 
-    if ([target isKindOfClass:[TargetKeyboard class]]) {
+    if ([target isKindOfClass:TargetKeyboard.class]) {
         [radioButtons selectCellAtRow:1 column:0];
-        keyInput.vk = [(TargetKeyboard*)target vk];
-    } else if ([target isKindOfClass:[TargetConfig class]]) {
+        keyInput.keyCode = [(TargetKeyboard*)target vk];
+    } else if ([target isKindOfClass:TargetConfig.class]) {
         [radioButtons selectCellAtRow:2 column:0];
         NSUInteger idx = [configsController.configs
                           indexOfObject:[(TargetConfig *)target config]];
         } else
             [configPopup selectItemAtIndex:idx];
     }
-    else if ([target isKindOfClass:[TargetMouseMove class]]) {
+    else if ([target isKindOfClass:TargetMouseMove.class]) {
         [radioButtons selectCellAtRow:3 column:0];
         [mouseDirSelect setSelectedSegment:[(TargetMouseMove *)target axis]];
     }
-    else if ([target isKindOfClass:[TargetMouseBtn class]]) {
+    else if ([target isKindOfClass:TargetMouseBtn.class]) {
         [radioButtons selectCellAtRow:4 column:0];
         mouseBtnSelect.selectedSegment = [(TargetMouseBtn *)target button] == kCGMouseButtonLeft ? 0 : 1;
     }
-    else if ([target isKindOfClass:[TargetMouseScroll class]]) {
+    else if ([target isKindOfClass:TargetMouseScroll.class]) {
         [radioButtons selectCellAtRow:5 column:0];
         scrollDirSelect.selectedSegment = [(TargetMouseScroll *)target amount] > 0;
     }
-    else if ([target isKindOfClass:[TargetToggleMouseScope class]]) {
+    else if ([target isKindOfClass:TargetToggleMouseScope.class]) {
         [radioButtons selectCellAtRow:6 column:0];
     } else {
         [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0];
 }
 
 - (void)loadCurrent {
-    [self loadTarget:[self currentTarget] forAction:joystickController.selectedAction];
+    [self loadTarget:self.currentTarget forInput:joystickController.selectedInput];
 }
 
 - (void)focusKey {
 }
 
 - (void)refreshConfigs {
-    // TODO: This doesn't work when removing configs.
     NSInteger initialIndex = configPopup.indexOfSelectedItem;
     [configPopup.menu removeAllItems];
     for (Config *config in configsController.configs) {