- [self mappingsChanged];
- }
-}
-
-- (void)mappingConflictDidResolve:(NSAlert *)alert
- returnCode:(NSInteger)returnCode
- contextInfo:(void *)contextInfo {
- NSDictionary *userInfo = CFBridgingRelease(contextInfo);
- NJMapping *oldMapping = userInfo[@"old mapping"];
- NJMapping *newMapping = userInfo[@"new mapping"];
- switch (returnCode) {
- case NSAlertFirstButtonReturn: // Merge
- [oldMapping mergeEntriesFrom:newMapping];
- [self activateMapping:oldMapping];
- [self mappingsChanged];
- break;
- case NSAlertThirdButtonReturn: // New Mapping
- [_mappings addObject:newMapping];
- [self activateMapping:newMapping];
- [self mappingsChanged];
- [self mappingPressed:alert];
- [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:_mappings.count - 1] byExtendingSelection:NO];
- [tableView editColumn:0 row:_mappings.count - 1 withEvent:nil select:YES];
- break;
- default: // Cancel, other.
- break;
- }
-}
-
-- (void)addMappingWithContentsOfURL:(NSURL *)url {
- NSWindow *window = popoverActivate.window;
- NSError *error;
- NJMapping *mapping = [NJMapping mappingWithContentsOfURL:url
- mappings:_mappings
- error:&error];
-
- if (mapping && !error) {
- 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:popoverActivate.window
- modalDelegate:self
- didEndSelector:@selector(mappingConflictDidResolve:returnCode:contextInfo:)
- contextInfo:(void *)CFBridgingRetain(@{ @"old mapping": mergeInto,
- @"new mapping": mapping })];
- } else {
- [_mappings addObject:mapping];
- [self activateMapping:mapping];
- [self mappingsChanged];
- }
- }
-
- if (error) {
- [window presentError:error
- modalForWindow:window
- delegate:nil
- didPresentSelector:nil
- contextInfo:nil];