Formal protocol for the interface shared between Joysticks and JSActions, use new...
[enjoyable.git] / TargetController.m
index 86fe968..1f285ec 100644 (file)
     } else {
         self.enabled = YES;
         NSString *actFullName = action.name;
-        for (JSAction *cur = action.base; cur; cur = cur.base) {
+        for (id <NJActionPathElement> cur = action.base; cur; cur = cur.base) {
             actFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, actFullName];
         }
         title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, actFullName];
     }
 
-    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]]) {
+    } else if ([target isKindOfClass:TargetConfig.class]) {
         [radioButtons selectCellAtRow:2 column:0];
-        [configPopup selectItemAtIndex:[configsController.configs
-                                        indexOfObject:[(TargetConfig *)target config]]];
+        NSUInteger idx = [configsController.configs
+                          indexOfObject:[(TargetConfig *)target config]];
+        if (idx == NSNotFound) {
+            [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0];
+            [configPopup selectItemAtIndex:-1];
+        } 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 forAction:joystickController.selectedAction];
 }
 
 - (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) {