Revision: 30100
          http://sourceforge.net/p/bibdesk/svn/30100
Author:   hofman
Date:     2026-03-04 10:11:52 +0000 (Wed, 04 Mar 2026)
Log Message:
-----------
Try expected index for progress indicators and downloads when adding or 
removing URLs. Wrapper methods for modifying URLs using nthe dataSource. Copy 
progressIndicators dictionary to enumerate as it can be modified.

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicator.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicator.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.h      2026-03-03 
17:55:37 UTC (rev 30099)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.h      2026-03-04 
10:11:52 UTC (rev 30100)
@@ -47,6 +47,7 @@
     NSURL                          *_fileURL;
     BOOL                            _replace;
     NSUInteger                      _indexInView;
+    NSUInteger                      _movedIndexInView;
     long long                       _expectedLength;
     long long                       _receivedLength;
     __weak id<FVDownloadDelegate>   _delegate;
@@ -59,6 +60,7 @@
 
 @property (nonatomic, readonly) NSURL *downloadURL;
 @property (nonatomic) NSUInteger indexInView;
+@property (nonatomic) NSUInteger movedIndexInView;
 @property (nonatomic, readonly) BOOL replace;
 
 @property (nonatomic, strong) NSURL *fileURL;

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.m      2026-03-03 
17:55:37 UTC (rev 30099)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.m      2026-03-04 
10:11:52 UTC (rev 30100)
@@ -54,6 +54,7 @@
 @synthesize delegate=_delegate;
 @synthesize downloadURL=_downloadURL;
 @synthesize indexInView=_indexInView;
+@synthesize movedIndexInView=_movedIndexInView;
 @synthesize replace=_replace;
 @synthesize fileURL=_fileURL;
 @synthesize expectedLength=_expectedLength;
@@ -68,6 +69,7 @@
     if (self) {
         _downloadURL = [aURL copy];
         _indexInView = indexInView;
+        _movedIndexInView = NSNotFound;
         _replace = replace;
         _fileURL = nil;
         _expectedLength = 0;

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2026-03-03 
17:55:37 UTC (rev 30099)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2026-03-04 
10:11:52 UTC (rev 30100)
@@ -1769,34 +1769,46 @@
 
 - (void)_updateProgressIndicatorFrames;
 {
-    [_progressIndicators enumerateKeysAndObjectsUsingBlock:^(NSURL *url, 
FVProgressIndicator *progressIndicator, BOOL *stop){
-        [progressIndicator setFrame:[self 
_rectOfProgressIndicatorForIconAtIndex:[progressIndicator indexInView]]];
-    }];
+    if ([_progressIndicators count]) {
+        [_progressIndicators enumerateKeysAndObjectsUsingBlock:^(NSURL *url, 
FVProgressIndicator *progressIndicator, BOOL *stop){
+            [progressIndicator setFrame:[self 
_rectOfProgressIndicatorForIconAtIndex:[progressIndicator indexInView]]];
+        }];
+    }
 }
 
 - (void)_updateProgressIndicatorIndexes;
 {
-    [_progressIndicators enumerateKeysAndObjectsUsingBlock:^(NSURL *url, 
FVProgressIndicator *progressIndicator, BOOL *stop){
-        NSUInteger anIndex = [progressIndicator indexInView];
-        if ([_orderedURLs containsObject:url] == NO) {
-            [self removeProgressIndicatorForURL:url atIndex:anIndex];
-        } else if (anIndex >= [self numberOfIcons] || [[self 
URLAtIndex:anIndex] isEqual:url] == NO) {
-            anIndex = [_orderedURLs indexOfObject:url];
-            [progressIndicator setIndexInView:anIndex];
-            // frame will be updated from _resetViewLayout
-        }
-    }];
+    if ([_progressIndicators count]) {
+        [[_progressIndicators copy] enumerateKeysAndObjectsUsingBlock:^(NSURL 
*url, FVProgressIndicator *progressIndicator, BOOL *stop){
+            NSUInteger anIndex = [progressIndicator indexInView];
+            if ([_orderedURLs containsObject:url] == NO) {
+                [self removeProgressIndicatorForURL:url atIndex:anIndex];
+            } else {
+                NSUInteger movedIndex = [progressIndicator movedIndexInView];
+                if (movedIndex != NSNotFound && movedIndex < [self 
numberOfIcons] && [[self URLAtIndex:movedIndex] isEqual:url])
+                    [progressIndicator setIndexInView:movedIndex];
+                else if (anIndex >= [self numberOfIcons] || [[self 
URLAtIndex:anIndex] isEqual:url] == NO)
+                    [progressIndicator setIndexInView:[_orderedURLs 
indexOfObject:url]];
+                // frame will be updated from _resetViewLayout
+            }
+        }];
+    }
 }
 
 - (void)_updateDownloadIndexes;
 {
-    for (FVDownload *download in _downloads) {
-        NSUInteger anIndex = [download indexInView];
-        NSURL *url = [download downloadURL];
-        if (anIndex >= [self numberOfIcons] || [[self URLAtIndex:anIndex] 
isEqual:url] == NO) {
-            anIndex = [_orderedURLs indexOfObject:url];
-            if (anIndex != NSNotFound)
-                [download setIndexInView:anIndex];
+    if ([_downloads count]) {
+        for (FVDownload *download in _downloads) {
+            NSUInteger anIndex = [download indexInView];
+            NSUInteger movedIndex = [download movedIndexInView];
+            NSURL *url = [download downloadURL];
+            if (movedIndex != NSNotFound && movedIndex < [self numberOfIcons] 
&& [[self URLAtIndex:movedIndex] isEqual:url]) {
+                [download setIndexInView:movedIndex];
+            } else if (anIndex >= [self numberOfIcons] || [[self 
URLAtIndex:anIndex] isEqual:url] == NO) {
+                anIndex = [_orderedURLs indexOfObject:url];
+                if (anIndex != NSNotFound)
+                    [download setIndexInView:anIndex];
+            }
         }
     }
 }
@@ -2630,6 +2642,114 @@
         [self _drawDropHighlight];
 }
 
+#pragma mark Modifying URLs
+
+- (BOOL)_moveURLsAtIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)anIndex 
forDrop:(id <NSDraggingInfo>)info dropOperation:(FVDropOperation)operation
+{
+    if ([[self dataSource] 
respondsToSelector:@selector(fileView:moveURLsAtIndexes:toIndex:forDrop:dropOperation:)]
 == NO)
+        return NO;
+    
+    [_progressIndicators enumerateKeysAndObjectsUsingBlock:^(NSURL *url, 
FVProgressIndicator *progressIndicator, BOOL *stop){
+        NSUInteger currentIndex = [progressIndicator indexInView];
+        if ([[self URLAtIndex:currentIndex] isEqual:url]) {
+            NSUInteger numBefore = [indexSet 
countOfIndexesInRange:NSMakeRange(0, currentIndex)];
+            NSUInteger movedIndex = currentIndex;
+            if ([indexSet containsIndex:currentIndex])
+                movedIndex = anIndex - [indexSet 
countOfIndexesInRange:NSMakeRange(0, anIndex)] + numBefore;
+            else
+                movedIndex = currentIndex < anIndex ? currentIndex - numBefore 
: currentIndex - numBefore + [indexSet count];
+            if (movedIndex != currentIndex)
+                [progressIndicator setMovedIndexInView:movedIndex];
+        }
+    }];
+    
+    for (FVDownload *download in _downloads) {
+        NSUInteger currentIndex = [download indexInView];
+        if ([[self URLAtIndex:currentIndex] isEqual:[download downloadURL]]) {
+            NSUInteger numBefore = [indexSet 
countOfIndexesInRange:NSMakeRange(0, currentIndex)];
+            NSUInteger movedIndex = currentIndex;
+            if ([indexSet containsIndex:currentIndex])
+                movedIndex = anIndex - [indexSet 
countOfIndexesInRange:NSMakeRange(0, anIndex)] + numBefore;
+            else
+                movedIndex = currentIndex < anIndex ? currentIndex - numBefore 
: currentIndex - numBefore + [indexSet count];
+            if (movedIndex != currentIndex)
+                [download setMovedIndexInView:movedIndex];
+        }
+    }
+    
+    BOOL didMove = [[self dataSource] fileView:self moveURLsAtIndexes:indexSet 
toIndex:anIndex forDrop:info dropOperation:operation];
+    
+    if ([_progressIndicators count])
+        [[_progressIndicators allValues] setValue:[NSNumber 
numberWithUnsignedInteger:NSNotFound] forKey:@"movedIndexInView"];
+    if ([_downloads count])
+        [_downloads setValue:[NSNumber numberWithUnsignedInteger:NSNotFound] 
forKey:@"movedIndexInView"];
+    
+    return didMove;
+}
+
+- (BOOL)_replaceURLAtIndex:(NSUInteger)anIndex withURL:(NSURL *)newURL 
forDrop:(id <NSDraggingInfo>)info dropOperation:(FVDropOperation)operation;
+{
+    if ([[self dataSource] 
respondsToSelector:@selector(fileView:replaceURLAtIndex:withURL:forDrop:dropOperation:)]
 == NO)
+        return NO;
+    
+    return [[self dataSource] fileView:self replaceURLAtIndex:anIndex 
withURL:newURL forDrop:info dropOperation:operation];
+}
+
+- (BOOL)_insertURLs:(NSArray *)absoluteURLs atIndexes:(NSIndexSet *)indexSet 
forDrop:(id <NSDraggingInfo>)info dropOperation:(FVDropOperation)operation
+{
+    if ([[self dataSource] 
respondsToSelector:@selector(fileView:insertURLs:atIndexes:forDrop:dropOperation:)]
 == NO)
+        return NO;
+    
+    [_progressIndicators enumerateKeysAndObjectsUsingBlock:^(NSURL *url, 
FVProgressIndicator *progressIndicator, BOOL *stop){
+        NSUInteger currentIndex = [progressIndicator indexInView];
+        if ([[self URLAtIndex:currentIndex] isEqual:url] && currentIndex >= 
[indexSet firstIndex])
+            [progressIndicator setMovedIndexInView:currentIndex + 
[absoluteURLs count]];
+    }];
+    
+    for (FVDownload *download in _downloads) {
+        NSUInteger currentIndex = [download indexInView];
+        if ([[self URLAtIndex:currentIndex] isEqual:[download downloadURL]] && 
currentIndex >= [indexSet firstIndex])
+            [download setMovedIndexInView:currentIndex + [absoluteURLs count]];
+    }
+    
+    [[self dataSource] fileView:self insertURLs:absoluteURLs 
atIndexes:indexSet forDrop:info dropOperation:operation];
+    
+    if ([_progressIndicators count])
+        [[_progressIndicators allValues] setValue:[NSNumber 
numberWithUnsignedInteger:NSNotFound] forKey:@"movedIndexInView"];
+    if ([_downloads count])
+        [_downloads setValue:[NSNumber numberWithUnsignedInteger:NSNotFound] 
forKey:@"movedIndexInView"];
+    
+    return YES;
+}
+
+- (BOOL)_deleteURLsAtIndexes:(NSIndexSet *)indexSet
+{
+    if ([[self dataSource] 
respondsToSelector:@selector(fileView:deleteURLsAtIndexes:)] == NO)
+        return NO;
+    
+    [_progressIndicators enumerateKeysAndObjectsUsingBlock:^(NSURL *url, 
FVProgressIndicator *progressIndicator, BOOL *stop){
+        NSUInteger currentIndex = [progressIndicator indexInView];
+        if ([[self URLAtIndex:currentIndex] isEqual:url] && currentIndex > 
[indexSet firstIndex])
+            [progressIndicator setMovedIndexInView:currentIndex - [indexSet 
countOfIndexesInRange:NSMakeRange(0, currentIndex)]];
+    }];
+    
+    for (FVDownload *download in _downloads) {
+        NSUInteger currentIndex = [download indexInView];
+        if ([[self URLAtIndex:currentIndex] isEqual:[download downloadURL]] && 
currentIndex > [indexSet firstIndex])
+            [download setMovedIndexInView:currentIndex - [indexSet 
countOfIndexesInRange:NSMakeRange(0, currentIndex)]];
+    }
+    
+    BOOL didDelete = [[self dataSource] fileView:self 
deleteURLsAtIndexes:indexSet];
+              
+    if ([_progressIndicators count])
+        [[_progressIndicators allValues] setValue:[NSNumber 
numberWithUnsignedInteger:NSNotFound] forKey:@"movedIndexInView"];
+    if ([_downloads count])
+        [_downloads setValue:[NSNumber numberWithUnsignedInteger:NSNotFound] 
forKey:@"movedIndexInView"];
+    
+    return didDelete;
+}
+
+
 #pragma mark Drag source
 
 #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= 
MAC_OS_X_VERSION_10_7
@@ -2649,7 +2769,7 @@
     // only called if we originated the drag, so the row/column must be valid
     if ((operation & NSDragOperationDelete) != 0 && operation != 
NSDragOperationEvery && [self isEditable]) {
         _fvFlags.needsReload = YES;
-        if ([[self dataSource] fileView:self 
deleteURLsAtIndexes:_selectionIndexes]) {
+        if ([self _deleteURLsAtIndexes:_selectionIndexes]) {
             [self _setSelectionIndexes:[NSIndexSet indexSet]];
             if (_fvFlags.needsReload)
                 [self reloadIcons];
@@ -2735,7 +2855,7 @@
     // only called if we originated the drag, so the row/column must be valid
     if ((operation & NSDragOperationDelete) != 0 && operation != 
NSDragOperationEvery && [self isEditable]) {
         _fvFlags.needsReload = YES;
-        if ([[self dataSource] fileView:self 
deleteURLsAtIndexes:_selectionIndexes]) {
+        if ([self _deleteURLsAtIndexes:_selectionIndexes]) {
             [self _setSelectionIndexes:[NSIndexSet indexSet]];
             if (_fvFlags.needsReload)
                 [self reloadIcons];
@@ -2986,15 +3106,14 @@
     
     if (isMove) {
         
-        didPerform = [[self dataSource] fileView:self 
moveURLsAtIndexes:_selectionIndexes toIndex:insertIndex forDrop:sender 
dropOperation:dropOp];
+        didPerform = [self _moveURLsAtIndexes:_selectionIndexes 
toIndex:insertIndex forDrop:sender dropOperation:dropOp];
         
     } else if (FVDropBefore == dropOp || FVDropAfter == dropOp || NSNotFound 
== dropIndex) {
-           
+        
         // drop on the whole view
         NSIndexSet *insertSet = [NSIndexSet 
indexSetWithIndexesInRange:NSMakeRange(insertIndex, [allURLs count])];
-        [[self dataSource] fileView:self insertURLs:allURLs 
atIndexes:insertSet forDrop:sender dropOperation:dropOp];
-        didPerform = YES;
-
+        didPerform = [self _insertURLs:allURLs atIndexes:insertSet 
forDrop:sender dropOperation:dropOp];
+        
     }
     else {
         // we're targeting a particular cell, make sure that cell is a legal 
replace operation
@@ -3007,7 +3126,7 @@
             aURL = [NSURL fileURLWithPath:[[pboard 
propertyListForType:NSFilenamesPboardType] lastObject]];
         }
         if (aURL)
-            didPerform = [[self dataSource] fileView:self 
replaceURLAtIndex:dropIndex withURL:aURL forDrop:sender dropOperation:dropOp];
+            didPerform = [self _replaceURLAtIndex:dropIndex withURL:aURL 
forDrop:sender dropOperation:dropOp];
     }
     
     if ([downloads count]) {
@@ -3825,7 +3944,7 @@
 - (IBAction)delete:(id)sender;
 {
     _fvFlags.needsReload = YES;
-    if (NO == [self isEditable] || NO == [[self dataSource] fileView:self 
deleteURLsAtIndexes:_selectionIndexes])
+    if (NO == [self isEditable] || NO == [self 
_deleteURLsAtIndexes:_selectionIndexes])
         NSBeep();
     else if (_fvFlags.needsReload)
         [self reloadIcons];
@@ -3858,9 +3977,7 @@
 {
     if ([self isEditable]) {
         NSArray *URLs = FVURLsFromPasteboard([NSPasteboard generalPasteboard]);
-        if ([URLs count])
-            [[self dataSource] fileView:self insertURLs:URLs 
atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange([self 
numberOfIcons], [URLs count])] forDrop:nil dropOperation:FVDropOn];
-        else
+        if ([URLs count] == 0 || NO == [self _insertURLs:URLs 
atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange([self 
numberOfIcons], [URLs count])] forDrop:nil dropOperation:FVDropOn])
             NSBeep();
     }
     else NSBeep();
@@ -4161,8 +4278,8 @@
             NSArray *urls = [NSArray arrayWithObject:dest];
             NSIndexSet *indexes = [NSIndexSet indexSetWithIndex:idx];
             if (replace == NO) {
-                [[self dataSource] fileView:self insertURLs:urls 
atIndexes:indexes forDrop:nil dropOperation:FVDropBefore];
-            } else if ([[self dataSource] fileView:self replaceURLAtIndex:idx 
withURL:dest forDrop:nil dropOperation:FVDropOn]) {
+                [self _insertURLs:urls atIndexes:indexes forDrop:nil 
dropOperation:FVDropBefore];
+            } else if ([self _replaceURLAtIndex:idx withURL:dest forDrop:nil 
dropOperation:FVDropOn]) {
                 NSUInteger r, c;
                 if ([self _getGridRow:&r column:&c ofIndex:idx])
                     [self _setNeedsDisplayForIconInRow:r column:c];

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicator.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicator.h     
2026-03-03 17:55:37 UTC (rev 30099)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicator.h     
2026-03-04 10:11:52 UTC (rev 30100)
@@ -58,6 +58,7 @@
     NSInteger                _currentStep;
     FVProgressIndicatorStyle _style;
     NSUInteger               _indexInView;
+    NSUInteger               _movedIndexInView;
     CFRunLoopTimerRef        _progressTimer;
 }
 
@@ -67,5 +68,6 @@
 @property (nonatomic) FVProgressIndicatorStyle style;
 
 @property (nonatomic) NSUInteger indexInView;
+@property (nonatomic) NSUInteger movedIndexInView;
 
 @end

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicator.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicator.m     
2026-03-03 17:55:37 UTC (rev 30099)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVProgressIndicator.m     
2026-03-04 10:11:52 UTC (rev 30100)
@@ -51,6 +51,7 @@
 @synthesize currentProgress=_currentProgress;
 @synthesize style=_style;
 @synthesize indexInView=_indexInView;
+@synthesize movedIndexInView=_movedIndexInView;
 
 + (id)defaultAnimationForKey:(NSString *)key {
     if ([key isEqualToString:@"currentProgress"])
@@ -76,6 +77,8 @@
         _currentProgress = 0;
         _currentStep = 0;
         _style = FVProgressIndicatorDeterminate;
+        _indexInView = 0;
+        _movedIndexInView = NSNotFound;
     }
     return 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