Revision: 23925
http://sourceforge.net/p/bibdesk/svn/23925
Author: hofman
Date: 2019-07-03 09:57:16 +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. Only redraw icon for changed progress
indicator.
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.h 2019-07-03
09:25:02 UTC (rev 23924)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.h 2019-07-03
09:57:16 UTC (rev 23925)
@@ -44,12 +44,13 @@
@private;
NSURL *_downloadURL;
NSURL *_fileURL;
+ BOOL _replace;
NSUInteger _indexInView;
long long _expectedLength;
long long _receivedLength;
id _delegate;
}
-- (id)initWithDownloadURL:(NSURL *)aURL indexInView:(NSUInteger)indexInView;
+- (id)initWithDownloadURL:(NSURL *)aURL indexInView:(NSUInteger)indexInView
replace:(BOOL)replace;
- (void)setDelegate:(id)obj;
- (id)delegate;
@@ -56,6 +57,7 @@
- (NSURL *)downloadURL;
- (NSUInteger)indexInView;
+- (BOOL)replace;
- (void)setFileURL:(NSURL *)fileURL;
- (NSURL *)fileURL;
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.m 2019-07-03
09:25:02 UTC (rev 23924)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVDownload.m 2019-07-03
09:57:16 UTC (rev 23925)
@@ -46,7 +46,7 @@
@implementation FVDownload
-- (id)initWithDownloadURL:(NSURL *)aURL indexInView:(NSUInteger)indexInView;
+- (id)initWithDownloadURL:(NSURL *)aURL indexInView:(NSUInteger)indexInView
replace:(BOOL)replace;
{
NSParameterAssert(nil != aURL);
NSParameterAssert(NSNotFound != indexInView);
@@ -54,6 +54,7 @@
if (self) {
_downloadURL = [aURL copyWithZone:[self zone]];
_indexInView = indexInView;
+ _replace = replace;
_fileURL = nil;
_expectedLength = 0;
_receivedLength = 0;
@@ -117,6 +118,7 @@
- (NSURL *)downloadURL { return _downloadURL; }
- (NSUInteger)indexInView { return _indexInView; }
+- (BOOL)replace { return _replace; }
- (id)delegate { return _delegate; }
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h 2019-07-03
09:25:02 UTC (rev 23924)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h 2019-07-03
09:57:16 UTC (rev 23925)
@@ -166,9 +166,10 @@
@param aFileView The requesting view
@param aURL The URL to download
@param anIndex The index of the URL to download
+ @param replace Whether the downloaded file should replace the URL
@return YES to allow FileView to download the URL
*/
-- (BOOL)fileView:(FVFileView *)aFileView shouldDownloadURL:(NSURL *)aURL
atIndex:(NSUInteger)anIndex;
+- (BOOL)fileView:(FVFileView *)aFileView shouldDownloadURL:(NSURL *)aURL
atIndex:(NSUInteger)anIndex replace:(BOOL)replace;
/** For download and replace of selection.
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2019-07-03
09:25:02 UTC (rev 23924)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2019-07-03
09:57:16 UTC (rev 23925)
@@ -208,7 +208,7 @@
- (BOOL)_hasArrows;
- (void)_cancelDownloads;
- (void)_invalidateProgressTimer;
-- (void)_downloadURLAtIndex:(NSUInteger)anIndex;
+- (void)_downloadURLAtIndex:(NSUInteger)anIndex replace:(BOOL)replace;
- (void)_handleFinderLabelChanged:(NSNotification *)note;
- (void)_updateBinding:(NSString *)binding;
- (void)_setSelectionIndexes:(NSIndexSet *)indexSet;
@@ -2941,7 +2941,7 @@
NSUInteger anIndex = [[dl objectForKey:@"index"]
unsignedIntegerValue];
NSURL *aURL = [dl objectForKey:@"URL"];
if (anIndex < [self numberOfIcons] && [aURL isEqual:[self
URLAtIndex:anIndex]])
- [self _downloadURLAtIndex:anIndex];
+ [self _downloadURLAtIndex:anIndex replace:YES];
}
}
@@ -4057,8 +4057,14 @@
- (void)_progressTimerFired:(CFRunLoopTimerRef)timer
{
- [[_progressIndicators allValues]
makeObjectsPerformSelector:@selector(animate)];
- [self setNeedsDisplay:YES];
+ NSUInteger r, c;
+ for (FVProgressIndicatorCell *progressIndicator in [_progressIndicators
allValues]) {
+ if ([progressIndicator style] == FVProgressIndicatorIndeterminate) {
+ [progressIndicator animate];
+ if ([self _getGridRow:&r column:&c ofIndex:[progressIndicator
tag]])
+ [self _setNeedsDisplayForIconInRow:r column:c];
+ }
+ }
}
- (void)downloadUpdated:(FVDownload *)download
@@ -4083,6 +4089,7 @@
NSUInteger idx = [download indexInView];
NSURL *currentURL = [self URLAtIndex:idx];
NSURL *downloadURL = [download downloadURL];
+ BOOL replace = [download replace];
NSURL *dest = [download fileURL];
// things could have been rearranged since the download was started, so
don't replace the wrong one
if (nil != dest) {
@@ -4094,10 +4101,16 @@
break;
}
}
- if ([currentURL isEqual:downloadURL] && [[self dataSource]
fileView:self replaceURLsAtIndexes:[NSIndexSet indexSetWithIndex:idx]
withURLs:[NSArray arrayWithObject:dest] forDrop:nil dropOperation:FVDropOn]) {
- NSUInteger r, c;
- if ([self _getGridRow:&r column:&c ofIndex:idx])
- [self _setNeedsDisplayForIconInRow:r column:c];
+ if ([currentURL isEqual:downloadURL]) {
+ 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
replaceURLsAtIndexes:indexes withURLs:urls forDrop:nil dropOperation:FVDropOn])
{
+ NSUInteger r, c;
+ if ([self _getGridRow:&r column:&c ofIndex:idx])
+ [self _setNeedsDisplayForIconInRow:r column:c];
+ }
}
}
[self removeProgressIndicatorForURL:[download downloadURL]
atIndex:[download indexInView]];
@@ -4125,14 +4138,14 @@
[_downloads removeAllObjects];
}
-- (void)_downloadURLAtIndex:(NSUInteger)anIndex;
+- (void)_downloadURLAtIndex:(NSUInteger)anIndex replace:(BOOL)replace;
{
if ([self allowsDownloading]) {
NSURL *theURL = [self URLAtIndex:anIndex];
- if ([[self delegate]
respondsToSelector:@selector(fileView:shouldDownloadURL:atIndex:)] == NO ||
- [[self delegate] fileView:self shouldDownloadURL:theURL
atIndex:anIndex] == YES) {
+ if ([[self delegate]
respondsToSelector:@selector(fileView:shouldDownloadURL:atIndex:replace:)] ==
NO ||
+ [[self delegate] fileView:self shouldDownloadURL:theURL
atIndex:anIndex replace:replace] == YES) {
Class downloadClass = NSClassFromString(@"NSURLSession") ?
[FVDownloadSession class] : [FVDownloadDeprecated class];
- FVDownload *download = [[downloadClass alloc]
initWithDownloadURL:theURL indexInView:anIndex];
+ FVDownload *download = [[downloadClass alloc]
initWithDownloadURL:theURL indexInView:anIndex replace:replace];
[_downloads addObject:download];
[download setDelegate:self];
[download start];
@@ -4148,7 +4161,7 @@
// validation ensures that we have a single selection, and that there
is no current download with this URL
NSUInteger selIndex = [_selectionIndexes firstIndex];
if (NSNotFound != selIndex)
- [self _downloadURLAtIndex:selIndex];
+ [self _downloadURLAtIndex:selIndex replace:YES];
}
}
@@ -4157,13 +4170,8 @@
if ([self allowsDownloading]) {
// validation ensures that we have a single selection, and that there
is no current download with this URL
NSUInteger selIndex = [_selectionIndexes firstIndex];
- if (NSNotFound != selIndex) {
- NSURL *theURL = [self URLAtIndex:selIndex];
- NSUInteger addIndex = selIndex + 1;
- [[self dataSource] fileView:self insertURLs:[NSArray
arrayWithObjects:theURL, nil] atIndexes:[NSIndexSet indexSetWithIndex:addIndex]
forDrop:nil dropOperation:FVDropOn];
- if (addIndex < [self numberOfIcons] && [theURL isEqual:[self
URLAtIndex:addIndex]])
- [self _downloadURLAtIndex:addIndex];
- }
+ if (NSNotFound != selIndex)
+ [self _downloadURLAtIndex:selIndex replace:NO];
}
}
@@ -4172,16 +4180,18 @@
[progressIndicator setTag:anIndex];
[_progressIndicators setObject:progressIndicator forKey:aURL];
[progressIndicator release];
- [self setNeedsDisplay:YES];
+ NSUInteger r, c;
+ if ([self _getGridRow:&r column:&c ofIndex:anIndex])
+ [self _setNeedsDisplayForIconInRow:r column:c];
}
- (void)removeProgressIndicatorForURL:(NSURL *)aURL
atIndex:(NSUInteger)anIndex {
- FVProgressIndicatorCell *progressIndicator = [_progressIndicators
objectForKey:aURL];
- if (progressIndicator)
- [_progressIndicators setObject:progressIndicator forKey:aURL];
- [self setNeedsDisplay:YES];
+ [_progressIndicators removeObjectForKey:aURL];
if ([_progressIndicators count] == 0 || [[[_progressIndicators allValues]
valueForKey:@"style"] containsObject:[NSNumber
numberWithInteger:FVProgressIndicatorIndeterminate]] == NO)
[self _invalidateProgressTimer];
+ NSUInteger r, c;
+ if ([self _getGridRow:&r column:&c ofIndex:anIndex])
+ [self _setNeedsDisplayForIconInRow:r column:c];
}
- (void)updateProgressIndicator:(double)progress forURL:(NSURL *)aURL
atIndex:(NSUInteger)anIndex {
@@ -4196,14 +4206,22 @@
} else {
[progressIndicator setStyle:FVProgressIndicatorDeterminate];
[progressIndicator setCurrentProgress:progress];
- [self setNeedsDisplay:YES];
}
+ NSUInteger r, c;
+ if ([self _getGridRow:&r column:&c ofIndex:anIndex])
+ [self _setNeedsDisplayForIconInRow:r column:c];
}
- (void)moveProgressIndicatorForURL:(NSURL *)aURL toIndex:(NSUInteger)anIndex {
FVProgressIndicatorCell *progressIndicator = [_progressIndicators
objectForKey:aURL];
- [progressIndicator setTag:anIndex];
- [self setNeedsDisplay:YES];
+ NSUInteger r, c, oldIndex = [progressIndicator tag];
+ if (progressIndicator && oldIndex != anIndex) {
+ [progressIndicator setTag:anIndex];
+ if ([self _getGridRow:&r column:&c ofIndex:oldIndex])
+ [self _setNeedsDisplayForIconInRow:r column:c];
+ if ([self _getGridRow:&r column:&c ofIndex:anIndex])
+ [self _setNeedsDisplayForIconInRow:r column:c];
+ }
}
#pragma mark Quick Look support
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