Revision: 18477
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=18477&view=rev
Author: hofman
Date: 2012-02-03 12:57:58 +0000 (Fri, 03 Feb 2012)
Log Message:
-----------
Use error recovery from string parser for bibtex failure, and use presentError:
to directly handle it when verbose handling of paste/drag data
Modified Paths:
--------------
trunk/bibdesk/BDSKStringParser.m
trunk/bibdesk/BibDocument.m
Modified: trunk/bibdesk/BDSKStringParser.m
===================================================================
--- trunk/bibdesk/BDSKStringParser.m 2012-02-03 12:51:47 UTC (rev 18476)
+++ trunk/bibdesk/BDSKStringParser.m 2012-02-03 12:57:58 UTC (rev 18477)
@@ -51,6 +51,7 @@
#import "BDSKSciFinderParser.h"
#import "BDSKPubMedXMLParser.h"
#import "BDSKRuntime.h"
+#import "BDSKErrorObjectController.h"
@implementation BDSKStringParser
@@ -111,6 +112,15 @@
// this will create the NSError if the type is unrecognized
newPubs = [self itemsFromString:string ofType:type error:&parseError];
+ if([parseError isLocalError] && [parseError code] ==
kBDSKBibTeXParserFailed){
+ NSError *error = [NSError
mutableLocalErrorWithCode:kBDSKBibTeXParserFailed
localizedDescription:NSLocalizedString(@"Error Reading String", @"Message in
alert dialog when failing to parse dropped or copied string")];
+ [error setValue:NSLocalizedString(@"There was a problem inserting the
data. Do you want to ignore this data, open a window containing the data to
edit it and remove the errors, or keep going and use everything that BibDesk
could parse?\n(It's likely that choosing \"Keep Going\" will lose some data.)",
@"Informative text in alert dialog")
forKey:NSLocalizedRecoverySuggestionErrorKey];
+ [error setValue:self forKey:NSRecoveryAttempterErrorKey];
+ [error setValue:[NSArray arrayWithObjects:NSLocalizedString(@"Cancel",
@"Button title"), NSLocalizedString(@"Edit data", @"Button title"),
NSLocalizedString(@"Keep going", @"Button title"), nil]
forKey:NSLocalizedRecoveryOptionsErrorKey];
+ [error setValue:parseError forKey:NSUnderlyingErrorKey];
+ parseError = error;
+ }
+
if(type == BDSKNoKeyBibTeXStringType && parseError == nil){
// return an error when we inserted temporary keys, let the caller
decide what to do with it
// don't override a parseError though, as that is probably more
relevant
@@ -122,6 +132,12 @@
return newPubs;
}
++ (BOOL)attemptRecoveryFromError:(NSError *)error
optionIndex:(NSUInteger)recoveryOptionIndex {
+ if (recoveryOptionIndex == 1)
+ [[BDSKErrorObjectController sharedErrorObjectController]
showEditorForLastPasteDragError];
+ return recoveryOptionIndex == 2;
+}
+
@end
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2012-02-03 12:51:47 UTC (rev 18476)
+++ trunk/bibdesk/BibDocument.m 2012-02-03 12:57:58 UTC (rev 18477)
@@ -2105,40 +2105,6 @@
#pragma mark -
#pragma mark New publications from pasteboard
-// pass BDSKUnkownStringType to allow BDSKStringParser to sniff the text and
determine the format
-- (NSArray *)publicationsForString:(NSString *)string
type:(BDSKStringType)type verbose:(BOOL)verbose error:(NSError **)outError {
- NSError *error = nil;
- NSArray *newPubs = [BDSKStringParser itemsFromString:string ofType:type
owner:self error:&error];
-
- if ([error isLocalError]) {
- if ([error code] == kBDSKBibTeXParserFailed) {
- NSInteger rv = NSAlertDefaultReturn;
- if (verbose) {
- // this was BibTeX, but the user may want to try going with
partial data
- // run a modal dialog asking if we want to use partial data or
give up
- NSAlert *alert = [NSAlert
alertWithMessageText:NSLocalizedString(@"Error Reading String", @"Message in
alert dialog when failing to parse dropped or copied string")
-
defaultButton:NSLocalizedString(@"Cancel", @"Button title")
-
alternateButton:NSLocalizedString(@"Edit data", @"Button title")
-
otherButton:NSLocalizedString(@"Keep going", @"Button title")
-
informativeTextWithFormat:NSLocalizedString(@"There was a problem inserting the
data. Do you want to ignore this data, open a window containing the data to
edit it and remove the errors, or keep going and use everything that BibDesk
could parse?\n(It's likely that choosing \"Keep Going\" will lose some data.)",
@"Informative text in alert dialog")];
- rv = [alert runModal];
- }
- if(rv == NSAlertAlternateReturn)
- [[BDSKErrorObjectController sharedErrorObjectController]
showEditorForLastPasteDragError];
- if (rv != NSAlertOtherReturn)
- newPubs = nil;
- } else if ([error code] == kBDSKParserIgnoredFrontMatter) {
- // here we want to display an alert, but don't propagate a
nil/error back up, since it's not a failure
- if (verbose)
- [self presentError:error];
- error = nil;
- }
- }
-
- if(outError) *outError = error;
- return newPubs;
-}
-
- (NSArray *)publicationsForFiles:(NSArray *)filenames {
NSMutableArray *newPubs = [NSMutableArray arrayWithCapacity:[filenames
count]];
NSURL *url = nil;
@@ -2228,8 +2194,19 @@
else
type = [contentString contentStringType];
- if (type != BDSKUnknownStringType)
- contentArray = [self
publicationsForString:contentString type:type verbose:verbose
error:&parseError];
+ if (type != BDSKUnknownStringType) {
+ contentArray = [BDSKStringParser
itemsFromString:contentString ofType:type owner:self error:&parseError];
+
+ if ([parseError isLocalError]) {
+ if ([parseError code] ==
kBDSKParserIgnoredFrontMatter) {
+ if (verbose) [self presentError:parseError];
+ parseError = nil;
+ } else if([parseError code] ==
kBDSKBibTeXParserFailed) {
+ if (verbose == NO || [self
presentError:parseError] == NO)
+ contentArray = nil;
+ }
+ }
+ }
[contentString release];
}
@@ -2330,14 +2307,21 @@
if([type isEqualToString:BDSKBibItemPboardType]){
NSData *pbData = [pb dataForType:BDSKBibItemPboardType];
newPubs = [BibItem publicationsFromArchivedData:pbData
macroResolver:[self macroResolver]];
- } else if([type isEqualToString:BDSKReferenceMinerStringPboardType]){ //
pasteboard type from Reference Miner, determined using Pasteboard Peeker
- 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];
- }else if([type isEqualToString:NSStringPboardType]){
+ }else if([type isEqualToString:NSStringPboardType] || [type
isEqualToString:BDSKReferenceMinerStringPboardType]){
NSString *pbString = [pb stringForType:NSStringPboardType];
- // sniff the string to see what its type is
- newPubs = [self publicationsForString:pbString
type:BDSKUnknownStringType verbose:verbose error:&error];
+ NSInteger stringType = [type
isEqualToString:BDSKReferenceMinerStringPboardType] ?
BDSKReferenceMinerStringType : BDSKUnknownStringType;
+ // sniff the string to see what its type is
+ // sniffing the string for RIS is broken because RefMiner puts junk at
the beginning
+ newPubs = [BDSKStringParser itemsFromString:pbString
ofType:stringType owner:self error:&error];
+ if([error isLocalError]){
+ if ([error code] == kBDSKParserIgnoredFrontMatter){
+ if (verbose) [self presentError:error];
+ error = nil;
+ }else if([error code] == kBDSKBibTeXParserFailed){
+ if(verbose == NO || [self presentError:error] == NO)
+ newPubs = nil;
+ }
+ }
}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
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit