Revision: 23910
http://sourceforge.net/p/bibdesk/svn/23910
Author: hofman
Date: 2019-07-01 16:25:19 +0000 (Mon, 01 Jul 2019)
Log Message:
-----------
Add support to download URLs to BibItem, editor as temporary delegate to update
corresponding progress. This will replace the downloads implemented by the file
view, but can also download the Url field
Modified Paths:
--------------
trunk/bibdesk/BDSKEditor.h
trunk/bibdesk/BDSKEditor.m
trunk/bibdesk/BDSKStatusBar.m
trunk/bibdesk/BibItem.h
trunk/bibdesk/BibItem.m
trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/bibdesk/BDSKItemDownload.h
trunk/bibdesk/BDSKItemDownload.m
Modified: trunk/bibdesk/BDSKEditor.h
===================================================================
--- trunk/bibdesk/BDSKEditor.h 2019-07-01 09:15:34 UTC (rev 23909)
+++ trunk/bibdesk/BDSKEditor.h 2019-07-01 16:25:19 UTC (rev 23910)
@@ -46,10 +46,11 @@
#import <FileView/FileView.h>
#import <Quartz/Quartz.h>
#import "NSTouchBar_BDSKForwardDeclarations.h"
+#import "BibItem.h"
@class BDSKRatingButton, BDSKRatingButtonCell, BDSKStatusBar,
BDSKZoomablePDFView, BDSKEditorTableView, BDSKEditorTextView;
@class BDSKComplexStringEditor, BDSKCiteKeyFormatter;
-@class BibItem, BibAuthor;
+@class BibAuthor;
/*!
@class BDSKEditor
@@ -56,7 +57,7 @@
@abstract WindowController for the edit window
@discussion Subclass of the NSWindowController class, This handles making,
reversing and keeping track of changes to the BibItem, and displaying a nice
GUI.
*/
-@interface BDSKEditor : NSWindowController <NSWindowDelegate,
NSTableViewDelegate, NSTableViewDataSource, NSSplitViewDelegate,
NSControlTextEditingDelegate, BDSKStatusBarDelegate,
BDSKComplexStringFormatterDelegate, BDSKCitationFormatterDelegate,
FVFileViewDelegate, FVFileViewDataSource, QLPreviewPanelDelegate,
QLPreviewPanelDataSource, NSTouchBarDelegate> {
+@interface BDSKEditor : NSWindowController <NSWindowDelegate,
NSTableViewDelegate, NSTableViewDataSource, NSSplitViewDelegate,
NSControlTextEditingDelegate, BDSKStatusBarDelegate,
BDSKComplexStringFormatterDelegate, BDSKCitationFormatterDelegate,
FVFileViewDelegate, FVFileViewDataSource, BDSKItemProgressDelegate,
QLPreviewPanelDelegate, QLPreviewPanelDataSource, NSTouchBarDelegate> {
IBOutlet NSSplitView *mainSplitView;
IBOutlet NSSplitView *fileSplitView;
IBOutlet NSPopUpButton *bibTypeButton;
Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m 2019-07-01 09:15:34 UTC (rev 23909)
+++ trunk/bibdesk/BDSKEditor.m 2019-07-01 16:25:19 UTC (rev 23910)
@@ -284,6 +284,8 @@
[fileView addObserver:self forKeyPath:@"displayMode" options:0
context:&BDSKEditorObservationContext];
[fileView setEditable:editorFlags.isEditable];
[fileView setAllowsDownloading:editorFlags.isEditable];
+
+ [publication setProgressDelegate:self];
}
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName{
@@ -1783,6 +1785,47 @@
}
}
+#pragma mark BDSKItemProgressDelegate
+
+- (void)item:(BibItem *)item updateProgress:(CGFloat)progress forURL:(NSURL
*)url atIndex:(NSUInteger)index {
+ if (index != NSNotFound) {
+ // update progress indicator in file view
+ } else {
+ if (progress < 0.0) {
+ [[statusBar progressIndicator] setIndeterminate:YES];
+ } else {
+ [[statusBar progressIndicator] setIndeterminate:NO];
+ [[statusBar progressIndicator] setDoubleValue:progress];
+ }
+ }
+}
+
+- (void)item:(BibItem *)item addProgressForURL:(NSURL *)url
atIndex:(NSUInteger)index {
+ if (index != NSNotFound) {
+ // add progress in indicator file view
+ } else {
+ [statusBar
setProgressIndicatorStyle:BDSKProgressIndicatorSpinningStyle];
+ [statusBar startAnimation:nil];
+ }
+}
+
+- (void)item:(BibItem *)item removeProgressForURL:(NSURL *)url
atIndex:(NSUInteger)index {
+ if (index != NSNotFound) {
+ // remove progress indicator from file view
+ } else {
+ [statusBar stopAnimation:nil];
+ [statusBar setProgressIndicatorStyle:BDSKProgressIndicatorNone];
+ }
+}
+
+- (void)item:(BibItem *)item moveProgressForURL:(NSURL *)url
toIndex:(NSUInteger)index {
+ if (index != NSNotFound) {
+ // move progress indicator in file view
+ }
+}
+
+#pragma mark KVO
+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (context == &BDSKEditorObservationContext) {
[[NSUserDefaults standardUserDefaults] setInteger:[fileView
displayMode] forKey:BDSKEditorFileViewDisplayModeKey];
@@ -2948,6 +2991,8 @@
if (editorFlags.isEditing && [self commitEditing] == NO)
[self discardEditing];
+ [publication setProgressDelegate:nil];
+
// close so it's not hanging around by itself; this works if the doc
window closes, also
[complexStringEditor close];
Added: trunk/bibdesk/BDSKItemDownload.h
===================================================================
--- trunk/bibdesk/BDSKItemDownload.h (rev 0)
+++ trunk/bibdesk/BDSKItemDownload.h 2019-07-01 16:25:19 UTC (rev 23910)
@@ -0,0 +1,76 @@
+//
+// BDSKItemDownload.h
+// BibDesk
+//
+// Created by Christiaan Hofman on 01/07/2019.
+/*
+ This software is Copyright (c) 2019
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import "BDSKDownloader.h"
+
+@protocol BDSKItemDownloadDelegate;
+
+@class BDSKLinkedFile;
+
+@interface BDSKItemDownload : NSObject <BDSKDownloaderDelegate> {
+ id <BDSKItemDownloadDelegate> delegate;
+ BDSKDownload *download;
+ BDSKLinkedFile *linkedFile;
+ NSURL *URL;
+ NSUInteger index;
+ int64_t expectedLength, receivedLength;
+ NSURL *fileURL;
+}
+
+@property (nonatomic, assign) id <BDSKItemDownloadDelegate> delegate;
+@property (nonatomic, readonly) BDSKLinkedFile *linkedFile;
+@property (nonatomic, readonly) NSURL *URL;
+@property (nonatomic) NSUInteger index;
+@property (nonatomic) CGFloat progress;
+
+- (id)initWithLinkedFile:(BDSKLinkedFile *)aLinkedFile
atIndex:(NSUInteger)anIndex;
+- (id)initWithURL:(NSURL *)aURL;
+
+- (void)start;
+- (void)cancel;
+
+@end
+
+@protocol BDSKItemDownloadDelegate <NSObject>
+
+- (void)itemDownload:(BDSKItemDownload *)download
updateWithProgress:(CGFloat)progress;
+- (void)itemDownload:(BDSKItemDownload *)download didFinishWithURL:(NSURL
*)fileURL;
+
+@end
+
Added: trunk/bibdesk/BDSKItemDownload.m
===================================================================
--- trunk/bibdesk/BDSKItemDownload.m (rev 0)
+++ trunk/bibdesk/BDSKItemDownload.m 2019-07-01 16:25:19 UTC (rev 23910)
@@ -0,0 +1,153 @@
+//
+// BDSKItemDownload.m
+// BibDesk
+//
+// Created by Christiaan Hofman on 01/07/2019.
+/*
+ This software is Copyright (c) 2019
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "BDSKItemDownload.h"
+#import "BDSKLinkedFile.h"
+#import "BDSKStringConstants.h"
+#import "NSFileManager_BDSKExtensions.h"
+
+@implementation BDSKItemDownload
+
+@synthesize delegate, linkedFile, URL, index;
+@dynamic progress;
+
+- (id)initWithURL:(NSURL *)aURL {
+ self = [super init];
+ if (self) {
+ linkedFile = nil;
+ URL = [aURL retain];
+ index = NSNotFound;
+ download = nil;
+ expectedLength = 0;
+ receivedLength = 0;
+ }
+ return self;
+}
+
+- (id)initWithLinkedFile:(BDSKLinkedFile *)aLinkedFile
atIndex:(NSUInteger)anIndex {
+ self = [super init];
+ if (self) {
+ linkedFile = [aLinkedFile retain];
+ URL = [[linkedFile URL] retain];
+ index = anIndex;
+ download = nil;
+ expectedLength = 0;
+ receivedLength = 0;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [download cancel];
+ delegate = nil;
+ BDSKDESTROY(download);
+ BDSKDESTROY(linkedFile);
+ BDSKDESTROY(URL);
+ BDSKDESTROY(fileURL);
+ [super dealloc];
+}
+
+- (void)start {
+ NSURLRequest *request = [NSURLRequest requestWithURL:[self URL]];
+ download = [[[BDSKDownloader sharedDownloader]
startFileDownloadWithRequest:request delegate:self] retain];
+}
+
+- (void)cancel {
+ [download cancel];
+ BDSKDESTROY(download);
+}
+
+- (CGFloat)progress {
+ return expectedLength > 0 ? (CGFloat)receivedLength /
(CGFloat)expectedLength : (CGFloat)NSURLResponseUnknownLength;
+}
+
+#pragma mark BDSKDownloaderDelegate
+
+- (void)downloader:(BDSKDownloader *)downloader download:(BDSKDownload
*)aDownload decideDestinationWithSuggestedFilename:(NSString *)destinationName
completionHandler:(void (^)(NSURL *destinationURL, BOOL
allowOverwrite))completionHandler {
+ NSURL *destURL = nil;
+ NSString *extension = [destinationName pathExtension];
+ NSString *downloadsDirectory = [[[NSUserDefaults standardUserDefaults]
stringForKey:BDSKDownloadsDirectoryKey] stringByExpandingTildeInPath];
+ BOOL isDir;
+
+ if (downloadsDirectory == nil)
+ 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];
+ } else {
+ NSSavePanel *savePanel = [NSSavePanel savePanel];
+ if (NO == [extension isEqualToString:@""])
+ [savePanel setAllowedFileTypes:[NSArray
arrayWithObjects:extension, nil]];
+ [savePanel setAllowsOtherFileTypes:YES];
+ [savePanel setCanSelectHiddenExtension:YES];
+ [savePanel setNameFieldStringValue:destinationName];
+ if (NSFileHandlingPanelOKButton == [savePanel runModal])
+ destURL = [savePanel URL];
+ }
+ if (destURL == nil)
+ destURL = [NSURL fileURLWithPath:[NSTemporaryDirectory()
stringByAppendingPathComponent:destinationName]];
+ completionHandler(destURL, NO);
+}
+
+- (void)downloader:(BDSKDownloader *)downloader download:(BDSKDownload
*)aDownload didCreateDestination:(NSURL *)destinationURL {
+ fileURL = [destinationURL retain];
+}
+
+- (void)downloader:(BDSKDownloader *)downloader download:(BDSKDownload
*)aDownload didReceiveExpectedContentLength:(int64_t)expectedContentLength {
+ expectedLength = expectedContentLength;
+ if (expectedLength < 0)
+ [[self delegate] itemDownload:self updateWithProgress:[self progress]];
+}
+
+- (void)downloader:(BDSKDownloader *)downloader download:(BDSKDownload
*)aDownload didReceiveDataOfLength:(uint64_t)length {
+ receivedLength += length;
+ if (expectedLength > 0)
+ [[self delegate] itemDownload:self updateWithProgress:[self progress]];
+}
+
+- (void)downloader:(BDSKDownloader *)downloader download:(BDSKDownload
*)aDownload didFinishWithData:(NSData *)data {
+ BDSKDESTROY(download);
+ [[self delegate] itemDownload:self didFinishWithURL:fileURL];
+}
+
+- (void)downloader:(BDSKDownloader *)downloader download:(BDSKDownload
*)aDownload didFailWithError:(NSError *)error {
+ BDSKDESTROY(download);
+ [[self delegate] itemDownload:self didFinishWithURL:nil];
+}
+
+@end
Modified: trunk/bibdesk/BDSKStatusBar.m
===================================================================
--- trunk/bibdesk/BDSKStatusBar.m 2019-07-01 09:15:34 UTC (rev 23909)
+++ trunk/bibdesk/BDSKStatusBar.m 2019-07-01 16:25:19 UTC (rev 23910)
@@ -351,7 +351,8 @@
[progressIndicator setAutoresizingMask:NSViewMinXMargin |
NSViewMinYMargin | NSViewMaxYMargin];
[progressIndicator setStyle:style];
[progressIndicator setControlSize:NSSmallControlSize];
- [progressIndicator setIndeterminate:YES];
+ [progressIndicator setMaxValue:1.0];
+ [progressIndicator setIndeterminate:YES];
[progressIndicator setDisplayedWhenStopped:NO];
[progressIndicator sizeToFit];
Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h 2019-07-01 09:15:34 UTC (rev 23909)
+++ trunk/bibdesk/BibItem.h 2019-07-01 16:25:19 UTC (rev 23910)
@@ -41,6 +41,7 @@
#import <Cocoa/Cocoa.h>
#import "BDSKFormatParser.h"
#import "BDSKLinkedFile.h"
+#import "BDSKItemDownload.h"
extern NSString *BDSKBibItemKeyKey;
extern NSString *BDSKBibItemOldValueKey;
@@ -80,6 +81,7 @@
@class BibDocument, BDSKCategoryGroup, BibAuthor, BDSKFieldCollection,
BDSKTemplate, BDSKPublicationsArray, BDSKMacroResolver;
@protocol BDSKParseableItem, BDSKOwner;
+@protocol BDSKItemProgressDelegate;
/*!
@class BibItem
@@ -87,7 +89,7 @@
@discussion This is the data model class that encapsulates each Bibtex entry.
BibItems are created for each entry in a file, and a BibDocument keeps
collections of BibItems. They are also created in response to drag-in or paste
operations containing BibTeX source. Their textvalue method is used to provide
the text that is written to a file on saves.
*/
-@interface BibItem : NSObject <NSCopying, NSCoding, BDSKParseableItem,
BDSKLinkedFileDelegate> {
+@interface BibItem : NSObject <NSCopying, NSCoding, BDSKParseableItem,
BDSKLinkedFileDelegate, BDSKItemDownloadDelegate> {
NSString *citeKey;
NSString *pubType;
NSMutableDictionary *pubFields;
@@ -111,6 +113,8 @@
NSURL *identifierURL;
NSMutableArray *files;
NSUInteger colorLabel;
+ NSMutableArray *downloads;
+ id<BDSKItemProgressDelegate> progressDelegate;
}
+ (NSString *)defaultCiteKey;
@@ -815,6 +819,12 @@
- (NSString *)fieldValueForFileURL:(NSURL *)aURL withFormat:(NSInteger)format;
+- (id<BDSKItemProgressDelegate>)progressDelegate;
+- (void)setProgressDelegate:(id<BDSKItemProgressDelegate>)delegate;
+
+- (void)downloadUrl;
+- (void)downloadLinkedFile:(BDSKLinkedFile *)linkedFile;
+
- (void)customFieldsDidChange:(NSNotification *)aNotification;
- (void)duplicateTitleToBooktitleOverwriting:(BOOL)overwrite;
@@ -849,3 +859,12 @@
extern const CFSetCallBacks kBDSKBibItemEqualitySetCallBacks;
extern const CFSetCallBacks kBDSKBibItemEquivalenceSetCallBacks;
+
+@protocol BDSKItemProgressDelegate <NSObject>
+
+- (void)item:(BibItem *)item updateProgress:(CGFloat)progress forURL:(NSURL
*)url atIndex:(NSUInteger)index;
+- (void)item:(BibItem *)item addProgressForURL:(NSURL *)url
atIndex:(NSUInteger)index;
+- (void)item:(BibItem *)item removeProgressForURL:(NSURL *)url
atIndex:(NSUInteger)index;
+- (void)item:(BibItem *)item moveProgressForURL:(NSURL *)url
toIndex:(NSUInteger)index;
+
+@end
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2019-07-01 09:15:34 UTC (rev 23909)
+++ trunk/bibdesk/BibItem.m 2019-07-01 16:25:19 UTC (rev 23910)
@@ -81,6 +81,7 @@
#import <AGRegex/AGRegex.h>
#import "BDSKEntrezGroupServer.h"
#import "BDSKDOIParser.h"
+#import "BDSKItemDownload.h"
NSString *BDSKBibItemKeyKey = @"key";
NSString *BDSKBibItemOldValueKey = @"oldValue";
@@ -108,6 +109,9 @@
- (void)createFilesArray;
+- (BDSKItemDownload *)downloadForLinkedFile:(BDSKLinkedFile *)linkedFile;
+- (void)updateDownloadIndexes;
+
@end
@@ -284,6 +288,8 @@
filesToBeFiled = nil;
localUrlNeedsToBeFiled = NO;
+ downloads = nil;
+
groups = [[NSMutableDictionary alloc] initWithCapacity:5];
URLs = [[NSMutableDictionary alloc] initWithCapacity:5];
@@ -389,11 +395,11 @@
- (void)dealloc{
[[people allValues] setValue:nil forKey:@"publication"];
+ [downloads makeObjectsPerformSelector:@selector(cancel)];
BDSKDESTROY(pubFields);
BDSKDESTROY(people);
BDSKDESTROY(URLs);
BDSKDESTROY(groups);
-
BDSKDESTROY(pubType);
BDSKDESTROY(citeKey);
BDSKDESTROY(pubDate);
@@ -404,6 +410,7 @@
BDSKDESTROY(macroResolver);
BDSKDESTROY(files);
BDSKDESTROY(filesToBeFiled);
+ BDSKDESTROY(downloads);
[super dealloc];
}
@@ -599,6 +606,10 @@
- (void)setOwner:(id<BDSKOwner>)newOwner {
if (owner != newOwner) {
+ if (owner && newOwner == nil && [downloads count] > 0) {
+ [downloads makeObjectsPerformSelector:@selector(cancel)];
+ [downloads removeAllObjects];
+ }
owner = newOwner;
// we don't reset the macroResolver when the owner is set to nil,
because we use the macroResolver to know the macroResolver used for the fields,
so we can prevent items from being added to another document
if (newOwner)
@@ -2678,6 +2689,7 @@
[aFile updateWithPath:nil];
[self noteFilesChanged:[aFile isFile]];
+ [self updateDownloadIndexes];
}
- (void)removeObjectFromFilesAtIndex:(NSUInteger)idx
@@ -2684,12 +2696,23 @@
{
BDSKLinkedFile *file = [files objectAtIndex:idx];
BOOL isFile = [file isFile];
+
[[[self undoManager] prepareWithInvocationTarget:self] insertObject:file
inFilesAtIndex:idx];
[file setDelegate:nil];
+
[self removeFileToBeFiled:file];
+
+ BDSKItemDownload *download = [self downloadForLinkedFile:file];
+ if (download) {
+ [download cancel];
+ [progressDelegate item:self removeProgressForURL:[download URL]
atIndex:[download index]];
+ [downloads removeObject:download];
+ }
+
[files removeObjectAtIndex:idx];
[self noteFilesChanged:isFile];
+ [self updateDownloadIndexes];
}
- (void)moveFilesAtIndexes:(NSIndexSet *)aSet toIndex:(NSUInteger)idx
@@ -2701,6 +2724,11 @@
[observedFiles removeObjectsAtIndexes:aSet];
[observedFiles insertObjects:toMove atIndexes:[NSIndexSet
indexSetWithIndexesInRange:NSMakeRange(idx, [toMove count])]];
[toMove release];
+
+ // should we dow this?
+ [self noteFilesChanged:YES];
+ [self noteFilesChanged:NO];
+ [self updateDownloadIndexes];
}
- (BOOL)addFileForURL:(NSURL *)aURL autoFile:(BOOL)shouldAutoFile
runScriptHook:(BOOL)runScriptHook {
@@ -3156,6 +3184,76 @@
return NO;
}
+#pragma mark Download
+
+- (id<BDSKItemProgressDelegate>)progressDelegate {
+ return progressDelegate;
+}
+
+- (void)setProgressDelegate:(id<BDSKItemProgressDelegate>)delegate {
+ BOOL wasNil = progressDelegate == nil;
+ progressDelegate = delegate;
+ if (progressDelegate && wasNil && [downloads count]) {
+ for (BDSKItemDownload *download in downloads) {
+ NSUInteger idx = [download index];
+ NSURL *url = [download URL];
+ [progressDelegate item:self addProgressForURL:url atIndex:idx];
+ [progressDelegate item:self updateProgress:[download progress]
forURL:url atIndex:idx];
+ }
+ }
+}
+
+- (void)itemDownload:(BDSKItemDownload *)download
updateWithProgress:(CGFloat)progress {
+ [progressDelegate item:self updateProgress:progress forURL:[download URL]
atIndex:[download index]];
+}
+
+- (void)itemDownload:(BDSKItemDownload *)download didFinishWithURL:(NSURL
*)fileURL {
+ NSUInteger idx = [download index];
+ [progressDelegate item:self removeProgressForURL:[download URL]
atIndex:idx];
+ if (fileURL) {
+ 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 && autoFile)
+ [self autoFileLinkedFile:file];
+ } else {
+ [self setField:BDSKLocalUrlString toURLValue:fileURL];
+ if (useLocalUrl && autoFile)
+ [self autoFileLocalUrl];
+ }
+ }
+ [downloads removeObject:download];
+}
+
+- (void)downloadUrl {
+ NSURL *url = [self remoteURLForField:BDSKUrlString];
+ if (url) {
+ BDSKItemDownload *download = [[BDSKItemDownload alloc]
initWithURL:url];
+ if (downloads == nil)
+ downloads = [[NSMutableArray alloc] init];
+ [downloads addObject:download];
+ [download start];
+ [download release];
+ }
+}
+
+- (void)downloadLinkedFile:(BDSKLinkedFile *)linkedFile {
+ NSUInteger idx = [files indexOfObject:linkedFile];
+ if ([linkedFile isFile] == NO && idx != NSNotFound) {
+ BDSKItemDownload *download = [[BDSKItemDownload alloc]
initWithLinkedFile:linkedFile atIndex:idx];
+ if (downloads == nil)
+ downloads = [[NSMutableArray alloc] init];
+ [downloads addObject:download];
+ [download start];
+ [download release];
+ }
+}
+
#pragma mark -
#pragma mark Groups
@@ -3997,4 +4095,25 @@
[unresolvedURLs release];
}
+- (BDSKItemDownload *)downloadForLinkedFile:(BDSKLinkedFile *)linkedFile {
+ for (BDSKItemDownload *download in downloads) {
+ if ([download linkedFile] == linkedFile)
+ return download;
+ }
+ return nil;
+}
+
+- (void)updateDownloadIndexes {
+ for (BDSKItemDownload *download in downloads) {
+ NSUInteger idx = [download index];
+ if (idx == NSNotFound) continue;
+ BDSKLinkedFile *linkedFile = [download linkedFile];
+ NSUInteger realIdx = [files indexOfObject:linkedFile];
+ if (realIdx != NSNotFound && realIdx != idx) {
+ [download setIndex:realIdx];
+ [progressDelegate item:self moveProgressForURL:[download URL]
toIndex:realIdx];
+ }
+ }
+}
+
@end
Modified: trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj
===================================================================
--- trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj 2019-07-01 09:15:34 UTC
(rev 23909)
+++ trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj 2019-07-01 16:25:19 UTC
(rev 23910)
@@ -99,6 +99,8 @@
CE15E6230FCC28B1009FCBF1 /* BibDocument_UI.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE15E6210FCC28B1009FCBF1 /* BibDocument_UI.m */;
};
CE1782FC1158EFCB00B2EBDF /* BookmarkSheet.xib in Resources */ =
{isa = PBXBuildFile; fileRef = CE1782FB1158EFCB00B2EBDF /* BookmarkSheet.xib
*/; };
CE17832E1158F0A000B2EBDF /* BDSKBookmarkSheetController.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE17832C1158F0A000B2EBDF /*
BDSKBookmarkSheetController.m */; };
+ CE17A30922CA42D9002B64F8 /* BDSKItemDownload.h in Headers */ =
{isa = PBXBuildFile; fileRef = CE17A30722CA42D9002B64F8 /* BDSKItemDownload.h
*/; };
+ CE17A30A22CA42D9002B64F8 /* BDSKItemDownload.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE17A30822CA42D9002B64F8 /* BDSKItemDownload.m
*/; };
CE18D6F021593FB60005CE3C /* Resources.r in Rez */ = {isa =
PBXBuildFile; fileRef = CE18D6E321593FB60005CE3C /* Resources.r */; };
CE1EF2940F8E0D54004E7AE8 /* BDSKParentGroup.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE1EF2920F8E0D54004E7AE8 /* BDSKParentGroup.m
*/; };
CE2153D416B169A4004EB59A /* BDSKAlias.m in Sources */ = {isa =
PBXBuildFile; fileRef = CE2153D216B169A4004EB59A /* BDSKAlias.m */; };
@@ -1263,6 +1265,8 @@
CE17832B1158F0A000B2EBDF /* BDSKBookmarkSheetController.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = BDSKBookmarkSheetController.h; sourceTree = "<group>"; };
CE17832C1158F0A000B2EBDF /* BDSKBookmarkSheetController.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = BDSKBookmarkSheetController.m; sourceTree =
"<group>"; };
CE1783631158F57600B2EBDF /* French */ = {isa =
PBXFileReference; lastKnownFileType = file.xib; name = French; path =
French.lproj/BookmarkSheet.xib; sourceTree = "<group>"; };
+ CE17A30722CA42D9002B64F8 /* BDSKItemDownload.h */ = {isa =
PBXFileReference; lastKnownFileType = sourcecode.c.h; path =
BDSKItemDownload.h; sourceTree = "<group>"; };
+ CE17A30822CA42D9002B64F8 /* BDSKItemDownload.m */ = {isa =
PBXFileReference; lastKnownFileType = sourcecode.c.objc; path =
BDSKItemDownload.m; sourceTree = "<group>"; };
CE17EE7E0E24F27400DE06EA /* BibDesk-App.xcconfig */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path =
"BibDesk-App.xcconfig"; sourceTree = "<group>"; };
CE18D6E321593FB60005CE3C /* Resources.r */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.rez; path =
Resources.r; sourceTree = "<group>"; };
CE1EF2910F8E0D54004E7AE8 /* BDSKParentGroup.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
BDSKParentGroup.h; sourceTree = "<group>"; };
@@ -2788,6 +2792,8 @@
CE69590E223A9BBE001239A6 /*
BDSKDownloaderDeprecated.m */,
CE695912223A9BD9001239A6 /*
BDSKDownloaderSession.m */,
CE044A4312667EB500CE55C4 /*
BDSKDownloadManager.m */,
+ CE17A30722CA42D9002B64F8 /* BDSKItemDownload.h
*/,
+ CE17A30822CA42D9002B64F8 /* BDSKItemDownload.m
*/,
CEB4F47F22428F23008240EE /* BDSKSoapBinding.m
*/,
3B91DD46162225850088206D /*
WOKMWSAuthenticateService.m */,
CEBF7AE618F2EB6300012ECD /*
WokSearchLiteService.m */,
@@ -3658,6 +3664,7 @@
CE2A0AB722459A4500A8F31C /* BibPref_Crossref.h
in Headers */,
CE2A0A1B224599EF00A8F31C /* BDSKInfo.h in
Headers */,
CE2A0AD522459A4B00A8F31C /*
NSMenu_BDSKExtensions.h in Headers */,
+ CE17A30922CA42D9002B64F8 /* BDSKItemDownload.h
in Headers */,
CE2A09F6224599E100A8F31C /* BDSKFieldInfo.h in
Headers */,
CE2A0A6C22459A0A00A8F31C /* BDSKSeparatorCell.h
in Headers */,
CE2A0AD622459A4B00A8F31C /*
NSNumber_BDSKExtensions.h in Headers */,
@@ -4462,6 +4469,7 @@
CE62E0C00F4C4A5500BDF01E /* BDSKOutlineView.m
in Sources */,
CEDBDE4C0F4C863500190AF5 /*
BDSKPreferenceRecord.m in Sources */,
CEDBE05A0F4CDAD900190AF5 /*
NSView_BDSKExtensions.m in Sources */,
+ CE17A30A22CA42D9002B64F8 /* BDSKItemDownload.m
in Sources */,
CEED2CBE0F4DAD2C0078E87A /* BDSKCFCallBacks.m
in Sources */,
CEED2F350F4E0C860078E87A /* BDSKRuntime.m in
Sources */,
CEC1CEA80F51D2CE00D18921 /* BDSKReadWriteLock.m
in Sources */,
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