Revision: 27574
          http://sourceforge.net/p/bibdesk/svn/27574
Author:   hofman
Date:     2022-06-07 09:33:04 +0000 (Tue, 07 Jun 2022)
Log Message:
-----------
rename variable, reorder code

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

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2022-06-07 06:30:18 UTC (rev 27573)
+++ trunk/bibdesk/BibItem.m     2022-06-07 09:33:04 UTC (rev 27574)
@@ -2734,12 +2734,15 @@
 - (void)insertFiles:(NSArray *)newFiles atIndexes:(NSIndexSet *)aSet
 {
     [[[self undoManager] prepareWithInvocationTarget:self] 
removeFilesAtIndexes:aSet];
+    
+    BOOL hasFile = [[newFiles valueForKeyPath:@"@max.file"] boolValue];
+    
     [files insertObjects:newFiles atIndexes:aSet];
     [newFiles setValue:self forKey:@"delegate"];
-    if ([owner fileURL])
+    if (hasFile && [owner fileURL])
         [newFiles makeObjectsPerformSelector:@selector(updateWithPath:) 
withObject:nil];
     
-    [self noteFilesChanged:[[newFiles valueForKeyPath:@"@max.file"] 
boolValue]];
+    [self noteFilesChanged:hasFile];
     [self updateDownloadIndexes];
 }
 
@@ -2754,7 +2757,6 @@
     BOOL isFile = [[oldFiles valueForKeyPath:@"@max.file"] boolValue];
     
     [[[self undoManager] prepareWithInvocationTarget:self] 
insertFiles:oldFiles atIndexes:aSet];
-    [oldFiles setValue:nil forKey:@"delegate"];
     
     for (BDSKLinkedFile *file in oldFiles) {
         [self removeFileToBeFiled:file];
@@ -2769,6 +2771,7 @@
         }
     }
     
+    [oldFiles setValue:nil forKey:@"delegate"];
     [files removeObjectsAtIndexes:aSet];
     
     [self noteFilesChanged:isFile];
@@ -2777,16 +2780,15 @@
 
 - (void)replaceObjectInFilesAtIndex:(NSUInteger)idx withObject:(BDSKLinkedFile 
*)aFile
 {
-    BDSKLinkedFile *file = [files objectAtIndex:idx];
-    BOOL isFile = [file isFile] || [aFile isFile];
+    BDSKLinkedFile *oldFile = [files objectAtIndex:idx];
+    BOOL isFile = [oldFile isFile] || [aFile isFile];
     
-    [[[self undoManager] prepareWithInvocationTarget:self] 
replaceObjectInFilesAtIndex:idx withObject:file];
-    [file setDelegate:nil];
+    [[[self undoManager] prepareWithInvocationTarget:self] 
replaceObjectInFilesAtIndex:idx withObject:oldFile];
     
-    [self removeFileToBeFiled:file];
+    [self removeFileToBeFiled:oldFile];
     
     for (BDSKItemDownload *download in downloads) {
-        if ([download linkedFile] == file) {
+        if ([download linkedFile] == oldFile) {
             [download cancel];
             NSDictionary *userInfo = [NSDictionary 
dictionaryWithObject:download forKey:BDSKItemDownloadKey];
             [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKItemDownloadFinishedNotification object:self 
userInfo:userInfo];
@@ -2795,8 +2797,11 @@
         }
     }
     
+    [oldFile setDelegate:nil];
     [files replaceObjectAtIndex:idx withObject:aFile];
     [aFile setDelegate:self];
+    if ([aFile isFile] && [owner fileURL])
+        [aFile updateWithPath:nil];
     
     [self noteFilesChanged:isFile];
     [self updateDownloadIndexes];

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