X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJMappingsController.m;fp=Classes%2FNJMappingsController.m;h=5faa4bf47d0384dac19695592aacf51335fa36c9;hp=0db11111ca0ae8995ba4ce2a008f175b948983c9;hb=52fbe3168fcb8237252bdc2a723c08eb7c1a8741;hpb=a693c12733277a53d38580d6a35222fa233a2af5 diff --git a/Classes/NJMappingsController.m b/Classes/NJMappingsController.m index 0db1111..5faa4bf 100644 --- a/Classes/NJMappingsController.m +++ b/Classes/NJMappingsController.m @@ -195,6 +195,31 @@ } } +- (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; @@ -204,42 +229,29 @@ if (mapping && !error) { NJMapping *mergeInto = self[mapping.name]; - BOOL conflict = [mergeInto hasConflictWith:mapping]; - - if (conflict) { + if ([mergeInto hasConflictWith:mapping]) { NSAlert *conflictAlert = [[NSAlert alloc] init]; conflictAlert.messageText = @"Replace existing mappings?"; conflictAlert.informativeText = [NSString stringWithFormat: - @"This file contains inputs you've already mapped in \"%@\". Do you " - @"want to merge them and replace your existing mappings, or import this " - @"as a separate mapping?", mapping.name]; + @"This file contains inputs you've already mapped in \"%@\". Do you " + @"want to merge them and replace your existing mappings, or import this " + @"as a separate mapping?", mapping.name]; [conflictAlert addButtonWithTitle:@"Merge"]; [conflictAlert addButtonWithTitle:@"Cancel"]; [conflictAlert addButtonWithTitle:@"New Mapping"]; - NSInteger res = [conflictAlert runModal]; - if (res == NSAlertSecondButtonReturn) - return; - else if (res == NSAlertThirdButtonReturn) - mergeInto = nil; - } - - if (mergeInto) { - [mergeInto mergeEntriesFrom:mapping]; - mapping = mergeInto; + [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 (conflict && !mergeInto) { - [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:_mappings.count - 1] byExtendingSelection:NO]; - [tableView editColumn:0 row:_mappings.count - 1 withEvent:nil select:YES]; + [self activateMapping:mapping]; + [self mappingsChanged]; } } - + if (error) { [window presentError:error modalForWindow:window