Alessandro Bahgat avatar Alessandro Bahgat committed 58979ec

Fixed the behaviour of MercuiralApp so that ClonePanel is correctly closed even after an unexpected event

Comments (0)

Files changed (1)

Source/MercurialApp.m

 - (IBAction) runClonePanel: (id)sender
 {
     [_clonePanel center];
-    if( [NSApp runModalForWindow: _clonePanel] == NSOKButton ) {
-        NSURL *srcURL = _cloneSrcURLField.objectValue;
-        NSURL *dstURL = _cloneDstURLField.objectValue;
-        if( ! srcURL || ! dstURL ) {
-            NSBeep();
-            return;
+
+    BOOL terminate = YES;
+    do {
+        if( [NSApp runModalForWindow: _clonePanel] == NSOKButton ) {
+            NSURL *srcURL = _cloneSrcURLField.objectValue;
+            NSURL *dstURL = _cloneDstURLField.objectValue;
+            if( ! srcURL || ! dstURL ) {
+                NSBeep();
+                // operation not completed because one of the URLs (or both) is invalid
+                terminate = NO;
+                continue;
+            } else {
+                Log(@"Clone from <%@> to <%@>",srcURL,dstURL);
+                NSError *error = nil;
+                HgOperation *op = [HgRepository cloneRevision: nil fromURL: srcURL toURL: dstURL
+                                                      options: kHgUpdateAfterwards];
+                if( ! [op run: &error] ) {
+                    [NSApp presentError: error];
+                    // operation not completed because of error
+                    terminate = NO;
+                    continue;
+                }
+                if( dstURL.isFileURL )
+                    [self openRepository: dstURL.path remember: YES];
+                else
+                    NSRunInformationalAlertPanel(NSLocalizedString(@"Cloned Repository", 
+                                                                   @"Title of post-clone success alert"),
+                                                 NSLocalizedString(@"Successfully created a cloned repository at \n\n%@", 
+                                                                   @"Body of post-clone success alert"),
+                                                 nil, nil, nil,
+                                                 dstURL.absoluteString);
+                
+                // ok button was pressed and clone was performed
+                terminate = YES;
+                continue;
+            }
+        } else {
+            // cancel button was pressed
+            terminate = YES;
+            continue;
         }
-        Log(@"Clone from <%@> to <%@>",srcURL,dstURL);
-        NSError *error = nil;
-        HgOperation *op = [HgRepository cloneRevision: nil fromURL: srcURL toURL: dstURL
-                                              options: kHgUpdateAfterwards];
-        if( ! [op run: &error] ) {
-            [NSApp presentError: error];
-            return;
-        }
-        if( dstURL.isFileURL )
-            [self openRepository: dstURL.path remember: YES];
-        else
-            NSRunInformationalAlertPanel(NSLocalizedString(@"Cloned Repository", 
-                                                           @"Title of post-clone success alert"),
-                                         NSLocalizedString(@"Successfully created a cloned repository at \n\n%@", 
-                                                           @"Body of post-clone success alert"),
-                                         nil, nil, nil,
-                                         dstURL.absoluteString);
-    }
+    } while ( ! terminate );
+    
     [_clonePanel orderOut: self];
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.