-- (void)addOrMergeMapping:(NJMapping *)mapping atIndex:(NSInteger)idx {
- NSWindow *window = NSApplication.sharedApplication.keyWindow;
- if (mapping) {
- NJMapping *mergeInto = self[mapping.name];
- if ([mergeInto hasConflictWith:mapping]) {
- NSAlert *conflictAlert = [[NSAlert alloc] init];
- conflictAlert.messageText = NSLocalizedString(@"import conflict prompt", @"Title of import conflict alert");
- conflictAlert.informativeText =
- [NSString stringWithFormat:NSLocalizedString(@"import conflict in %@", @"Explanation of import conflict"),
- mapping.name];
- [conflictAlert addButtonWithTitle:NSLocalizedString(@"import and merge", @"button to merge imported mappings")];
- [conflictAlert addButtonWithTitle:NSLocalizedString(@"cancel import", @"button to cancel import")];
- [conflictAlert addButtonWithTitle:NSLocalizedString(@"import new mapping", @"button to import as new mapping")];
- [conflictAlert beginSheetModalForWindow:window
- modalDelegate:self
- didEndSelector:@selector(mappingConflictDidResolve:returnCode:contextInfo:)
- contextInfo:(void *)CFBridgingRetain(@{ @"old mapping": mergeInto,
- @"new mapping": mapping })];
- } else if (mergeInto) {
- [mergeInto mergeEntriesFrom:mapping];
- [self activateMapping:mergeInto];
- [self mappingsChanged];
- } else {
- if (idx == -1)
- idx = _mappings.count;
- [self.mvc.mappingList beginUpdates];
- [_mappings insertObject:mapping atIndex:idx];
- [self.mvc addedMappingAtIndex:idx startEditing:NO];
- [self.mvc.mappingList endUpdates];
- [self activateMapping:mapping];
- [self mappingsChanged];
- }
- }
-}
-
-- (NSInteger)numberOfMappings:(NJMappingsViewController *)dvc {
- return _mappings.count;
-}
-
-- (NJMapping *)mappingsViewController:(NJMappingsViewController *)dvc
- mappingForIndex:(NSUInteger)idx {
- return _mappings[idx];
-}
-
-- (void)mappingsViewController:(NJMappingsViewController *)mvc
- editedMappingAtIndex:(NSInteger)index {