Revision: 22616
          http://sourceforge.net/p/bibdesk/svn/22616
Author:   hofman
Date:     2018-09-16 12:36:11 +0000 (Sun, 16 Sep 2018)
Log Message:
-----------
Add scripting support for authors in arbitrary person fields, as element of 
fields

Modified Paths:
--------------
    trunk/bibdesk/BDSKField.h
    trunk/bibdesk/BDSKField.m
    trunk/bibdesk/BibAuthor+Scripting.m
    trunk/bibdesk/Scripting/BibDesk.sdef

Modified: trunk/bibdesk/BDSKField.h
===================================================================
--- trunk/bibdesk/BDSKField.h   2018-09-16 06:30:55 UTC (rev 22615)
+++ trunk/bibdesk/BDSKField.h   2018-09-16 12:36:11 UTC (rev 22616)
@@ -37,8 +37,9 @@
  */
 
 #import <Cocoa/Cocoa.h>
-#import "BibItem.h"
 
+@class BibItem, BibAuthor;
+
 @interface BDSKField : NSObject {
        NSString *name;
        BibItem *bibItem;
@@ -70,4 +71,7 @@
 
 - (BOOL)isInherited;
 
+- (NSArray *)scriptingAuthors;
+- (BibAuthor *)valueInScriptingAuthorsWithName:(NSString *)aName;
+
 @end

Modified: trunk/bibdesk/BDSKField.m
===================================================================
--- trunk/bibdesk/BDSKField.m   2018-09-16 06:30:55 UTC (rev 22615)
+++ trunk/bibdesk/BDSKField.m   2018-09-16 12:36:11 UTC (rev 22616)
@@ -39,6 +39,8 @@
 #import "BDSKField.h"
 #import "BDSKOwnerProtocol.h"
 #import "BDSKTypeManager.h"
+#import "BibItem.h"
+#import "BibAuthor.h"
 
 /* cmh
 A wrapper object around the fields to access them in AppleScript. 
@@ -207,4 +209,23 @@
        return [[bibItem valueOfField:name] isInherited];
 }
 
+- (NSArray *)scriptingAuthors {
+    return [name isPersonField] ? [bibItem peopleArrayForField:name] : nil;
+}
+
+- (BibAuthor *)valueInScriptingAuthorsWithName:(NSString *)aName {
+    if ([name isPersonField] == NO)
+        return nil;
+    
+    // create a new author so we can use BibAuthor's isEqual: method for 
comparison
+    // instead of trying to do string comparisons
+    BibAuthor *newAuth = [BibAuthor authorWithName:aName];
+    
+    for (BibAuthor *auth in [bibItem peopleArrayForField:name]) {
+        if ([auth isEqual:newAuth])
+            return auth;
+    }
+    return nil;
+}
+
 @end

Modified: trunk/bibdesk/BibAuthor+Scripting.m
===================================================================
--- trunk/bibdesk/BibAuthor+Scripting.m 2018-09-16 06:30:55 UTC (rev 22615)
+++ trunk/bibdesk/BibAuthor+Scripting.m 2018-09-16 12:36:11 UTC (rev 22616)
@@ -88,9 +88,14 @@
 
 - (NSScriptObjectSpecifier *) objectSpecifier {
        NSScriptObjectSpecifier *containerRef = [[self publication] 
objectSpecifier];
-    NSString *key = [field isEqualToString:BDSKEditorString] ? 
@"scriptingEditors" : @"scriptingAuthors";
-               
-       return [[[NSNameSpecifier allocWithZone:[self zone]] 
initWithContainerClassDescription:[containerRef keyClassDescription] 
containerSpecifier:containerRef key:key name:[self normalizedName]] 
autorelease];
+    NSString *key = @"scriptingAuthors";
+    
+    if ([field isEqualToString:BDSKEditorString])
+        key = @"scriptingEditors";
+    else if ([key isEqualToString:BDSKAuthorString] == NO)
+        containerRef = [[[NSNameSpecifier allocWithZone:[self zone]] 
initWithContainerClassDescription:[containerRef keyClassDescription] 
containerSpecifier:containerRef key:@"bibFields" name:field] autorelease];
+    
+    return [[[NSNameSpecifier allocWithZone:[self zone]] 
initWithContainerClassDescription:[containerRef keyClassDescription] 
containerSpecifier:containerRef key:key name:[self normalizedName]] 
autorelease];
 }
 
 - (NSArray *)scriptingPublications {

Modified: trunk/bibdesk/Scripting/BibDesk.sdef
===================================================================
--- trunk/bibdesk/Scripting/BibDesk.sdef        2018-09-16 06:30:55 UTC (rev 
22615)
+++ trunk/bibdesk/Scripting/BibDesk.sdef        2018-09-16 12:36:11 UTC (rev 
22616)
@@ -1183,6 +1183,10 @@
                 description="Whether the value of the field is inherited 
(crossreffed)">
                 <cocoa key="isInherited"/>
             </property>
+            <element type="author" name="author" access="r"
+                description="Person values of the field.">
+                <cocoa key="scriptingAuthors"/>
+            </element>
         </class>
         
         <class name="info" plural="infos" code="Info"

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