Reset target settings in UI when switching target types.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 28 Feb 2013 14:49:40 +0000 (15:49 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 28 Feb 2013 14:49:40 +0000 (15:49 +0100)
English.lproj/MainMenu.xib
TargetController.h
TargetController.m

index 7ba1177..ac82d63 100644 (file)
                                                                                                                        <string key="NSFrameSize">{200, 298}</string>
                                                                                                                        <reference key="NSSuperview" ref="698362889"/>
                                                                                                                        <reference key="NSWindow"/>
                                                                                                                        <string key="NSFrameSize">{200, 298}</string>
                                                                                                                        <reference key="NSSuperview" ref="698362889"/>
                                                                                                                        <reference key="NSWindow"/>
-                                                                                                                       <reference key="NSNextKeyView" ref="1036252745"/>
+                                                                                                                       <reference key="NSNextKeyView" ref="892486973"/>
                                                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                                                        <bool key="NSControlAllowsExpansionToolTips">YES</bool>
                                                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                                                        <bool key="NSControlAllowsExpansionToolTips">YES</bool>
                                                                                        <string key="NSFrameSize">{202, 300}</string>
                                                                                        <reference key="NSSuperview" ref="977242492"/>
                                                                                        <reference key="NSWindow"/>
                                                                                        <string key="NSFrameSize">{202, 300}</string>
                                                                                        <reference key="NSSuperview" ref="977242492"/>
                                                                                        <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView" ref="892486973"/>
+                                                                                       <reference key="NSNextKeyView" ref="698362889"/>
                                                                                        <int key="NSsFlags">133650</int>
                                                                                        <reference key="NSVScroller" ref="1036252745"/>
                                                                                        <reference key="NSHScroller" ref="892486973"/>
                                                                                        <int key="NSsFlags">133650</int>
                                                                                        <reference key="NSVScroller" ref="1036252745"/>
                                                                                        <reference key="NSHScroller" ref="892486973"/>
                                                                                        <string key="NSFrame">{{227, 55}, {180, 24}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
                                                                                        <string key="NSFrame">{{227, 55}, {180, 24}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView"/>
                                                                                        <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                        <object class="NSSegmentedCell" key="NSCell" id="301345285">
                                                                                        <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                        <object class="NSSegmentedCell" key="NSCell" id="301345285">
                                                                                        <string key="NSFrame">{{20, 16}, {201, 236}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
                                                                                        <string key="NSFrame">{{20, 16}, {201, 236}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView"/>
                                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                        <int key="NSNumRows">7</int>
                                                                                        <int key="NSNumCols">1</int>
                                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                        <int key="NSNumRows">7</int>
                                                                                        <int key="NSNumCols">1</int>
@@ -1392,10 +1390,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                <string key="NSClassName">TargetController</string>
                        </object>
                        <object class="NSButton" id="735675040">
                                <string key="NSClassName">TargetController</string>
                        </object>
                        <object class="NSButton" id="735675040">
-                               <reference key="NSNextResponder"/>
+                               <nil key="NSNextResponder"/>
                                <int key="NSvFlags">268</int>
                                <string key="NSFrameSize">{82, 32}</string>
                                <int key="NSvFlags">268</int>
                                <string key="NSFrameSize">{82, 32}</string>
-                               <reference key="NSSuperview"/>
                                <string key="NSReuseIdentifierKey">_NS:9</string>
                                <bool key="NSEnabled">YES</bool>
                                <object class="NSButtonCell" key="NSCell" id="835359972">
                                <string key="NSReuseIdentifierKey">_NS:9</string>
                                <bool key="NSEnabled">YES</bool>
                                <object class="NSButtonCell" key="NSCell" id="835359972">
@@ -1697,22 +1694,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                        </object>
                                        <int key="connectionID">696</int>
                                </object>
                                        </object>
                                        <int key="connectionID">696</int>
                                </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" key="connection">
-                                               <string key="label">radioKey</string>
-                                               <reference key="source" ref="801536542"/>
-                                               <reference key="destination" ref="387494389"/>
-                                       </object>
-                                       <int key="connectionID">690</int>
-                               </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" key="connection">
-                                               <string key="label">radioNoAction</string>
-                                               <reference key="source" ref="801536542"/>
-                                               <reference key="destination" ref="177186415"/>
-                                       </object>
-                                       <int key="connectionID">691</int>
-                               </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
                                                <string key="label">radioButtons</string>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
                                                <string key="label">radioButtons</string>
@@ -1761,14 +1742,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                        </object>
                                        <int key="connectionID">714</int>
                                </object>
                                        </object>
                                        <int key="connectionID">714</int>
                                </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" key="connection">
-                                               <string key="label">radioConfig</string>
-                                               <reference key="source" ref="801536542"/>
-                                               <reference key="destination" ref="339215895"/>
-                                       </object>
-                                       <int key="connectionID">715</int>
-                               </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBActionConnection" key="connection">
                                                <string key="label">radioChanged:</string>
                                <object class="IBConnectionRecord">
                                        <object class="IBActionConnection" key="connection">
                                                <string key="label">radioChanged:</string>
@@ -2657,7 +2630,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                </object>
                                <object class="IBPartialClassDescription">
                                        <string key="className">KeyInputTextView</string>
                                </object>
                                <object class="IBPartialClassDescription">
                                        <string key="className">KeyInputTextView</string>
-                                       <string key="superclassName">NSTextView</string>
+                                       <string key="superclassName">NSTextField</string>
                                        <dictionary class="NSMutableDictionary" key="outlets">
                                                <string key="targetController">TargetController</string>
                                                <string key="window">NSWindow</string>
                                        <dictionary class="NSMutableDictionary" key="outlets">
                                                <string key="targetController">TargetController</string>
                                                <string key="window">NSWindow</string>
@@ -2717,9 +2690,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                                <string key="mouseBtnSelect">NSSegmentedControl</string>
                                                <string key="mouseDirSelect">NSSegmentedControl</string>
                                                <string key="radioButtons">NSMatrix</string>
                                                <string key="mouseBtnSelect">NSSegmentedControl</string>
                                                <string key="mouseDirSelect">NSSegmentedControl</string>
                                                <string key="radioButtons">NSMatrix</string>
-                                               <string key="radioConfig">NSButtonCell</string>
-                                               <string key="radioKey">NSButtonCell</string>
-                                               <string key="radioNoAction">NSButtonCell</string>
                                                <string key="scrollDirSelect">NSSegmentedControl</string>
                                                <string key="title">NSTextField</string>
                                        </dictionary>
                                                <string key="scrollDirSelect">NSSegmentedControl</string>
                                                <string key="title">NSTextField</string>
                                        </dictionary>
@@ -2752,18 +2722,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                                        <string key="name">radioButtons</string>
                                                        <string key="candidateClassName">NSMatrix</string>
                                                </object>
                                                        <string key="name">radioButtons</string>
                                                        <string key="candidateClassName">NSMatrix</string>
                                                </object>
-                                               <object class="IBToOneOutletInfo" key="radioConfig">
-                                                       <string key="name">radioConfig</string>
-                                                       <string key="candidateClassName">NSButtonCell</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="radioKey">
-                                                       <string key="name">radioKey</string>
-                                                       <string key="candidateClassName">NSButtonCell</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="radioNoAction">
-                                                       <string key="name">radioNoAction</string>
-                                                       <string key="candidateClassName">NSButtonCell</string>
-                                               </object>
                                                <object class="IBToOneOutletInfo" key="scrollDirSelect">
                                                        <string key="name">scrollDirSelect</string>
                                                        <string key="candidateClassName">NSSegmentedControl</string>
                                                <object class="IBToOneOutletInfo" key="scrollDirSelect">
                                                        <string key="name">scrollDirSelect</string>
                                                        <string key="candidateClassName">NSSegmentedControl</string>
index 589023b..4606784 100644 (file)
@@ -14,7 +14,6 @@
 
 @interface TargetController : NSObject {
        IBOutlet KeyInputTextView* keyInput;
 
 @interface TargetController : NSObject {
        IBOutlet KeyInputTextView* keyInput;
-       IBOutlet NSButtonCell *radioNoAction, *radioKey, *radioConfig;
        IBOutlet NSMatrix* radioButtons;
     IBOutlet NSSegmentedControl* mouseDirSelect;
     IBOutlet NSSegmentedControl* mouseBtnSelect;
        IBOutlet NSMatrix* radioButtons;
     IBOutlet NSSegmentedControl* mouseDirSelect;
     IBOutlet NSSegmentedControl* mouseBtnSelect;
@@ -30,7 +29,6 @@
 -(void) load;
 -(void) commit;
 -(void) reset;
 -(void) load;
 -(void) commit;
 -(void) reset;
--(Target*) state;
 -(void) refreshConfigsPreservingSelection: (BOOL) preserve;
 -(IBAction)configChosen:(id)sender;
 -(IBAction)radioChanged:(id)sender;
 -(void) refreshConfigsPreservingSelection: (BOOL) preserve;
 -(IBAction)configChosen:(id)sender;
 -(IBAction)radioChanged:(id)sender;
@@ -39,6 +37,6 @@
 -(IBAction)sdirChanged:(id)sender;
 -(void) focusKey;
 
 -(IBAction)sdirChanged:(id)sender;
 -(void) focusKey;
 
-@property(readwrite) BOOL enabled;
+@property (assign) BOOL enabled;
 
 @end
 
 @end
index 14f81a9..0119980 100644 (file)
 
 @implementation TargetController
 
 
 @implementation TargetController
 
--(void) keyChanged {
-       [radioButtons setState: 1 atRow: 1 column: 0 ];
+- (void)keyChanged {
+       [radioButtons setState:1 atRow:1 column:0 ];
        [self commit];
 }
        [self commit];
 }
--(IBAction)radioChanged:(id)sender {
-       [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
+
+- (IBAction)radioChanged:(id)sender {
+    NSInteger row, col;
+    [radioButtons getRow:&row column:&col ofCell:sender];
+       [[NSApplication sharedApplication].mainWindow makeFirstResponder:sender];
+
+    if (row != 1)
+        keyInput.vk = -1;
+
+    if (row != 2)
+        [configPopup selectItemAtIndex:-1];
+    else if (!configPopup.selectedItem)
+        [configPopup selectItemAtIndex:0];
+
+    if (row != 3)
+        mouseDirSelect.selectedSegment = -1;
+    else if (mouseDirSelect.selectedSegment == -1)
+        mouseDirSelect.selectedSegment = 0;
+
+    if (row != 4)
+        mouseBtnSelect.selectedSegment = -1;
+    else if (mouseBtnSelect.selectedSegment == -1)
+        mouseBtnSelect.selectedSegment = 0;
+    
+    if (row != 5)
+        scrollDirSelect.selectedSegment = -1;
+    else if (scrollDirSelect.selectedSegment == -1)
+        scrollDirSelect.selectedSegment = 0;
+    
        [self commit];
 }
        [self commit];
 }
--(IBAction)mdirChanged:(id)sender {
-    [radioButtons setState: 1 atRow: 3 column: 0];
-       [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
+
+- (IBAction)mdirChanged:(id)sender {
+    [radioButtons setState:1 atRow:3 column:0];
+       [[NSApplication sharedApplication].mainWindow makeFirstResponder:sender];
        [self commit];
 }
        [self commit];
 }
--(IBAction)mbtnChanged:(id)sender {
-    [radioButtons setState: 1 atRow: 4 column: 0];
-       [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
+
+- (IBAction)mbtnChanged:(id)sender {
+    [radioButtons setState:1 atRow:4 column:0];
+       [[NSApplication sharedApplication].mainWindow makeFirstResponder:sender];
        [self commit];
 }
        [self commit];
 }
--(IBAction)sdirChanged:(id)sender {
-    [radioButtons setState: 1 atRow: 5 column: 0];
-       [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
+
+- (IBAction)sdirChanged:(id)sender {
+    [radioButtons setState:1 atRow:5 column:0];
+       [[NSApplication sharedApplication].mainWindow makeFirstResponder:sender];
        [self commit];
 }
 
        [self commit];
 }
 
-
--(Target*) state {
-       switch([radioButtons selectedRow]) {
-               case 0: // none
-                       return NULL;
-               case 1: // key
-                       if(keyInput.hasKey) {
+- (Target *)makeTarget {
+       switch (radioButtons.selectedRow) {
+               case 0:
+                       return nil;
+               case 1:
+                       if (keyInput.hasKey) {
                                TargetKeyboard* k = [[TargetKeyboard alloc] init];
                                TargetKeyboard* k = [[TargetKeyboard alloc] init];
-                               [k setVk: [keyInput vk]];
+                k.vk = keyInput.vk;
                                return k;
                                return k;
-                       }
+                       } else {
+                return nil;
+            }
                        break;
                        break;
-               case 2:
-               {
-                       TargetConfig* c = [[TargetConfig alloc] init];
-                       [c setConfig: [configsController configs][[configPopup indexOfSelectedItem]]];
+               case 2: {
+                       TargetConfig *c = [[TargetConfig alloc] init];
+            if (!configPopup.selectedItem)
+                [configPopup selectItemAtIndex:0];
+            c.config = configsController.configs[configPopup.indexOfSelectedItem];
                        return c;
                }
         case 3: {
                        return c;
                }
         case 3: {
-            // mouse X/Y
             TargetMouseMove *mm = [[TargetMouseMove alloc] init];
             TargetMouseMove *mm = [[TargetMouseMove alloc] init];
-            [mm setDir: [mouseDirSelect selectedSegment]];
+            mm.dir = mouseDirSelect.selectedSegment;
             return mm;
         }
         case 4: {
             return mm;
         }
         case 4: {
-            // mouse button
             TargetMouseBtn *mb = [[TargetMouseBtn alloc] init];
             TargetMouseBtn *mb = [[TargetMouseBtn alloc] init];
-            if ([mouseBtnSelect selectedSegment] == 0) {
-                [mb setWhich: kCGMouseButtonLeft];
-            }
-            else {
-                [mb setWhich: kCGMouseButtonRight];
-            }
+            mb.which = mouseBtnSelect.selectedSegment == 0 ? kCGMouseButtonLeft : kCGMouseButtonRight;
             return mb;
         }
         case 5: {
             return mb;
         }
         case 5: {
-            // scroll
             TargetMouseScroll *ms = [[TargetMouseScroll alloc] init];
             TargetMouseScroll *ms = [[TargetMouseScroll alloc] init];
-            if ([scrollDirSelect selectedSegment] == 0) {
-                [ms setHowMuch: -1];
-            }
-            else {
-                [ms setHowMuch: 1];
-            }
+            ms.howMuch = scrollDirSelect.selectedSegment ? 1 : -1;
             return ms;
         }
         case 6: {
             return ms;
         }
         case 6: {
-            // toggle mouse scope
             TargetToggleMouseScope *tms = [[TargetToggleMouseScope alloc] init];
             return tms;
         }
             TargetToggleMouseScope *tms = [[TargetToggleMouseScope alloc] init];
             return tms;
         }
+        default:
+            return nil;
        }
        }
-       return NULL;
 }
 
 -(void)configChosen:(id)sender {
 }
 
 -(void)configChosen:(id)sender {
-       [radioButtons setState: 1 atRow: 2 column: 0];
+       [radioButtons setState:1 atRow:2 column:0];
        [self commit];
 }
 
        [self commit];
 }
 
--(void) commit {
-       JSAction *action = [joystickController selectedAction];
-       if (action) {
-        configsController.currentConfig[action] = self.state;
-       }
+- (void)commit {
+    configsController.currentConfig[joystickController.selectedAction] = [self makeTarget];
 }
 
 }
 
--(void) reset {
+- (void)reset {
        [keyInput clear];
        [keyInput clear];
-       [radioButtons setState: 1 atRow: 0 column: 0];
-    [mouseDirSelect setSelectedSegment: 0];
-    [mouseBtnSelect setSelectedSegment: 0];
-    [scrollDirSelect setSelectedSegment: 0];
-       [self refreshConfigsPreservingSelection: NO];
+       [radioButtons setState:1 atRow:0 column:0];
+       [self refreshConfigsPreservingSelection:NO];
 }
 
 }
 
--(void) setEnabled: (BOOL) enabled {
-       [radioButtons setEnabled: enabled];
-       [keyInput setEnabled: enabled];
-       [configPopup setEnabled: enabled];
-    [mouseDirSelect setEnabled: enabled];
-    [mouseBtnSelect setEnabled: enabled];
-    [scrollDirSelect setEnabled: enabled];
-}
--(BOOL) enabled {
+- (BOOL)enabled {
        return [radioButtons isEnabled];
 }
 
        return [radioButtons isEnabled];
 }
 
+- (void)setEnabled:(BOOL)enabled {
+       [radioButtons setEnabled:enabled];
+       [keyInput setEnabled:enabled];
+       [configPopup setEnabled:enabled];
+    [mouseDirSelect setEnabled:enabled];
+    [mouseBtnSelect setEnabled:enabled];
+    [scrollDirSelect setEnabled:enabled];
+}
 -(void) load {
 -(void) load {
-       id jsaction = [joystickController selectedAction];
+       id jsaction = joystickController.selectedAction;
        currentJsaction = jsaction;
        if(!jsaction) {
        currentJsaction = jsaction;
        if(!jsaction) {
-               [self setEnabled: NO];
-               [title setStringValue: @""];
+        self.enabled = NO;
+        title.stringValue = @"";
                return;
        } else {
                return;
        } else {
-               [self setEnabled: YES];
+        self.enabled = YES;
        }
        }
-       Targettarget = configsController.currentConfig[jsaction];
+       Target *target = configsController.currentConfig[jsaction];
        
        id act = jsaction;
        NSString* actFullName = [act name];
        while([act base]) {
                act = [act base];
        
        id act = jsaction;
        NSString* actFullName = [act name];
        while([act base]) {
                act = [act base];
-               actFullName = [[NSString alloc] initWithFormat: @"%@ > %@", [act name], actFullName];
+               actFullName = [[NSString alloc] initWithFormat:@"%@ > %@", [act name], actFullName];
        }
        }
-       [title setStringValue: [[NSString alloc] initWithFormat: @"%@ > %@", [[configsController currentConfig] name], actFullName]];
+    title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, actFullName];
        
        if(!target) {
        
        if(!target) {
-               // already reset
-       } else if([target isKindOfClass: [TargetKeyboard class]]) {
-               [radioButtons setState:1 atRow: 1 column: 0];
-               [keyInput setVk: [(TargetKeyboard*)target vk]];
-       } else if([target isKindOfClass: [TargetConfig class]]) {
-               [radioButtons setState:1 atRow: 2 column: 0];
-               [configPopup selectItemAtIndex: [[configsController configs] indexOfObject: [(TargetConfig*)target config]]];
+               [radioButtons setState:1 atRow:0 column:0];
+       } else if([target isKindOfClass:[TargetKeyboard class]]) {
+               [radioButtons setState:1 atRow:1 column:0];
+        keyInput.vk = [(TargetKeyboard*)target vk];
+       } else if([target isKindOfClass:[TargetConfig class]]) {
+               [radioButtons setState:1 atRow:2 column:0];
+               [configPopup selectItemAtIndex:[configsController.configs
+                                        indexOfObject:[(TargetConfig *)target config]]];
     }
     }
-    else if ([target isKindOfClass: [TargetMouseMove class]]) {
-        [radioButtons setState:1 atRow: 3 column: 0];
-        [mouseDirSelect setSelectedSegment: [(TargetMouseMove *)target dir]];
+    else if ([target isKindOfClass:[TargetMouseMove class]]) {
+        [radioButtons setState:1 atRow:3 column:0];
+        [mouseDirSelect setSelectedSegment:[(TargetMouseMove *)target dir]];
        }
        }
-    else if ([target isKindOfClass: [TargetMouseBtn class]]) {
-        [radioButtons setState: 1 atRow: 4 column: 0];
-        if ([(TargetMouseBtn *)target which] == kCGMouseButtonLeft)
-            [mouseBtnSelect setSelectedSegment: 0];
-        else
-            [mouseBtnSelect setSelectedSegment: 1];
+    else if ([target isKindOfClass:[TargetMouseBtn class]]) {
+        [radioButtons setState:1 atRow:4 column:0];
+        mouseBtnSelect.selectedSegment = [(TargetMouseBtn *)target which] == kCGMouseButtonLeft ? 0 : 1;
     }
     }
-    else if ([target isKindOfClass: [TargetMouseScroll class]]) {
-        [radioButtons setState: 1 atRow: 5 column: 0];
-        if ([(TargetMouseScroll *)target howMuch] < 0)
-            [scrollDirSelect setSelectedSegment: 0];
-        else
-            [scrollDirSelect setSelectedSegment: 1];
+    else if ([target isKindOfClass:[TargetMouseScroll class]]) {
+        [radioButtons setState:1 atRow:5 column:0];
+        scrollDirSelect.selectedSegment = [(TargetMouseScroll *)target howMuch] > 0;
     }
     }
-    else if ([target isKindOfClass: [TargetToggleMouseScope class]]) {
-        [radioButtons setState: 1 atRow: 6 column: 0];
+    else if ([target isKindOfClass:[TargetToggleMouseScope class]]) {
+        [radioButtons setState:1 atRow:6 column:0];
     } else {
     } else {
-               [NSException raise:@"Unknown target subclass" format:@"Unknown target subclass"];
+        NSLog(@"Unknown target type %@.", target.description);
        }
 }
 
 -(void) focusKey {
     Target *currentTarget = configsController.currentConfig[currentJsaction];
     if (!currentTarget || [currentTarget isKindOfClass:[TargetKeyboard class]])
        }
 }
 
 -(void) focusKey {
     Target *currentTarget = configsController.currentConfig[currentJsaction];
     if (!currentTarget || [currentTarget isKindOfClass:[TargetKeyboard class]])
-        [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: keyInput];
+        [[[NSApplication sharedApplication] mainWindow] makeFirstResponder:keyInput];
     else
         [keyInput resignFirstResponder];
 }
 
     else
         [keyInput resignFirstResponder];
 }
 
--(void) refreshConfigsPreservingSelection: (BOOL) preserve  {
+- (void)refreshConfigsPreservingSelection:(BOOL)preserve  {
        int initialIndex = [configPopup indexOfSelectedItem];
        int initialIndex = [configPopup indexOfSelectedItem];
-       
-       NSArray* configs = [configsController configs];
        [configPopup removeAllItems];
        [configPopup removeAllItems];
-       for(int i=0; i<[configs count]; i++) {
-               [configPopup addItemWithTitle: [configs[i]name]];
-       }
-       if(preserve)
-               [configPopup selectItemAtIndex:initialIndex];
-               
+       for (Config *config in configsController.configs)
+               [configPopup addItemWithTitle:config.name];
+    [configPopup selectItemAtIndex:preserve ? initialIndex : -1];
 }
 
 @end
 }
 
 @end