Stack errors.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 20 Mar 2013 21:35:10 +0000 (22:35 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 20 Mar 2013 21:35:10 +0000 (22:35 +0100)
Classes/EnjoyableApplicationDelegate.m
Info.plist

index beab960..b21ee77 100644 (file)
@@ -15,6 +15,7 @@
 
 @implementation EnjoyableApplicationDelegate {
     NSStatusItem *statusItem;
+    NSMutableArray *_errors;
 }
 
 - (void)didSwitchApplication:(NSNotification *)note {
     return self.dockMenu;
 }
 
+- (void)showNextError {
+    if (!self.window.attachedSheet && _errors.count) {
+        NSError *error = _errors.lastObject;
+        [_errors removeLastObject];
+        [NSApplication.sharedApplication activateIgnoringOtherApps:YES];
+        [self.window makeKeyAndOrderFront:nil];
+        [self.window presentError:error
+                   modalForWindow:self.window
+                         delegate:self
+               didPresentSelector:@selector(didPresentErrorWithRecovery:contextInfo:)
+                      contextInfo:nil];
+    }
+}
+
+- (void)didPresentErrorWithRecovery:(BOOL)didRecover
+                        contextInfo:(void *)contextInfo {
+    [self showNextError];
+}
+
+- (void)presentErrorSheet:(NSError *)error {
+    if (!_errors)
+        _errors = [[NSMutableArray alloc] initWithCapacity:1];
+    [_errors insertObject:error atIndex:0];
+    [self showNextError];
+}
+
 - (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
     [self restoreToForeground:sender];
     NSError *error;
         [self.mvc endUpdates];
         [self.ic activateMapping:mapping];
     } else {
-        [self.window presentError:error
-                   modalForWindow:self.window
-                         delegate:nil
-               didPresentSelector:nil
-                      contextInfo:nil];
+        [self presentErrorSheet:error];
     }
     return !!mapping;
 }
                       } else if (mapping) {
                           [self.ic addMapping:mapping];
                       } else {
-                          [self.window presentError:error
-                                     modalForWindow:self.window
-                                           delegate:nil
-                                 didPresentSelector:nil
-                                        contextInfo:nil];
+                          [self presentErrorSheet:error];
                       }
                   }];
     
                       [panel close];
                       NSError *error;
                       if (![mapping writeToURL:panel.URL error:&error]) {
-                          [self.window presentError:error
-                                     modalForWindow:self.window
-                                           delegate:nil
-                                 didPresentSelector:nil
-                                        contextInfo:nil];
+                          [self presentErrorSheet:error];
                       }
                   }];
 }
 }
 
 - (void)inputController:(NJInputController *)ic didError:(NSError *)error {
-    // Since the error shows the window, it can trigger another attempt
-    // to re-open the HID manager, which will also probably fail and error,
-    // so don't bother repeating ourselves.
-    if (!self.window.attachedSheet) {
-        [NSApplication.sharedApplication activateIgnoringOtherApps:YES];
-        [self.window makeKeyAndOrderFront:nil];
-        [self.window presentError:error
-                   modalForWindow:self.window
-                         delegate:nil
-               didPresentSelector:nil
-                      contextInfo:nil];
-    }
+    [self presentErrorSheet:error];
 }
 
 - (NSInteger)numberOfDevicesInDeviceList:(NJDeviceViewController *)dvc {
index 64274c3..d1e308d 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>573</string>
+       <string>575</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>