Revision: 29532
          http://sourceforge.net/p/bibdesk/svn/29532
Author:   hofman
Date:     2025-09-05 16:10:00 +0000 (Fri, 05 Sep 2025)
Log Message:
-----------
pass nil as download destination to cancel BDSKDownload

Modified Paths:
--------------
    trunk/bibdesk/BDSKDownloadManager.m
    trunk/bibdesk/BDSKDownloader.h
    trunk/bibdesk/BDSKDownloader.m
    trunk/bibdesk/BDSKTextImportController.m

Modified: trunk/bibdesk/BDSKDownloadManager.m
===================================================================
--- trunk/bibdesk/BDSKDownloadManager.m 2025-09-05 15:54:40 UTC (rev 29531)
+++ trunk/bibdesk/BDSKDownloadManager.m 2025-09-05 16:10:00 UTC (rev 29532)
@@ -316,18 +316,10 @@
     [sPanel setNameFieldStringValue:filename];
     [sPanel setDirectoryURL:downloadsURL];
     
-    if ([sPanel runModal] == NSModalResponseOK) {
+    if ([sPanel runModal] == NSModalResponseOK)
         completionHandler([sPanel URL], YES);
-    } else {
-        [download cancel];
-        
-        BDSKWebDownload *webDownload = [self webDownloadForDownload:download];
-        [webDownload setStatus:BDSKDownloadStatusFailed];
-        
-        if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKRemoveFailedDownloadsKey] && webDownload)
-            [downloads removeObject:webDownload];
-        [self notifyUpdate];
-    }
+    else
+        completionHandler(nil, NO);
 }
 
 #pragma mark WKDownload delegate protocol

Modified: trunk/bibdesk/BDSKDownloader.h
===================================================================
--- trunk/bibdesk/BDSKDownloader.h      2025-09-05 15:54:40 UTC (rev 29531)
+++ trunk/bibdesk/BDSKDownloader.h      2025-09-05 16:10:00 UTC (rev 29532)
@@ -97,7 +97,7 @@
 - (NSWindow *)downloadWindowForAuthenticationSheet:(BDSKDownload *)download;
 
 // only for file downloads
-- (void)download:(BDSKDownload *)download 
decideDestinationWithSuggestedFilename:(NSString *)destinationName 
completionHandler:(void (^)(NSURL *destinationURL, BOOL 
allowOverwrite))completionHandler;
+- (void)download:(BDSKDownload *)download 
decideDestinationWithSuggestedFilename:(NSString *)destinationName 
completionHandler:(void (^)(NSURL *_Nullable destinationURL, BOOL 
allowOverwrite))completionHandler;
 - (void)download:(BDSKDownload *)download didCreateDestination:(NSURL 
*)destinationURL;
 
 @end

Modified: trunk/bibdesk/BDSKDownloader.m
===================================================================
--- trunk/bibdesk/BDSKDownloader.m      2025-09-05 15:54:40 UTC (rev 29531)
+++ trunk/bibdesk/BDSKDownloader.m      2025-09-05 16:10:00 UTC (rev 29532)
@@ -158,24 +158,30 @@
     NSString *suggestedFileName = [[task response] suggestedFilename] ?: 
[location lastPathComponent];
     
     [download _decideDestinationWithSuggestedFilename:suggestedFileName 
completionHandler:^(NSURL *destinationURL, BOOL allowOverwrite){
-        NSError *error = nil;
-        NSFileManager *fm = [NSFileManager defaultManager];
-        if ([destinationURL checkResourceIsReachableAndReturnError:NULL]) {
-            if (allowOverwrite) {
-                [fm removeItemAtURL:destinationURL error:NULL];
+        if (destinationURL == nil) {
+            NSError *error = [NSError errorWithDomain:NSURLErrorDomain 
code:NSURLErrorCancelled userInfo:nil];
+            [download _didCompleteWithError:error];
+            [self cleanupDownload:download];
+        } else {
+            NSError *error = nil;
+            NSFileManager *fm = [NSFileManager defaultManager];
+            if ([destinationURL checkResourceIsReachableAndReturnError:NULL]) {
+                if (allowOverwrite) {
+                    [fm removeItemAtURL:destinationURL error:NULL];
+                } else {
+                    destinationURL = [fm uniqueFileURL:destinationURL];
+                }
+            } else if ([[destinationURL URLByDeletingLastPathComponent] 
checkResourceIsReachableAndReturnError:NULL] == NO) {
+                [fm createDirectoryAtPath:[[destinationURL 
URLByDeletingLastPathComponent] path] withIntermediateDirectories:YES 
attributes:nil error:NULL];
+            }
+            if ([fm moveItemAtURL:location toURL:destinationURL error:&error]) 
{
+                [download _didCreateDestination:destinationURL];
+                [download _didCompleteWithError:nil];
             } else {
-                destinationURL = [fm uniqueFileURL:destinationURL];
+                [download _didCompleteWithError:error];
+                [self cleanupDownload:download];
             }
-        } else if ([[destinationURL URLByDeletingLastPathComponent] 
checkResourceIsReachableAndReturnError:NULL] == NO) {
-            [fm createDirectoryAtPath:[[destinationURL 
URLByDeletingLastPathComponent] path] withIntermediateDirectories:YES 
attributes:nil error:NULL];
         }
-        if ([fm moveItemAtURL:location toURL:destinationURL error:&error]) {
-            [download _didCreateDestination:destinationURL];
-            [download _didCompleteWithError:nil];
-        } else {
-            [download _didCompleteWithError:error];
-            [self cleanupDownload:download];
-        }
     }];
 }
 

Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m    2025-09-05 15:54:40 UTC (rev 
29531)
+++ trunk/bibdesk/BDSKTextImportController.m    2025-09-05 16:10:00 UTC (rev 
29532)
@@ -1223,7 +1223,7 @@
         if (result == NSModalResponseOK)
             completionHandler([sPanel URL], YES);
         else
-            [self cancelDownload];
+            completionHandler(nil, NO);
     }];
 }
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to