Revision: 29991
          http://sourceforge.net/p/bibdesk/svn/29991
Author:   hofman
Date:     2026-02-15 16:14:39 +0000 (Sun, 15 Feb 2026)
Log Message:
-----------
run save panel for item download async, in sheet if possible

Modified Paths:
--------------
    trunk/bibdesk/BDSKItemDownload.h
    trunk/bibdesk/BDSKItemDownload.m
    trunk/bibdesk/BibItem.m

Modified: trunk/bibdesk/BDSKItemDownload.h
===================================================================
--- trunk/bibdesk/BDSKItemDownload.h    2026-02-14 18:32:53 UTC (rev 29990)
+++ trunk/bibdesk/BDSKItemDownload.h    2026-02-15 16:14:39 UTC (rev 29991)
@@ -85,7 +85,7 @@
 - (void)itemDownloadDidStart:(BDSKItemDownload *)download;
 - (void)itemDownloadDidUpdate:(BDSKItemDownload *)download;
 - (void)itemDownloadDidFinish:(BDSKItemDownload *)download;
-- (nullable NSWindow 
*)itemDownloadWindowForAuthenticationSheet:(BDSKItemDownload *)download;
+- (nullable NSWindow *)itemDownloadWindowForSheet:(BDSKItemDownload *)download;
 
 @end
 

Modified: trunk/bibdesk/BDSKItemDownload.m
===================================================================
--- trunk/bibdesk/BDSKItemDownload.m    2026-02-14 18:32:53 UTC (rev 29990)
+++ trunk/bibdesk/BDSKItemDownload.m    2026-02-15 16:14:39 UTC (rev 29991)
@@ -100,7 +100,6 @@
 #pragma mark  BDSKDownloadDelegate
 
 - (void)download:(BDSKDownload *)aDownload 
decideDestinationWithSuggestedFilename:(NSString *)destinationName 
completionHandler:(void (^)(NSURL *destinationURL))completionHandler {
-    NSURL *destURL = nil;
     NSString *extension = [destinationName pathExtension];
     NSString *downloadsDirectory = [[[NSUserDefaults standardUserDefaults] 
stringForKey:BDSKDownloadsDirectoryKey] stringByExpandingTildeInPath];
     BOOL isDir;
@@ -109,7 +108,13 @@
         downloadsDirectory = [[[NSFileManager defaultManager] 
downloadFolderURL] path];
     
     if ([NSString isEmptyString:extension] == NO && [[NSFileManager 
defaultManager] fileExistsAtPath:downloadsDirectory isDirectory:&isDir] && 
isDir) {
-        destURL = [NSURL fileURLWithPath:[downloadsDirectory 
stringByAppendingPathComponent:destinationName] isDirectory:NO];
+        NSURL *destURL = [NSURL fileURLWithPath:[downloadsDirectory 
stringByAppendingPathComponent:destinationName] isDirectory:NO];
+        if (destURL == nil)
+            destURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() 
stringByAppendingPathComponent:destinationName]];
+        if ([destURL checkResourceIsReachableAndReturnError:NULL])
+            destURL = [[NSFileManager defaultManager] uniqueFileURL:destURL];
+        fileURL = destURL;
+        completionHandler(destURL);
     } else {
         NSSavePanel *savePanel = [NSSavePanel savePanel];
         if (NO == [extension isEqualToString:@""])
@@ -117,15 +122,21 @@
         [savePanel setAllowsOtherFileTypes:YES];
         [savePanel setCanSelectHiddenExtension:YES];
         [savePanel setNameFieldStringValue:destinationName];
-        if (NSModalResponseOK == [savePanel runModal])
-            destURL = [savePanel URL];
+        void (^handler)(NSModalResponse) = ^(NSModalResponse result){
+            NSURL *destURL = result == NSModalResponseOK ? [savePanel URL] : 
nil;
+            if (destURL == nil)
+                destURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() 
stringByAppendingPathComponent:destinationName]];
+            if ([destURL checkResourceIsReachableAndReturnError:NULL])
+                destURL = [[NSFileManager defaultManager] 
uniqueFileURL:destURL];
+            fileURL = destURL;
+            completionHandler(destURL);
+        };
+        NSWindow *window = [[self delegate] itemDownloadWindowForSheet:self];
+        if (window)
+            [savePanel beginSheetModalForWindow:window 
completionHandler:handler];
+        else
+            [savePanel beginWithCompletionHandler:handler];
     }
-    if (destURL == nil)
-        destURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() 
stringByAppendingPathComponent:destinationName]];
-    if ([destURL checkResourceIsReachableAndReturnError:NULL])
-        destURL = [[NSFileManager defaultManager] uniqueFileURL:destURL];
-    fileURL = destURL;
-    completionHandler(destURL);
 }
 
 - (void)download:(BDSKDownload *)aDownload 
didReceiveExpectedContentLength:(int64_t)expectedContentLength {
@@ -147,7 +158,7 @@
 }
 
 - (NSWindow *)downloadWindowForAuthenticationSheet:(BDSKDownload *)download {
-    return [[self delegate] itemDownloadWindowForAuthenticationSheet:self];
+    return [[self delegate] itemDownloadWindowForSheet:self];
 }
 
 @end

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2026-02-14 18:32:53 UTC (rev 29990)
+++ trunk/bibdesk/BibItem.m     2026-02-15 16:14:39 UTC (rev 29991)
@@ -3332,7 +3332,7 @@
     }
 }
 
-- (NSWindow *)itemDownloadWindowForAuthenticationSheet:(BDSKItemDownload 
*)download {
+- (NSWindow *)itemDownloadWindowForSheet:(BDSKItemDownload *)download {
     return [[self owner] windowForSheetForObject:self];
 }
 

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