Revision: 17982
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=17982&view=rev
Author: hofman
Date: 2011-06-28 19:56:45 +0000 (Tue, 28 Jun 2011)
Log Message:
-----------
Reorganize implementation of creating pubs for a document
Modified Paths:
--------------
trunk/bibdesk/BDSKTextImportController.m
trunk/bibdesk/BibDocument.h
trunk/bibdesk/BibDocument.m
Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m 2011-06-28 06:34:48 UTC (rev
17981)
+++ trunk/bibdesk/BDSKTextImportController.m 2011-06-28 19:56:45 UTC (rev
17982)
@@ -784,10 +784,14 @@
if (returnCode == NSFileHandlingPanelOKButton) {
NSString *fileName = [sheet filename];
// first try to parse the file
- if([document addPublicationsFromFile:fileName error:NULL]){
+ NSError *error = nil;
+ NSArray *newPubs = [document extractPublicationsFromFiles:[NSArray
arrayWithObject:fileName] unparseableFiles:NULL verbose:NO error:&error];
+ BOOL shouldEdit = [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKEditOnPasteKey];
+ if ([newPubs count]) {
+ [document addPublications:newPubs publicationsToAutoFile:nil
temporaryCiteKey:[[error userInfo] valueForKey:@"temporaryCiteKey"]
selectLibrary:YES edit:shouldEdit];
// succeeded to parse the file, we return immediately
[self didEndSheet:sheet returnCode:returnCode contextInfo:NULL];
- }else{
+ } else {
[sheet orderOut:nil];
// show the main window
Modified: trunk/bibdesk/BibDocument.h
===================================================================
--- trunk/bibdesk/BibDocument.h 2011-06-28 06:34:48 UTC (rev 17981)
+++ trunk/bibdesk/BibDocument.h 2011-06-28 19:56:45 UTC (rev 17982)
@@ -370,12 +370,11 @@
/* Paste related methods */
- (void)addPublications:(NSArray *)newPubs publicationsToAutoFile:(NSArray
*)pubsToAutoFile temporaryCiteKey:(NSString *)tmpCiteKey
selectLibrary:(BOOL)shouldSelect edit:(BOOL)shouldEdit;
- (NSArray *)addPublicationsFromPasteboard:(NSPasteboard *)pb
selectLibrary:(BOOL)select verbose:(BOOL)verbose error:(NSError **)error;
-- (NSArray *)addPublicationsFromFile:(NSString *)fileName error:(NSError
**)outError;
- (NSArray *)publicationsFromArchivedData:(NSData *)data;
- (NSArray *)publicationsForString:(NSString *)string
type:(BDSKStringType)type verbose:(BOOL)verbose error:(NSError **)error;
-- (NSArray *)publicationsForFiles:(NSArray *)filenames error:(NSError **)error;
+- (NSArray *)publicationsForFiles:(NSArray *)filenames;
+- (NSArray *)publicationsForURL:(NSURL *)aURL title:(NSString *)aTitle;
- (NSArray *)extractPublicationsFromFiles:(NSArray *)filenames
unparseableFiles:(NSArray **)unparseableFiles verbose:(BOOL)verbose
error:(NSError **)error;
-- (NSArray *)publicationsForURLFromPasteboard:(NSPasteboard *)pboard
error:(NSError **)error;
// Private methods
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2011-06-28 06:34:48 UTC (rev 17981)
+++ trunk/bibdesk/BibDocument.m 2011-06-28 19:56:45 UTC (rev 17982)
@@ -2141,6 +2141,8 @@
NSString *type = [pb availableTypeFromArray:[NSArray
arrayWithObjects:BDSKBibItemPboardType, BDSKWeblocFilePboardType,
BDSKReferenceMinerStringPboardType, NSStringPboardType, NSFilenamesPboardType,
NSURLPboardType, nil]];
NSArray *newPubs = nil;
NSArray *newFilePubs = nil;
+ NSArray *newFiles = nil;
+ NSURL *newURL = nil;
NSError *error = nil;
NSString *temporaryCiteKey = nil;
BOOL shouldEdit = [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKEditOnPasteKey];
@@ -2152,42 +2154,37 @@
NSString *pbString = [pb
stringForType:BDSKReferenceMinerStringPboardType];
// sniffing the string for RIS is broken because RefMiner puts junk at
the beginning
newPubs = [self publicationsForString:pbString
type:BDSKReferenceMinerStringType verbose:verbose error:&error];
- if(temporaryCiteKey = [[error userInfo]
valueForKey:@"temporaryCiteKey"])
- error = nil; // accept temporary cite keys, but show a warning
later
}else if([type isEqualToString:NSStringPboardType]){
NSString *pbString = [pb stringForType:NSStringPboardType];
// sniff the string to see what its type is
newPubs = [self publicationsForString:pbString
type:BDSKUnknownStringType verbose:verbose error:&error];
- if(temporaryCiteKey = [[error userInfo]
valueForKey:@"temporaryCiteKey"])
- error = nil; // accept temporary cite keys, but show a warning
later
}else if([type isEqualToString:NSFilenamesPboardType]){
NSArray *pbArray = [pb
propertyListForType:NSFilenamesPboardType]; // we will get an array
// try this first, in case these files are a type we can open
- NSArray *unparseableFiles = nil;
- newPubs = [self extractPublicationsFromFiles:pbArray
unparseableFiles:&unparseableFiles verbose:verbose error:&error];
- if(temporaryCiteKey = [[error userInfo]
objectForKey:@"temporaryCiteKey"])
- error = nil; // accept temporary cite keys, but show a warning
later
- if ([unparseableFiles count] > 0) {
- newFilePubs = [self publicationsForFiles:unparseableFiles
error:&error];
- newPubs = [newPubs arrayByAddingObjectsFromArray:newFilePubs];
- }
+ newPubs = [self extractPublicationsFromFiles:pbArray
unparseableFiles:&newFiles verbose:verbose error:&error];
}else if([type isEqualToString:BDSKWeblocFilePboardType]){
- NSURL *pbURL = [NSURL URLWithString:[pb
stringForType:BDSKWeblocFilePboardType]];
- if([pbURL isFileURL])
- newPubs = newFilePubs = [self publicationsForFiles:[NSArray
arrayWithObject:[pbURL path]] error:&error];
- else
- newPubs = [self publicationsForURLFromPasteboard:pb error:&error];
+ newURL = [NSURL URLWithString:[pb
stringForType:BDSKWeblocFilePboardType]];
}else if([type isEqualToString:NSURLPboardType]){
- NSURL *pbURL = [NSURL URLFromPasteboard:pb];
- if([pbURL isFileURL])
- newPubs = newFilePubs = [self publicationsForFiles:[NSArray
arrayWithObject:[pbURL path]] error:&error];
- else
- newPubs = [self publicationsForURLFromPasteboard:pb error:&error];
+ newURL = [NSURL URLFromPasteboard:pb];
}else{
// errors are key, value
error = [NSError localErrorWithCode:kBDSKParserFailed
localizedDescription:NSLocalizedString(@"Did not find anything appropriate on
the pasteboard", @"Error description")];
}
+ if(newURL){
+ if([newURL isFileURL])
+ newFiles = [NSArray arrayWithObject:[newURL path]];
+ else
+ newPubs = [self publicationsForURL:newURL title:[WebView
URLTitleFromPasteboard:pb]];
+ }
+ if([newFiles count]){
+ newFilePubs = [self publicationsForFiles:newFiles];
+ newPubs = newPubs ? [newPubs
arrayByAddingObjectsFromArray:newFilePubs]: newFilePubs;
+ }
+
+ if(temporaryCiteKey = [[error userInfo] objectForKey:@"temporaryCiteKey"])
+ error = nil; // accept temporary cite keys, but show a warning later
+
if ([newPubs count] > 0)
[self addPublications:newPubs
publicationsToAutoFile:newFilePubs temporaryCiteKey:temporaryCiteKey
selectLibrary:shouldSelect edit:shouldEdit];
else if (newPubs == nil && outError)
@@ -2196,24 +2193,6 @@
return newPubs;
}
-- (NSArray *)addPublicationsFromFile:(NSString *)fileName error:(NSError
**)outError{
- NSError *error = nil;
- NSString *temporaryCiteKey = nil;
- NSArray *newPubs = [self extractPublicationsFromFiles:[NSArray
arrayWithObject:fileName] unparseableFiles:NULL verbose:NO error:&error];
- BOOL shouldEdit = [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKEditOnPasteKey];
-
- if ((temporaryCiteKey = [[error userInfo]
valueForKey:@"temporaryCiteKey"]))
- error = nil; // accept temporary cite keys, but show a warning later
-
- if ([newPubs count] == 0) {
- if (outError) *outError = error;
- return nil;
- } else {
- [self addPublications:newPubs publicationsToAutoFile:nil
temporaryCiteKey:temporaryCiteKey selectLibrary:YES edit:shouldEdit];
- return newPubs;
- }
-}
-
- (NSArray *)publicationsFromArchivedData:(NSData *)data{
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
initForReadingWithData:data];
@@ -2382,7 +2361,7 @@
return array;
}
-- (NSArray *)publicationsForFiles:(NSArray *)filenames error:(NSError **)error
{
+- (NSArray *)publicationsForFiles:(NSArray *)filenames {
NSMutableArray *newPubs = [NSMutableArray arrayWithCapacity:[filenames
count]];
NSURL *url = nil;
@@ -2405,13 +2384,13 @@
}
// GJ try parsing pdf to extract info that is then used
to get a PubMed record
- if(newBI == nil && [[[NSWorkspace sharedWorkspace]
typeOfFile:[[fnStr stringByStandardizingPath] stringByResolvingSymlinksInPath]
error:NULL] isEqualToUTI:(NSString *)kUTTypePDF] && [[NSUserDefaults
standardUserDefaults]
boolForKey:BDSKShouldParsePDFToGeneratePubMedSearchTermKey])
- newBI = [BibItem itemByParsingPDFFile:fnStr];
-
- // fall back on the least reliable metadata source (hidden pref)
- if(newBI == nil && [[[NSWorkspace sharedWorkspace]
typeOfFile:[[fnStr stringByStandardizingPath] stringByResolvingSymlinksInPath]
error:NULL] isEqualToUTI:(NSString *)kUTTypePDF] && [[NSUserDefaults
standardUserDefaults] boolForKey:BDSKShouldUsePDFMetadataKey])
- newBI = [BibItem itemWithPDFMetadata:[PDFMetadata
metadataForURL:url error:&xerror]];
-
+ if(newBI == nil && [[[NSWorkspace sharedWorkspace]
typeOfFile:[[fnStr stringByStandardizingPath] stringByResolvingSymlinksInPath]
error:NULL] isEqualToUTI:(NSString *)kUTTypePDF]){
+ if([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKShouldParsePDFToGeneratePubMedSearchTermKey])
+ newBI = [BibItem itemByParsingPDFFile:fnStr];
+ // fall back on the least reliable metadata source (hidden
pref)
+ if(newBI == nil && [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKShouldUsePDFMetadataKey])
+ newBI = [BibItem itemWithPDFMetadata:[PDFMetadata
metadataForURL:url error:&xerror]];
+ }
if(newBI == nil)
newBI = [[[BibItem alloc] init] autorelease];
@@ -2423,22 +2402,16 @@
return newPubs;
}
-- (NSArray *)publicationsForURLFromPasteboard:(NSPasteboard *)pboard
error:(NSError **)error {
+- (NSArray *)publicationsForURL:(NSURL *)aURL title:(NSString *)aTitle {
NSArray *pubs = nil;
- NSURL *theURL = [WebView URLFromPasteboard:pboard];
- if (theURL) {
- BibItem *newBI = [[BibItem alloc] init];
- [newBI addFileForURL:theURL autoFile:NO runScriptHook:YES];
- [newBI setPubType:@"webpage"];
- [newBI setField:@"Lastchecked" toValue:[[NSDate date]
dateDescription]];
- NSString *title = [WebView URLTitleFromPasteboard:pboard];
- if (title)
- [newBI setField:BDSKTitleString toValue:title];
- pubs = [NSArray arrayWithObject:newBI];
- [newBI release];
- } else if (error) {
- *error = [NSError localErrorWithCode:kBDSKParserFailed
localizedDescription:NSLocalizedString(@"Did not find expected URL on the
pasteboard", @"Error description")];
- }
+ BibItem *newBI = [[BibItem alloc] init];
+ [newBI addFileForURL:aURL autoFile:NO runScriptHook:YES];
+ [newBI setPubType:@"webpage"];
+ [newBI setField:@"Lastchecked" toValue:[[NSDate date] dateDescription]];
+ if (aTitle)
+ [newBI setField:BDSKTitleString toValue:aTitle];
+ pubs = [NSArray arrayWithObject:newBI];
+ [newBI release];
return pubs;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit