-- (void)importPressed:(id)sender {
- NSOpenPanel *panel = [NSOpenPanel openPanel];
- panel.allowedFileTypes = @[ @"enjoyable", @"json", @"txt" ];
- NSWindow *window = NSApplication.sharedApplication.keyWindow;
- [panel beginSheetModalForWindow:window
- completionHandler:^(NSInteger result) {
- if (result != NSFileHandlingPanelOKButton)
- return;
- [panel close];
- [self addMappingWithContentsOfURL:panel.URL];
- }];
-
-}
-
-- (void)exportPressed:(id)sender {
- NSSavePanel *panel = [NSSavePanel savePanel];
- panel.allowedFileTypes = @[ @"enjoyable" ];
- NJMapping *mapping = _currentMapping;
- panel.nameFieldStringValue = [mapping.name stringByFixingPathComponent];
- NSWindow *window = NSApplication.sharedApplication.keyWindow;
- [panel beginSheetModalForWindow:window
- completionHandler:^(NSInteger result) {
- if (result != NSFileHandlingPanelOKButton)
- return;
- [panel close];
- NSError *error;
- [mapping writeToURL:panel.URL error:&error];
- if (error) {
- [window presentError:error
- modalForWindow:window
- delegate:nil
- didPresentSelector:nil
- contextInfo:nil];
- }
- }];
-}
-
-- (IBAction)mappingPressed:(id)sender {
- [popover showRelativeToRect:popoverActivate.bounds
- ofView:popoverActivate
- preferredEdge:NSMinXEdge];
-}
-
-- (void)popoverWillShow:(NSNotification *)notification {
- popoverActivate.state = NSOnState;
-}
-
-- (void)popoverWillClose:(NSNotification *)notification {
- 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];
+- (void)renameMapping:(NJMapping *)mapping to:(NSString *)name {
+ mapping.name = name;
+ [self mappingsChanged];
+ if (mapping == _currentMapping) {
+ // FIXME: Hack to trigger updates in the rest of the UI.
+ _currentMapping = nil;
+ NJMapping *manual = _manualMapping;
+ [self activateMapping:mapping];
+ _manualMapping = manual;