Show import conflict alert as a sheet rather than a separate window.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Mon, 11 Mar 2013 12:02:28 +0000 (13:02 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Mon, 11 Mar 2013 12:02:28 +0000 (13:02 +0100)
Classes/NJMappingsController.m
Info.plist

index 0db11111ca0ae8995ba4ce2a008f175b948983c9..5faa4bf47d0384dac19695592aacf51335fa36c9 100644 (file)
     }
 }
 
+- (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;
     
     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
index 6665b11ebfaf38f633706cb4e164aba0d4f4da6c..0cda67cc8104aea4697b8611707a1166d44607e6 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>131</string>
+       <string>134</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>