Revision: 18483
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=18483&view=rev
Author:   hofman
Date:     2012-02-04 12:06:07 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
convenience method to check local error code

Modified Paths:
--------------
    trunk/bibdesk/BDSKEditor.m
    trunk/bibdesk/BDSKScriptGroup.m
    trunk/bibdesk/BDSKStringParser.m
    trunk/bibdesk/BDSKTextImportController.m
    trunk/bibdesk/BDSKURLGroup.m
    trunk/bibdesk/BDSKWebGroup.m
    trunk/bibdesk/BibDocument.m
    trunk/bibdesk/NSError_BDSKExtensions.h
    trunk/bibdesk/NSError_BDSKExtensions.m

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2012-02-03 18:25:37 UTC (rev 18482)
+++ trunk/bibdesk/BDSKEditor.m  2012-02-04 12:06:07 UTC (rev 18483)
@@ -2692,11 +2692,11 @@
         // this returns nil when there was a parser error and the user didn't 
decide to proceed anyway
         draggedPubs = [BDSKStringParser itemsFromString:pbString 
ofType:[pbString contentStringType] owner:[self document] 
isPartialData:&isPartialData error:&error];
         // we ignore warnings for parsing with temporary keys, but we want to 
ignore the cite key in that case
-        if (isPartialData && [error isLocalError]) {
-            if ([error code] == kBDSKHadMissingCiteKeys) {
+        if (isPartialData) {
+            if ([error isLocalErrorWithCode:kBDSKHadMissingCiteKeys]) {
                 hasTemporaryCiteKey = YES;
                 error = nil;
-            } else if ([error code] == kBDSKBibTeXParserFailed) {
+            } else if ([error isLocalErrorWithCode:kBDSKBibTeXParserFailed]) {
                 // should we accept partially parsed bibtex?
                 draggedPubs = nil;
             }

Modified: trunk/bibdesk/BDSKScriptGroup.m
===================================================================
--- trunk/bibdesk/BDSKScriptGroup.m     2012-02-03 18:25:37 UTC (rev 18482)
+++ trunk/bibdesk/BDSKScriptGroup.m     2012-02-04 12:06:07 UTC (rev 18483)
@@ -284,7 +284,7 @@
     
     if (type == BDSKBibTeXStringType) {
         pubs = [BDSKBibTeXParser itemsFromData:[outputString 
dataUsingEncoding:NSUTF8StringEncoding] macros:&macros filePath:@"" owner:self 
encoding:NSUTF8StringEncoding isPartialData:&isPartialData error:&error];
-        if (isPartialData && [error isLocalError] && [error code] == 
kBDSKParserIgnoredFrontMatter)
+        if (isPartialData && [error 
isLocalErrorWithCode:kBDSKParserIgnoredFrontMatter])
             isPartialData = NO;
     } else if (type != BDSKUnknownStringType){
         pubs = [BDSKStringParser itemsFromString:outputString ofType:type 
error:&error];

Modified: trunk/bibdesk/BDSKStringParser.m
===================================================================
--- trunk/bibdesk/BDSKStringParser.m    2012-02-03 18:25:37 UTC (rev 18482)
+++ trunk/bibdesk/BDSKStringParser.m    2012-02-04 12:06:07 UTC (rev 18483)
@@ -114,7 +114,7 @@
             *isPartialData = newPubs != nil;
     }
     
-    if([parseError isLocalError] && [parseError code] == 
kBDSKBibTeXParserFailed){
+    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];

Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m    2012-02-03 18:25:37 UTC (rev 
18482)
+++ trunk/bibdesk/BDSKTextImportController.m    2012-02-04 12:06:07 UTC (rev 
18483)
@@ -1505,7 +1505,7 @@
     NSArray *pubs = [BDSKStringParser itemsFromString:string ofType:type 
owner:owner isPartialData:&isPartialData error:&error];
     
     // ignore warnings for parsing with temporary citekeys, as we're not 
interested in the cite key
-    if ([error isLocalError] && [error code] == kBDSKHadMissingCiteKeys) {
+    if ([error isLocalErrorWithCode:kBDSKHadMissingCiteKeys]) {
         isPartialData = NO;
         error = nil;
     }

Modified: trunk/bibdesk/BDSKURLGroup.m
===================================================================
--- trunk/bibdesk/BDSKURLGroup.m        2012-02-03 18:25:37 UTC (rev 18482)
+++ trunk/bibdesk/BDSKURLGroup.m        2012-02-04 12:06:07 UTC (rev 18483)
@@ -202,7 +202,7 @@
         BOOL isPartialData = NO;
         if (type == BDSKBibTeXStringType) {
             pubs = [BDSKBibTeXParser itemsFromData:[contentString 
dataUsingEncoding:NSUTF8StringEncoding] macros:&macros filePath:filePath 
owner:self encoding:NSUTF8StringEncoding isPartialData:&isPartialData 
error:&error];
-            if (isPartialData && [error isLocalError] && [error code] == 
kBDSKParserIgnoredFrontMatter)
+            if (isPartialData && [error 
isLocalErrorWithCode:kBDSKParserIgnoredFrontMatter])
                 isPartialData = NO;
         } else if (type != BDSKUnknownStringType && type != 
BDSKNoKeyBibTeXStringType){
             pubs = [BDSKStringParser itemsFromString:contentString ofType:type 
error:&error];

Modified: trunk/bibdesk/BDSKWebGroup.m
===================================================================
--- trunk/bibdesk/BDSKWebGroup.m        2012-02-03 18:25:37 UTC (rev 18482)
+++ trunk/bibdesk/BDSKWebGroup.m        2012-02-04 12:06:07 UTC (rev 18483)
@@ -214,7 +214,7 @@
         else if (nil == newPubs && [MIMEType hasPrefix:@"text/"]) {
             // !!! logs are here to help diagnose problems that users are 
reporting
             // but unsupported web pages are far too common, we don't want to 
flood the console
-            if ([[error domain] isEqualToString:[NSError localErrorDomain]] == 
NO || [error code] != kBDSKWebParserUnsupported)
+            if ([error isLocalErrorWithCode:kBDSKWebParserUnsupported] == NO)
                 NSLog(@"-[%@ %@] %@", [self class], 
NSStringFromSelector(_cmd), error);
             //NSLog(@"loaded MIME type %@", [[dataSource mainResource] 
MIMEType]);
             // !!! what to do here? if user clicks on a PDF, we're loading 
application/pdf, which is clearly not an error from the user perspective...so 
should the error only be presented for text/plain?

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2012-02-03 18:25:37 UTC (rev 18482)
+++ trunk/bibdesk/BibDocument.m 2012-02-04 12:06:07 UTC (rev 18483)
@@ -1406,7 +1406,7 @@
     if(nil == data && outError){
         // see if this was an encoding failure; if so, we can suggest how to 
fix it
         // NSLocalizedRecoverySuggestion is appropriate for display as error 
message in alert
-        if(kBDSKStringEncodingError == [error code]){
+        if([error isLocalErrorWithCode:kBDSKStringEncodingError]){
             // encoding conversion failure (string to data)
             NSStringEncoding usedEncoding = [[error 
valueForKey:NSStringEncodingErrorKey] integerValue];
             NSMutableString *message = [NSMutableString 
stringWithFormat:NSLocalizedString(@"The document cannot be saved using %@ 
encoding.", @"Error informative text"), [NSString 
localizedNameOfStringEncoding:usedEncoding]];
@@ -2198,11 +2198,11 @@
                     if (type != BDSKUnknownStringType) {
                         contentArray = [BDSKStringParser 
itemsFromString:contentString ofType:type owner:self 
isPartialData:&isPartialData error:&parseError];
                         
-                        if (isPartialData && [parseError isLocalError]) {
-                            if ([parseError code] == 
kBDSKParserIgnoredFrontMatter) {
+                        if (isPartialData) {
+                            if ([parseError 
isLocalErrorWithCode:kBDSKParserIgnoredFrontMatter]) {
                                 if (verbose) [self presentError:parseError];
                                 parseError = nil;
-                            } else if([parseError code] == 
kBDSKBibTeXParserFailed) {
+                            } else if([parseError 
isLocalErrorWithCode:kBDSKBibTeXParserFailed]) {
                                 if (verbose == NO || [self 
presentError:parseError] == NO)
                                     contentArray = nil;
                             }
@@ -2341,15 +2341,15 @@
         newPubs = newPubs ? [newPubs 
arrayByAddingObjectsFromArray:newFilePubs]: newFilePubs;
     }
     
-    if([error isLocalError] && [error code] == kBDSKHadMissingCiteKeys) {
+    if([error isLocalErrorWithCode:kBDSKHadMissingCiteKeys]) {
         temporaryCiteKey = [[error userInfo] objectForKey:@"temporaryCiteKey"];
         error = nil; // accept temporary cite keys, but show a warning later
-    }else if([error isLocalError] && [error code] == 
kBDSKParserIgnoredFrontMatter){
+    }else if([error isLocalErrorWithCode:kBDSKParserIgnoredFrontMatter]){
         // just warn about this error when verbose, don't treat this as an 
error further
         if (verbose)
             [self presentError:error];
         error = nil;
-    }else if([error isLocalError] && [error code] == kBDSKBibTeXParserFailed){
+    }else if([error isLocalErrorWithCode:kBDSKBibTeXParserFailed]){
         // this asks whether to ignore partially failed bibtex when verbose, 
otherwise just ignore, for NSFilenamesPboardType this was already handled
         if(isPartialData && (verbose == NO || [self presentError:error] == NO))
             newPubs = nil;

Modified: trunk/bibdesk/NSError_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/NSError_BDSKExtensions.h      2012-02-03 18:25:37 UTC (rev 
18482)
+++ trunk/bibdesk/NSError_BDSKExtensions.h      2012-02-04 12:06:07 UTC (rev 
18483)
@@ -85,6 +85,7 @@
 
 // see if it has our local domain
 - (BOOL)isLocalError;
+- (BOOL)isLocalErrorWithCode:(NSInteger)code;
 - (BOOL)isMutable;
 
 // embed an underlying error; if this isn't a mutable subclass, raises an 
exception

Modified: trunk/bibdesk/NSError_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSError_BDSKExtensions.m      2012-02-03 18:25:37 UTC (rev 
18482)
+++ trunk/bibdesk/NSError_BDSKExtensions.m      2012-02-04 12:06:07 UTC (rev 
18483)
@@ -129,6 +129,11 @@
     return [[self domain] isEqualToString:[NSError localErrorDomain]];
 }
 
+- (BOOL)isLocalErrorWithCode:(NSInteger)code;
+{
+    return [self isLocalError] && [self code] == code;
+}
+
 + (id)localErrorWithCode:(NSInteger)code localizedDescription:(NSString 
*)description;
 {
     NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:description, NSLocalizedDescriptionKey, nil];

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

Reply via email to