From f0909929a979b62a110e230e8b384cafaed33eba Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Wed, 6 Mar 2013 23:53:29 +0100 Subject: [PATCH] Controls to reorder the mapping list. --- English.lproj/MainMenu.xib | 154 ++++++++++++++++++++++++++++++++++++- NJMappingsController.h | 4 + NJMappingsController.m | 36 +++++++-- 3 files changed, 185 insertions(+), 9 deletions(-) diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index b76cc8e..cd9a1b9 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -1223,10 +1223,10 @@ 268 - {{66, -1}, {134, 23}} + {{66, -1}, {68, 23}} - + _NS:22 YES @@ -1276,6 +1276,52 @@ NO + + + 292 + {{166, -1}, {34, 23}} + + + + YES + + 67108864 + 134479872 + ⬇ + + + -2033434624 + 268435618 + +  + 400 + 75 + + NO + + + + 292 + {{133, -1}, {34, 23}} + + + + YES + + 67108864 + 134479872 + ⬆ + + + -2033434624 + 268435618 + +  + 400 + 75 + + NO + 292 @@ -1598,6 +1644,38 @@ 515 + + + moveUpPressed: + + + + 899 + + + + moveDownPressed: + + + + 900 + + + + moveUp + + + + 901 + + + + moveDown + + + + 902 + dataSource @@ -2000,6 +2078,8 @@ + + Mapping List Popover Content @@ -2487,6 +2567,34 @@ + + 893 + + + + + + Move Mapping Up + + + 894 + + + + + 896 + + + + + + Move Mapping Down + + + 897 + + + @@ -2641,13 +2749,33 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Move the selected mapping up the list + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Move the selected mapping down the list + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - 892 + 902 @@ -2758,6 +2886,8 @@ id id id + id + id id @@ -2777,12 +2907,22 @@ mappingPressed: id + + moveDownPressed: + id + + + moveUpPressed: + id + removePressed: id + NSButton + NSButton NJOutputController NSPopover NSButton @@ -2790,6 +2930,14 @@ NSTableView + + moveDown + NSButton + + + moveUp + NSButton + outputController NJOutputController diff --git a/NJMappingsController.h b/NJMappingsController.h index f0dab4f..2f7ede0 100644 --- a/NJMappingsController.h +++ b/NJMappingsController.h @@ -20,6 +20,8 @@ IBOutlet NJOutputController *outputController; IBOutlet NSButton *popoverActivate; IBOutlet NSPopover *popover; + IBOutlet NSButton *moveUp; + IBOutlet NSButton *moveDown; } @property (nonatomic, readonly) NJMapping *currentMapping; @@ -35,6 +37,8 @@ - (IBAction)mappingPressed:(id)sender; - (IBAction)addPressed:(id)sender; - (IBAction)removePressed:(id)sender; +- (IBAction)moveUpPressed:(id)sender; +- (IBAction)moveDownPressed:(id)sender; - (IBAction)importPressed:(id)sender; - (IBAction)exportPressed:(id)sender; diff --git a/NJMappingsController.m b/NJMappingsController.m index 567f233..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]; @@ -71,6 +72,16 @@ } } +- (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 { if (!mapping) mapping = manualMapping; @@ -79,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]; } @@ -168,8 +175,8 @@ _mappings = newMappings; if (selected >= newMappings.count) selected = 0; - [self mappingsChanged]; [self activateMapping:_mappings[selected]]; + [self mappingsChanged]; } } @@ -317,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 -- 2.20.1