Revision: 23923
          http://sourceforge.net/p/bibdesk/svn/23923
Author:   hofman
Date:     2019-07-03 09:23:58 +0000 (Wed, 03 Jul 2019)
Log Message:
-----------
Add or replace linked file at the end of the download rather than optionally 
adding a copy before to download

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

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2019-07-03 06:30:33 UTC (rev 23922)
+++ trunk/bibdesk/BDSKEditor.m  2019-07-03 09:23:58 UTC (rev 23923)
@@ -562,7 +562,7 @@
     } else {
         for (BDSKLinkedFile *file in [publication remoteURLs]) {
             if ([publication canDownloadLinkedFile:file])
-                [publication downloadCopyOfLinkedFile:file];
+                [publication downloadLinkedFile:file replace:NO];
         }
     }
 }
@@ -1735,10 +1735,10 @@
     return dragOp;
 }
 
-- (BOOL)fileView:(FVFileView *)aFileView shouldDownloadURL:(NSURL *)aURL 
atIndex:(NSUInteger)anIndex {
+- (BOOL)fileView:(FVFileView *)aFileView shouldDownloadURL:(NSURL *)aURL 
atIndex:(NSUInteger)anIndex replace:(BOOL)replace {
     BDSKLinkedFile *file = [publication objectInFilesAtIndex:anIndex];
     if ([publication canDownloadLinkedFile:file])
-        [publication downloadLinkedFile:file];
+        [publication downloadLinkedFile:file replace:replace];
     return NO;
 }
 

Modified: trunk/bibdesk/BDSKItemDownload.h
===================================================================
--- trunk/bibdesk/BDSKItemDownload.h    2019-07-03 06:30:33 UTC (rev 23922)
+++ trunk/bibdesk/BDSKItemDownload.h    2019-07-03 09:23:58 UTC (rev 23923)
@@ -49,6 +49,7 @@
     BDSKLinkedFile *linkedFile;
     NSURL *URL;
     NSUInteger index;
+    BOOL replace;
     int64_t expectedLength, receivedLength;
     NSURL *fileURL;
 }
@@ -57,9 +58,10 @@
 @property (nonatomic, readonly) BDSKLinkedFile *linkedFile;
 @property (nonatomic, readonly) NSURL *URL;
 @property (nonatomic) NSUInteger index;
+@property (nonatomic) BOOL replace;
 @property (nonatomic) CGFloat progress;
 
-- (id)initWithLinkedFile:(BDSKLinkedFile *)aLinkedFile 
atIndex:(NSUInteger)anIndex;
+- (id)initWithLinkedFile:(BDSKLinkedFile *)aLinkedFile 
atIndex:(NSUInteger)anIndex replace:(BOOL)aReplace;
 - (id)initWithURL:(NSURL *)aURL;
 
 - (void)start;

Modified: trunk/bibdesk/BDSKItemDownload.m
===================================================================
--- trunk/bibdesk/BDSKItemDownload.m    2019-07-03 06:30:33 UTC (rev 23922)
+++ trunk/bibdesk/BDSKItemDownload.m    2019-07-03 09:23:58 UTC (rev 23923)
@@ -43,7 +43,7 @@
 
 @implementation BDSKItemDownload
 
-@synthesize delegate, linkedFile, URL, index;
+@synthesize delegate, linkedFile, URL, index, replace;
 @dynamic progress;
 
 - (id)initWithURL:(NSURL *)aURL {
@@ -52,6 +52,7 @@
         linkedFile = nil;
         URL = [aURL retain];
         index = NSNotFound;
+        replace = NO;
         download = nil;
         expectedLength = 0;
         receivedLength = 0;
@@ -59,12 +60,13 @@
     return self;
 }
 
-- (id)initWithLinkedFile:(BDSKLinkedFile *)aLinkedFile 
atIndex:(NSUInteger)anIndex {
+- (id)initWithLinkedFile:(BDSKLinkedFile *)aLinkedFile 
atIndex:(NSUInteger)anIndex replace:(BOOL)aReplace {
     self = [super init];
     if (self) {
         linkedFile = [aLinkedFile retain];
         URL = [[linkedFile URL] retain];
         index = anIndex;
+        replace = aReplace;
         download = nil;
         expectedLength = 0;
         receivedLength = 0;

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2019-07-03 06:30:33 UTC (rev 23922)
+++ trunk/bibdesk/BibDocument.m 2019-07-03 09:23:58 UTC (rev 23923)
@@ -2134,10 +2134,7 @@
                 for (BDSKLinkedFile *linkedURL in [pub remoteURLs]) {
                     if ([pub canDownloadLinkedFile:linkedURL] &&
                         [types containsObject:[[[linkedURL URL] pathExtension] 
lowercaseString] ?: @""]) {
-                        if (replace)
-                            [pub downloadLinkedFile:linkedURL];
-                        else
-                            [pub downloadCopyOfLinkedFile:linkedURL];
+                        [pub downloadLinkedFile:linkedURL replace:replace];
                     }
                 }
             }

Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h     2019-07-03 06:30:33 UTC (rev 23922)
+++ trunk/bibdesk/BibItem.h     2019-07-03 09:23:58 UTC (rev 23923)
@@ -823,8 +823,7 @@
 - (void)setProgressDelegate:(id<BDSKItemProgressDelegate>)delegate;
 
 - (void)downloadUrl;
-- (void)downloadLinkedFile:(BDSKLinkedFile *)linkedFile;
-- (void)downloadCopyOfLinkedFile:(BDSKLinkedFile *)linkedFile;
+- (void)downloadLinkedFile:(BDSKLinkedFile *)linkedFile replace:(BOOL)replace;
 
 - (BOOL)canDownloadUrl;
 - (BOOL)canDownloadLinkedFile:(BDSKLinkedFile *)linkedFile;

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2019-07-03 06:30:33 UTC (rev 23922)
+++ trunk/bibdesk/BibItem.m     2019-07-03 09:23:58 UTC (rev 23923)
@@ -3214,16 +3214,18 @@
         BOOL useLocalUrl = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey];
         BOOL autoFile = [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKFilePapersAutomaticallyKey];
         if (idx != NSNotFound) {
-            NSUInteger realIdx = [files indexOfObject:[download linkedFile]];
-            if (realIdx != NSNotFound)
-                [self removeObjectFromFilesAtIndex:idx];
             BDSKLinkedFile *file = [[BDSKLinkedFile alloc] initWithURL:fileURL 
delegate:self];
-            [self insertObject:file inFilesAtIndex:realIdx == NSNotFound ? idx 
: realIdx];
-            if (useLocalUrl == NO) {
-                if ([owner isDocument])
-                    [(BibDocument *)[self owner] userAddedURL:fileURL 
forPublication:self];
-                if (autoFile)
-                    [self autoFileLinkedFile:file];
+            if (file) {
+                NSUInteger realIdx = [files indexOfObject:[download 
linkedFile]];
+                if ([download replace] && realIdx != NSNotFound)
+                    [self removeObjectFromFilesAtIndex:idx];
+                [self insertObject:file inFilesAtIndex:realIdx == NSNotFound ? 
idx : realIdx];
+                if (useLocalUrl == NO) {
+                    if ([owner isDocument])
+                        [(BibDocument *)[self owner] userAddedURL:fileURL 
forPublication:self];
+                    if (autoFile)
+                        [self autoFileLinkedFile:file];
+                }
             }
         } else {
             NSString *oldValue = [self valueOfField:BDSKLocalUrlString 
inherit:NO] ?: @"";
@@ -3251,10 +3253,10 @@
     }
 }
 
-- (void)downloadLinkedFile:(BDSKLinkedFile *)linkedFile {
+- (void)downloadLinkedFile:(BDSKLinkedFile *)linkedFile replace:(BOOL)replace {
     NSUInteger idx = [files indexOfObject:linkedFile];
     if ([linkedFile isFile] == NO && idx != NSNotFound) {
-        BDSKItemDownload *download = [[BDSKItemDownload alloc] 
initWithLinkedFile:linkedFile atIndex:idx];
+        BDSKItemDownload *download = [[BDSKItemDownload alloc] 
initWithLinkedFile:linkedFile atIndex:idx replace:replace];
         if (downloads == nil)
             downloads = [[NSMutableArray alloc] init];
         [downloads addObject:download];
@@ -3263,20 +3265,6 @@
     }
 }
 
-- (void)downloadCopyOfLinkedFile:(BDSKLinkedFile *)linkedFile {
-    NSUInteger idx = [files indexOfObject:linkedFile];
-    if ([linkedFile isFile] == NO && idx != NSNotFound) {
-        linkedFile = [BDSKLinkedFile linkedFileWithURL:[linkedFile URL] 
delegate:nil];
-        [self insertObject:linkedFile inFilesAtIndex:++idx];
-        BDSKItemDownload *download = [[BDSKItemDownload alloc] 
initWithLinkedFile:linkedFile atIndex:idx];
-        if (downloads == nil)
-            downloads = [[NSMutableArray alloc] init];
-        [downloads addObject:download];
-        [download start];
-        [download release];
-    }
-}
-
 - (BOOL)canDownloadLinkedFile:(BDSKLinkedFile *)linkedFile {
     if ([linkedFile isFile] || [[self owner] isDocument] == NO)
         return NO;

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to