X-Git-Url: https://git.yukkurigames.com/?a=blobdiff_plain;f=Classes%2FNJMappingsController.m;h=5faa4bf47d0384dac19695592aacf51335fa36c9;hb=52fbe3168fcb8237252bdc2a723c08eb7c1a8741;hp=ad88d73d9740c1fc9fd8be4c1c52b688ff25cb38;hpb=3fae21830d647cf9c208fc8f96e23efedccdbd0e;p=enjoyable.git diff --git a/Classes/NJMappingsController.m b/Classes/NJMappingsController.m index ad88d73..5faa4bf 100644 --- a/Classes/NJMappingsController.m +++ b/Classes/NJMappingsController.m @@ -52,7 +52,8 @@ [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingListChanged object:self - userInfo:@{ @"mappings": _mappings }]; + userInfo:@{ NJMappingListKey: _mappings, + NJMappingKey: _currentMapping }]; } - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state @@ -107,8 +108,8 @@ [self updateInterfaceForCurrentMapping]; [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingChanged - object:self - userInfo:@{ @"mapping": _currentMapping }]; + object:self + userInfo:@{ NJMappingKey : _currentMapping }]; } - (IBAction)addPressed:(id)sender { @@ -194,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; @@ -203,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