X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=NJMappingsController.m;h=a1171a0088ffc0f69c64d26e43f23d449467cf69;hp=43f6282a4fc6876814fd4c2e439a34becffa43da;hb=f0909929a979b62a110e230e8b384cafaed33eba;hpb=6044e47a97de33531c47cd209b30d4405aa0530a diff --git a/NJMappingsController.m b/NJMappingsController.m index 43f6282..a1171a0 100644 --- a/NJMappingsController.m +++ b/NJMappingsController.m @@ -43,6 +43,7 @@ [self save]; [tableView reloadData]; popoverActivate.title = _currentMapping.name; + [self updateInterfaceForCurrentMapping]; [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingListChanged object:_mappings]; @@ -56,15 +57,29 @@ count:len]; } - - (void)activateMappingForProcess:(NSString *)processName { - NJMapping *oldMapping = manualMapping; - NJMapping *newMapping = self[processName]; - if (!newMapping) - newMapping = oldMapping; - if (newMapping != _currentMapping) - [self activateMapping:newMapping]; - manualMapping = oldMapping; + if ([manualMapping.name.lowercaseString isEqualToString:@"@application"]) { + manualMapping.name = processName; + [self mappingsChanged]; + } else { + NJMapping *oldMapping = manualMapping; + NJMapping *newMapping = self[processName]; + if (!newMapping) + newMapping = oldMapping; + if (newMapping != _currentMapping) + [self activateMapping:newMapping]; + manualMapping = oldMapping; + } +} + +- (void)updateInterfaceForCurrentMapping { + NSUInteger selected = [_mappings indexOfObject:_currentMapping]; + [removeButton setEnabled:selected != 0]; + [moveDown setEnabled:selected && selected != _mappings.count - 1]; + [moveUp setEnabled:selected > 1]; + popoverActivate.title = _currentMapping.name; + [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:selected] byExtendingSelection:NO]; + [NSUserDefaults.standardUserDefaults setInteger:selected forKey:@"selected"]; } - (void)activateMapping:(NJMapping *)mapping { @@ -75,12 +90,8 @@ NSLog(@"Switching to mapping %@.", mapping.name); manualMapping = mapping; _currentMapping = mapping; - [removeButton setEnabled:_mappings[0] != mapping]; + [self updateInterfaceForCurrentMapping]; [outputController loadCurrent]; - popoverActivate.title = _currentMapping.name; - NSUInteger selected = [_mappings indexOfObject:mapping]; - [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:selected] byExtendingSelection:NO]; - [NSUserDefaults.standardUserDefaults setInteger:selected forKey:@"selected"]; [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingChanged object:_currentMapping]; } @@ -164,8 +175,8 @@ _mappings = newMappings; if (selected >= newMappings.count) selected = 0; - [self mappingsChanged]; [self activateMapping:_mappings[selected]]; + [self mappingsChanged]; } } @@ -313,4 +324,21 @@ popoverActivate.state = NSOffState; } +- (IBAction)moveUpPressed:(id)sender { + NSUInteger idx = [_mappings indexOfObject:_currentMapping]; + if (idx > 1 && idx != NSNotFound) { + [_mappings exchangeObjectAtIndex:idx withObjectAtIndex:idx - 1]; + [self mappingsChanged]; + } +} + +- (IBAction)moveDownPressed:(id)sender { + NSUInteger idx = [_mappings indexOfObject:_currentMapping]; + if (idx < _mappings.count - 1) { + [_mappings exchangeObjectAtIndex:idx withObjectAtIndex:idx + 1]; + [self mappingsChanged]; + } +} + + @end