--(void) keyChanged {
- [radioButtons setState: 1 atRow: 1 column: 0 ];
- [self commit];
-}
--(IBAction)radioChanged:(id)sender {
- [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
- [self commit];
-}
--(IBAction)mdirChanged:(id)sender {
- [radioButtons setState: 1 atRow: 3 column: 0];
- [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
- [self commit];
-}
--(IBAction)mbtnChanged:(id)sender {
- [radioButtons setState: 1 atRow: 4 column: 0];
- [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
- [self commit];
-}
--(IBAction)sdirChanged:(id)sender {
- [radioButtons setState: 1 atRow: 5 column: 0];
- [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
- [self commit];
-}
-
-
--(Target*) state {
- switch([radioButtons selectedRow]) {
- case 0: // none
- return NULL;
- case 1: // key
- if(keyInput.hasKey) {
- TargetKeyboard* k = [[TargetKeyboard alloc] init];
- [k setVk: [keyInput vk]];
- [k setDescr: [keyInput descr]];
- return k;
- }
- break;
- case 2:
- {
- TargetConfig* c = [[TargetConfig alloc] init];
- [c setConfig: [configsController configs][[configPopup indexOfSelectedItem]]];
- return c;
- }
+- (void)cleanUpInterface {
+ NSInteger row = radioButtons.selectedRow;
+
+ if (row != 1) {
+ keyInput.vk = -1;
+ [keyInput resignIfFirstResponder];
+ }
+
+ if (row != 2) {
+ [configPopup selectItemAtIndex:-1];
+ [configPopup resignIfFirstResponder];
+ } else if (!configPopup.selectedItem)
+ [configPopup selectItemAtIndex:0];
+
+ if (row != 3) {
+ mouseDirSelect.selectedSegment = -1;
+ [mouseDirSelect resignIfFirstResponder];
+ } else if (mouseDirSelect.selectedSegment == -1)
+ mouseDirSelect.selectedSegment = 0;
+
+ if (row != 4) {
+ mouseBtnSelect.selectedSegment = -1;
+ [mouseBtnSelect resignIfFirstResponder];
+ } else if (mouseBtnSelect.selectedSegment == -1)
+ mouseBtnSelect.selectedSegment = 0;
+
+ if (row != 5) {
+ scrollDirSelect.selectedSegment = -1;
+ [scrollDirSelect resignIfFirstResponder];
+ } else if (scrollDirSelect.selectedSegment == -1)
+ scrollDirSelect.selectedSegment = 0;
+}
+
+- (IBAction)radioChanged:(NSView *)sender {
+ [sender.window makeFirstResponder:sender];
+ if (radioButtons.selectedRow == 1)
+ [keyInput.window makeFirstResponder:keyInput];
+ [self commit];
+}
+
+- (void)keyChanged {
+ [radioButtons selectCellAtRow:1 column:0];
+ [radioButtons.window makeFirstResponder:radioButtons];
+ [self commit];
+}
+
+- (void)configChosen:(id)sender {
+ [radioButtons selectCellAtRow:2 column:0];
+ [configPopup.window makeFirstResponder:configPopup];
+ [self commit];
+}
+
+- (void)mdirChanged:(NSView *)sender {
+ [radioButtons selectCellAtRow:3 column:0];
+ [sender.window makeFirstResponder:sender];
+ [self commit];
+}
+
+- (void)mbtnChanged:(NSView *)sender {
+ [radioButtons selectCellAtRow:4 column:0];
+ [sender.window makeFirstResponder:sender];
+ [self commit];
+}
+
+- (void)sdirChanged:(NSView *)sender {
+ [radioButtons selectCellAtRow:5 column:0];
+ [sender.window makeFirstResponder:sender];
+ [self commit];
+}
+
+- (Target *)currentTarget {
+ return configsController.currentConfig[joystickController.selectedAction];
+}
+
+- (Target *)makeTarget {
+ switch (radioButtons.selectedRow) {
+ case 0:
+ return nil;
+ case 1:
+ if (keyInput.hasKey) {
+ TargetKeyboard *k = [[TargetKeyboard alloc] init];
+ k.vk = keyInput.vk;
+ return k;
+ } else {
+ return nil;
+ }
+ break;
+ case 2: {
+ TargetConfig *c = [[TargetConfig alloc] init];
+ c.config = configsController.configs[configPopup.indexOfSelectedItem];
+ return c;
+ }