Revision: 25186
          http://sourceforge.net/p/bibdesk/svn/25186
Author:   hofman
Date:     2020-12-12 17:46:21 +0000 (Sat, 12 Dec 2020)
Log Message:
-----------
remove isValidCiteKey from parseable item protocol, implement in parser

Modified Paths:
--------------
    trunk/bibdesk/BDSKFormatParser.h
    trunk/bibdesk/BDSKFormatParser.m
    trunk/bibdesk/BDSKPreviewItem.m

Modified: trunk/bibdesk/BDSKFormatParser.h
===================================================================
--- trunk/bibdesk/BDSKFormatParser.h    2020-12-12 17:34:57 UTC (rev 25185)
+++ trunk/bibdesk/BDSKFormatParser.h    2020-12-12 17:46:21 UTC (rev 25186)
@@ -47,7 +47,6 @@
 - (NSInteger)integerValueOfField:(NSString *)field;
 - (NSArray *)peopleArrayForField:(NSString *)field;
 - (NSURL *)localFileURLForField:(NSString *)field;
-- (BOOL)isValidCiteKey:(NSString *)key;
 - (id<BDSKOwner>)owner;
 @end
 

Modified: trunk/bibdesk/BDSKFormatParser.m
===================================================================
--- trunk/bibdesk/BDSKFormatParser.m    2020-12-12 17:34:57 UTC (rev 25185)
+++ trunk/bibdesk/BDSKFormatParser.m    2020-12-12 17:46:21 UTC (rev 25186)
@@ -48,6 +48,7 @@
 #import "BDSKStringNode.h"
 #import "BDSKLinkedFile.h"
 #import "BDSKAppController.h"
+#import "BDSKPublicationsArray.h"
 #import "NSURL_BDSKExtensions.h"
 #import "NSParagraphStyle_BDSKExtensions.h"
 #import "NSColor_BDSKExtensions.h"
@@ -102,6 +103,8 @@
 static NSDictionary *textAttr = nil;
 static NSDictionary *errorAttr = nil;
 
+static BOOL isValidCiteKey(NSString *key, id<BDSKParseableItem> pub);
+
 static NSUInteger hashedTitleOrDOI(id<BDSKParseableItem> pub, BOOL *isDOI);
 
 static BOOL scanOptArg(NSScanner *scanner, NSString **result, BOOL 
*lastCharEscaped);
@@ -788,7 +791,7 @@
                 currentStr = nil;
         } else if ([fieldName isEqualToString:BDSKCiteKeyString]) {
             currentStr = [pub citeKey];
-            if ([pub isValidCiteKey:currentStr] == NO)
+            if (isValidCiteKey(currentStr, pub) == NO)
                 currentStr = nil;
         } else {
             currentStr = [pub stringValueOfField:fieldName];
@@ -853,7 +856,7 @@
             if ([NSString isEmptyString:str])
                 return nil;
             else if ([fieldName isEqualToString:BDSKCiteKeyString])
-                return [pub isValidCiteKey:str] ? str : nil;
+                return isValidCiteKey(str, pub) ? str : nil;
             else if ([fieldName isGeneralLocalFileField])
                 return [[papersFolderURL URLByAppendingPathComponent:str] 
checkResourceIsReachableAndReturnError:NULL] ? nil : str;
             else
@@ -1291,6 +1294,13 @@
     return [NSURL fileURLWithPath:[papersFolderPath 
stringByExpandingTildeInPath] isDirectory:YES];
 }
 
+static BOOL isValidCiteKey(NSString *key, id <BDSKParseableItem> pub) {
+    if ([NSString isEmptyString:key])
+        return NO;
+    NSArray *items = [[[pub owner] publications] allItemsForCiteKey:key];
+    return [items count] == 0 || ([items count] == 1 && [items firstObject] == 
pub);
+}
+
 static NSUInteger hashedTitleOrDOI(id<BDSKParseableItem> pub, BOOL *isDOI) {
     NSString *string = [pub title];
     if ([NSString isEmptyString:string] == NO) {

Modified: trunk/bibdesk/BDSKPreviewItem.m
===================================================================
--- trunk/bibdesk/BDSKPreviewItem.m     2020-12-12 17:34:57 UTC (rev 25185)
+++ trunk/bibdesk/BDSKPreviewItem.m     2020-12-12 17:46:21 UTC (rev 25186)
@@ -130,8 +130,6 @@
     return ([field isEqualToString:BDSKAuthorString]) ? pubAuthors : [NSArray 
array];
 }
 
-- (BOOL)isValidCiteKey:(NSString *)key { return [NSString isEmptyString:key] 
== NO; }
-
 - (NSString *)suggestedLocalFilePath {
        NSString *localFileFormat = [[NSUserDefaults standardUserDefaults] 
stringForKey:BDSKLocalFileFormatKey];
        NSString *path = [BDSKFormatParser parseFormat:localFileFormat 
forLinkedFile:linkedFile ofItem:self];

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

Reply via email to