Revision: 18485
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=18485&view=rev
Author: hofman
Date: 2012-02-04 17:59:52 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
Use error object controller as recovery attempter for bibtex parser errors. Use
recoverable error for failed bibtex document load.
Modified Paths:
--------------
trunk/bibdesk/BDSKErrorObjectController.m
trunk/bibdesk/BDSKStringParser.m
trunk/bibdesk/BibDocument.m
Modified: trunk/bibdesk/BDSKErrorObjectController.m
===================================================================
--- trunk/bibdesk/BDSKErrorObjectController.m 2012-02-04 15:43:54 UTC (rev
18484)
+++ trunk/bibdesk/BDSKErrorObjectController.m 2012-02-04 17:59:52 UTC (rev
18485)
@@ -389,6 +389,25 @@
}
+#pragma mark NSErrorRecoveryAttempting protocol
+
+// Error recovery for bibtex parser errors, see BibDocument and
BDSKStringParser for the errors
+// The options are (cancel, keep going, edit)
+- (BOOL)attemptRecoveryFromError:(NSError *)error
optionIndex:(NSUInteger)recoveryOptionIndex {
+ // this is set when the document failed to load
+ BibDocument *doc = [[error userInfo] objectForKey:@"failedDocument"];
+ BOOL shouldKeepGoing = recoveryOptionIndex == 1;
+ BOOL shouldEdit = recoveryOptionIndex == 2;
+ if (doc && shouldKeepGoing == NO)
+ // the document failed to load, the user chose not to keep going,
register failure
+ [self documentFailedLoad:doc shouldEdit:shouldEdit];
+ else if (doc == nil && shouldEdit)
+ // paste/drag failed, the user chose to edit
+ [self showEditorForLastPasteDragError];
+ // return YES to accept for Keep Going, otherwise return NO
+ return shouldKeepGoing;
+}
+
#pragma mark TableView delegate
- (NSString *)tableView:(NSTableView *)tv toolTipForCell:(NSCell *)aCell
rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation{
Modified: trunk/bibdesk/BDSKStringParser.m
===================================================================
--- trunk/bibdesk/BDSKStringParser.m 2012-02-04 15:43:54 UTC (rev 18484)
+++ trunk/bibdesk/BDSKStringParser.m 2012-02-04 17:59:52 UTC (rev 18485)
@@ -117,7 +117,7 @@
if([parseError isLocalErrorWithCode: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:[BDSKErrorObjectController
sharedErrorObjectController] forKey:NSRecoveryAttempterErrorKey];
[error setValue:[NSArray arrayWithObjects:NSLocalizedString(@"Cancel",
@"Button title"), NSLocalizedString(@"Keep going", @"Button title"),
NSLocalizedString(@"Edit data", @"Button title"), nil]
forKey:NSLocalizedRecoveryOptionsErrorKey];
[error setValue:parseError forKey:NSUnderlyingErrorKey];
parseError = error;
@@ -134,12 +134,6 @@
return newPubs;
}
-+ (BOOL)attemptRecoveryFromError:(NSError *)error
optionIndex:(NSUInteger)recoveryOptionIndex {
- if (recoveryOptionIndex == 2)
- [[BDSKErrorObjectController sharedErrorObjectController]
showEditorForLastPasteDragError];
- return recoveryOptionIndex == 1;
-}
-
@end
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2012-02-04 15:43:54 UTC (rev 18484)
+++ trunk/bibdesk/BibDocument.m 2012-02-04 17:59:52 UTC (rev 18485)
@@ -1878,33 +1878,20 @@
// @@ move this to NSDocumentController; need to figure out where to add
it, though
if (isPartialData) {
- if (outError) *outError = error;
+ NSError *recoveryError = [NSError mutableLocalErrorWithCode:[error
code] localizedDescription:[error localizedDescription] ?:
NSLocalizedString(@"Error reading file!", @"Message in alert dialog when unable
to read file")];
+ [recoveryError setValue:NSLocalizedString(@"There was a problem
reading the file. Do you want to give up, edit the file to correct the errors,
or keep going with everything that could be analyzed?\n\nIf you choose \"Keep
Going\" and then save the file, you will probably lose data.", @"Informative
text in alert dialog") forKey:NSLocalizedRecoverySuggestionErrorKey];
+ [recoveryError setValue:[BDSKErrorObjectController
sharedErrorObjectController] forKey:NSRecoveryAttempterErrorKey];
+ [recoveryError setValue:[NSArray
arrayWithObjects:NSLocalizedString(@"Give Up", @"Button title"),
NSLocalizedString(@"Keep Going", @"Button title"), NSLocalizedString(@"Edit
File", @"Button title"), nil] forKey:NSLocalizedRecoveryOptionsErrorKey];
+ [recoveryError setValue:self forKey:@"failedDocument"];
+ [recoveryError setValue:error forKey:NSUnderlyingErrorKey];
- // run a modal dialog asking if we want to use partial data or give up
- NSAlert *alert = [NSAlert alertWithMessageText:[error
localizedDescription] ?: NSLocalizedString(@"Error reading file!", @"Message in
alert dialog when unable to read file")
-
defaultButton:NSLocalizedString(@"Give Up", @"Button title")
-
alternateButton:NSLocalizedString(@"Edit File", @"Button title")
-
otherButton:NSLocalizedString(@"Keep Going", @"Button title")
-
informativeTextWithFormat:NSLocalizedString(@"There was a problem reading the
file. Do you want to give up, edit the file to correct the errors, or keep
going with everything that could be analyzed?\n\nIf you choose \"Keep Going\"
and then save the file, you will probably lose data.", @"Informative text in
alert dialog")];
- [alert setAlertStyle:NSCriticalAlertStyle];
- NSInteger rv = [alert runModal];
- if (rv == NSAlertDefaultReturn) {
- // the user said to give up
- [[BDSKErrorObjectController sharedErrorObjectController]
documentFailedLoad:self shouldEdit:NO]; // this hands the errors to a new error
editor and sets that as the documentForErrors
- // return NSUserCancelledError so NSDocumentController won't show
another alert
- if (outError)
- *outError = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSUserCancelledError userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:error, NSUnderlyingErrorKey, nil]];
- }else if (rv == NSAlertAlternateReturn){
- // the user said to edit the file.
- [[BDSKErrorObjectController sharedErrorObjectController]
documentFailedLoad:self shouldEdit:YES]; // this hands the errors to a new
error editor and sets that as the documentForErrors
- // return NSUserCancelledError so NSDocumentController won't show
another alert
- if (outError)
- *outError = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSUserCancelledError userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:error, NSUnderlyingErrorKey, nil]];
- }else if(rv == NSAlertOtherReturn){
+ if ([self presentError:recoveryError])
// the user said to keep going, so if they save, they might
clobber data...
// if we don't return YES, NSDocumentController puts up its lame
alert saying the document could not be opened, and we get no partial data
isPartialData = NO;
- }
+ else if (outError)
+ // return NSUserCancelledError so NSDocumentController won't show
another alert
+ *outError = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSUserCancelledError userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:error, NSUnderlyingErrorKey, nil]];
}
if (isPartialData == NO) {
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