Revision: 12284
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12284&view=rev
Author:   hofman
Date:     2008-01-05 11:41:57 -0800 (Sat, 05 Jan 2008)

Log Message:
-----------
Add a field ivar to BibAuthor, so scripting knows if it is an author or an 
editor. It may have other uses as well.

Modified Paths:
--------------
    trunk/bibdesk/BDSKBibTeXParser.h
    trunk/bibdesk/BDSKBibTeXParser.m
    trunk/bibdesk/BDSKPersonController.m
    trunk/bibdesk/BDSKPublicationsArray.h
    trunk/bibdesk/BDSKPublicationsArray.m
    trunk/bibdesk/BibAuthor+Scripting.m
    trunk/bibdesk/BibAuthor.h
    trunk/bibdesk/BibAuthor.m
    trunk/bibdesk/BibDocument+Scripting.m
    trunk/bibdesk/BibItem.m

Modified: trunk/bibdesk/BDSKBibTeXParser.h
===================================================================
--- trunk/bibdesk/BDSKBibTeXParser.h    2008-01-05 19:07:09 UTC (rev 12283)
+++ trunk/bibdesk/BDSKBibTeXParser.h    2008-01-05 19:41:57 UTC (rev 12284)
@@ -102,12 +102,12 @@
 + (NSDictionary *)macrosFromBibTeXStyle:(NSString *)styleContents 
document:(BibDocument *)aDocument;
     
 /*!
-    @method     authorsFromBibtexString:document:
+    @method     authorsFromBibtexString:withPublication:forField
     @abstract   Parses a BibTeX author string (separates components joined by 
the string "and")
     @discussion (comprehensive description)
     @param      aString The author string
     @result     An array of BibAuthor objects.
 */
-+ (NSArray *)authorsFromBibtexString:(NSString *)aString 
withPublication:(BibItem *)pub;
++ (NSArray *)authorsFromBibtexString:(NSString *)aString 
withPublication:(BibItem *)pub forField:(NSString *)field;
 
 @end

Modified: trunk/bibdesk/BDSKBibTeXParser.m
===================================================================
--- trunk/bibdesk/BDSKBibTeXParser.m    2008-01-05 19:07:09 UTC (rev 12283)
+++ trunk/bibdesk/BDSKBibTeXParser.m    2008-01-05 19:41:57 UTC (rev 12284)
@@ -596,7 +596,7 @@
     return mutableArray;
 }
 
-+ (NSArray *)authorsFromBibtexString:(NSString *)aString 
withPublication:(BibItem *)pub{
++ (NSArray *)authorsFromBibtexString:(NSString *)aString 
withPublication:(BibItem *)pub forField:(NSString *)field{
     
        NSMutableArray *authors = [NSMutableArray arrayWithCapacity:2];
     
@@ -625,7 +625,7 @@
     BibAuthor *anAuthor;
     
     for(i = 0; i < iMax; i++){
-        anAuthor = [[BibAuthor alloc] 
initWithName:(id)CFArrayGetValueAtIndex(names, i) andPub:pub];
+        anAuthor = [[BibAuthor alloc] 
initWithName:(id)CFArrayGetValueAtIndex(names, i) andPub:pub forField:(NSString 
*)field];
         [authors addObject:anAuthor];
         [anAuthor release];
     }

Modified: trunk/bibdesk/BDSKPersonController.m
===================================================================
--- trunk/bibdesk/BDSKPersonController.m        2008-01-05 19:07:09 UTC (rev 
12283)
+++ trunk/bibdesk/BDSKPersonController.m        2008-01-05 19:41:57 UTC (rev 
12284)
@@ -236,7 +236,7 @@
             fieldName = [fieldNames objectAtIndex:fieldIndex];
             
             // create a new array of BibAuthor objects from a person field 
(which may be nil or empty)
-            peopleFromString = [BDSKBibTeXParser authorsFromBibtexString:[pub 
valueOfField:fieldName] withPublication:pub];
+            peopleFromString = [BDSKBibTeXParser authorsFromBibtexString:[pub 
valueOfField:fieldName] withPublication:pub forField:fieldName];
                     
             if([peopleFromString count]){
                 

Modified: trunk/bibdesk/BDSKPublicationsArray.h
===================================================================
--- trunk/bibdesk/BDSKPublicationsArray.h       2008-01-05 19:07:09 UTC (rev 
12283)
+++ trunk/bibdesk/BDSKPublicationsArray.h       2008-01-05 19:41:57 UTC (rev 
12284)
@@ -54,5 +54,6 @@
 - (BOOL)citeKeyIsCrossreffed:(NSString *)key;
 - (id)itemForIdentifierURL:(NSURL *)aURL;
 - (NSArray *)itemsForAuthor:(BibAuthor *)anAuthor;
+- (NSArray *)itemsForEditor:(BibAuthor *)anEditor;
 
 @end

Modified: trunk/bibdesk/BDSKPublicationsArray.m
===================================================================
--- trunk/bibdesk/BDSKPublicationsArray.m       2008-01-05 19:07:09 UTC (rev 
12283)
+++ trunk/bibdesk/BDSKPublicationsArray.m       2008-01-05 19:41:57 UTC (rev 
12284)
@@ -282,6 +282,24 @@
     return anAuthorPubs;
 }
 
+- (NSArray *)itemsForEditor:(BibAuthor *)anEditor;
+{
+    NSMutableSet *auths = BDSKCreateFuzzyAuthorCompareMutableSet();
+    NSEnumerator *pubEnum = [publications objectEnumerator];
+    BibItem *bi;
+    NSMutableArray *anEditorPubs = [NSMutableArray array];
+    
+    while(bi = [pubEnum nextObject]){
+        [auths addObjectsFromArray:[bi pubEditors]];
+        if([auths containsObject:anEditor]){
+            [anEditorPubs addObject:bi];
+        }
+        [auths removeAllObjects];
+    }
+    [auths release];
+    return anEditorPubs;
+}
+
 @end
 
 

Modified: trunk/bibdesk/BibAuthor+Scripting.m
===================================================================
--- trunk/bibdesk/BibAuthor+Scripting.m 2008-01-05 19:07:09 UTC (rev 12283)
+++ trunk/bibdesk/BibAuthor+Scripting.m 2008-01-05 19:41:57 UTC (rev 12284)
@@ -51,24 +51,21 @@
     // only publications belonging to a BibDocument are scriptable
        BibDocument * myDoc = (BibDocument *)[[self publication] owner];
        NSScriptObjectSpecifier *containerRef = [myDoc objectSpecifier];
+    NSString *key = [field isEqualToString:BDSKEditorString] ? @"editors" : 
@"authors";
                
-       return [[[NSNameSpecifier allocWithZone:[self zone]] 
initWithContainerClassDescription:[containerRef keyClassDescription] 
containerSpecifier:containerRef key:@"authors" name:[self normalizedName]] 
autorelease];
-/*     unsigned index = [ar indexOfObjectIdenticalTo:self];
-    if (index != NSNotFound) {
-        NSScriptObjectSpecifier *containerRef = [[self document] 
objectSpecifier];
-        return [[[NSIndexSpecifier allocWithZone:[self zone]] 
initWithContainerClassDescription:[containerRef keyClassDescription] 
containerSpecifier:containerRef key:@"publications" index:index] autorelease];
-    } else {
-        return nil;
-    }
-*/     
+       return [[[NSNameSpecifier allocWithZone:[self zone]] 
initWithContainerClassDescription:[containerRef keyClassDescription] 
containerSpecifier:containerRef key:key name:[self normalizedName]] 
autorelease];
 }
 
 - (NSArray *)publications {
     // only publications belonging to a BibDocument are scriptable
        BibDocument * myDoc = (BibDocument *)[[self publication] owner];
-       if (myDoc)
-               return [[myDoc publications] itemsForAuthor:self];
-       return [NSArray array];
+       if (myDoc) {
+        if ([field isEqualToString:BDSKEditorString])
+            return [[myDoc publications] itemsForEditor:self];
+        else
+            return [[myDoc publications] itemsForAuthor:self];
+       }
+    return [NSArray array];
 }
 
 @end

Modified: trunk/bibdesk/BibAuthor.h
===================================================================
--- trunk/bibdesk/BibAuthor.h   2008-01-05 19:07:09 UTC (rev 12283)
+++ trunk/bibdesk/BibAuthor.h   2008-01-05 19:41:57 UTC (rev 12284)
@@ -78,6 +78,7 @@
     NSString *unpunctuatedAbbreviatedNormalizedName;
     BDSKPersonController *personController; // unretained
     BibItem *publication;
+    NSString *field;
     unsigned hash;
    
 @private
@@ -91,7 +92,7 @@
 + (BibAuthor *)authorWithVCardRepresentation:(NSData *)vCard andPub:aPub;
 
 // maybe this should be 'and pubs'
-- (id)initWithName:(NSString *)aName andPub:(BibItem *)aPub;
+- (id)initWithName:(NSString *)aName andPub:(BibItem *)aPub forField:(NSString 
*)aField;
 - (void)dealloc;
 
 - (NSComparisonResult)compare:(BibAuthor *)otherAuth;
@@ -133,6 +134,8 @@
 - (BibItem *)publication;
 - (void)setPublication:(BibItem *)newPub;
 
+- (NSString *)field;
+
 - (BDSKPersonController *)personController;
 - (void)setPersonController:(BDSKPersonController *)newPersonController;
 - (ABPerson *)personFromAddressBook;

Modified: trunk/bibdesk/BibAuthor.m
===================================================================
--- trunk/bibdesk/BibAuthor.m   2008-01-05 19:07:09 UTC (rev 12283)
+++ trunk/bibdesk/BibAuthor.m   2008-01-05 19:41:57 UTC (rev 12284)
@@ -66,7 +66,7 @@
 + (void)initialize{
     
     OBINITIALIZE;
-    emptyAuthorInstance = [[BibAuthor alloc] initWithName:@"" andPub:nil];
+    emptyAuthorInstance = [[BibAuthor alloc] initWithName:@"" andPub:nil 
forField:BDSKAuthorString];
 }
     
 
@@ -75,7 +75,7 @@
 }
 
 + (BibAuthor *)authorWithName:(NSString *)newName andPub:(BibItem *)aPub{      
-    return [[[BibAuthor alloc] initWithName:newName andPub:aPub] autorelease];
+    return [[[BibAuthor alloc] initWithName:newName andPub:aPub 
forField:BDSKAuthorString] autorelease];
 }
 
 + (BibAuthor *)authorWithVCardRepresentation:(NSData *)vCard andPub:aPub{
@@ -104,7 +104,7 @@
     return emptyAuthorInstance;
 }
 
-- (id)initWithName:(NSString *)aName andPub:(BibItem *)aPub{
+- (id)initWithName:(NSString *)aName andPub:(BibItem *)aPub forField:(NSString 
*)aField{
        if (self = [super init]) {
         // zero the flags
         memset(&flags, (BOOL)0, sizeof(BibAuthorFlags));
@@ -112,6 +112,8 @@
                // set this first so we have the document for parser errors
         publication = aPub; // don't retain this, since it retains us
         
+        field = aField ? [aField retain] : [BDSKAuthorString retain];
+        
         originalName = [aName copy];
         // this does all the name parsing
                [self splitName:aName];
@@ -135,6 +137,7 @@
     [unpunctuatedAbbreviatedNormalizedName release];
     [firstNames release];
     [fuzzyName release];
+    [field release];
     [super dealloc];
 }
 
@@ -383,6 +386,10 @@
     publication = newPub;
 }
 
+- (NSString *)field{
+    return field;
+}
+
 // Accessors for personController - we don't retain it to avoid cycles.
 - (BDSKPersonController *)personController{
     return personController; 

Modified: trunk/bibdesk/BibDocument+Scripting.m
===================================================================
--- trunk/bibdesk/BibDocument+Scripting.m       2008-01-05 19:07:09 UTC (rev 
12283)
+++ trunk/bibdesk/BibDocument+Scripting.m       2008-01-05 19:41:57 UTC (rev 
12284)
@@ -199,12 +199,12 @@
 }
 
 - (BibAuthor *)objectInAuthorsAtIndex:(unsigned int)idx {
-       NSMutableSet *auths = [NSMutableSet set];
+       NSMutableArray *auths = [NSMutableArray array];
        
     [auths performSelector:@selector(addObjectsFromArray:) 
withObjectsByMakingObjectsFromArray:publications 
performSelector:@selector(pubAuthors)];
        
        if (idx < [auths count]) 
-               return [[auths allObjects] objectAtIndex:idx];
+               return [auths objectAtIndex:idx];
        return nil;
 }
 
@@ -217,14 +217,12 @@
     // instead of trying to do string comparisons
     BibAuthor *newAuth = [BibAuthor authorWithName:name andPub:nil];
     
-       NSEnumerator *pubEnum;
+       NSEnumerator *pubEnum = [publications objectEnumerator];
        NSEnumerator *authEnum;
        BibItem *pub;
        BibAuthor *auth;
-       BibAuthor *author;
-    BibAuthor *editor = nil;
+       BibAuthor *author = nil;
 
-    pubEnum = [publications objectEnumerator];
        while (author == nil && (pub = [pubEnum nextObject])) {
                authEnum = [[pub pubAuthors] objectEnumerator];
                while (auth = [authEnum nextObject]) {
@@ -233,16 +231,9 @@
                 break;
             }
                }
-        if (editor == nil) {
-            authEnum = [[pub pubEditors] objectEnumerator];
-            while (auth = [authEnum nextObject]) {
-                if ([auth isEqual:newAuth])
-                    editor = auth;
-            }
-        }
        }
     
-       return author ? author : editor;
+       return author;
 }
 
 - (unsigned int)countOfEditors {
@@ -254,12 +245,12 @@
 }
 
 - (BibAuthor *)objectInEditorsAtIndex:(unsigned int)idx {
-       NSMutableSet *auths = [NSMutableSet set];
+       NSMutableArray *auths = [NSMutableArray array];
        
     [auths performSelector:@selector(addObjectsFromArray:) 
withObjectsByMakingObjectsFromArray:publications 
performSelector:@selector(pubEditors)];
        
        if (idx < [auths count]) 
-               return [[auths allObjects] objectAtIndex:idx];
+               return [auths objectAtIndex:idx];
        return nil;
 }
 
@@ -272,14 +263,13 @@
     // instead of trying to do string comparisons
     BibAuthor *newAuth = [BibAuthor authorWithName:name andPub:nil];
     
-       NSEnumerator *pubEnum;
+       NSEnumerator *pubEnum = [publications objectEnumerator];
        NSEnumerator *authEnum;
        BibItem *pub;
        BibAuthor *auth;
     BibAuthor *editor = nil;
 
-    pubEnum = [publications objectEnumerator];
-       while (pub = [pubEnum nextObject]) {
+       while (editor == nil && (pub = [pubEnum nextObject])) {
                authEnum = [[pub pubEditors] objectEnumerator];
                while (auth = [authEnum nextObject]) {
                        if ([auth isEqual:newAuth]) {
@@ -289,7 +279,7 @@
                }
        }
     
-       return nil;
+       return editor;
 }
 
 - (NSArray*) selection { 

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2008-01-05 19:07:09 UTC (rev 12283)
+++ trunk/bibdesk/BibItem.m     2008-01-05 19:41:57 UTC (rev 12284)
@@ -582,7 +582,7 @@
             personStr = [pubFields objectForKey:personType];
             
             // parse into an array of BibAuthor objects
-            NSArray *tmpPeople = [BDSKBibTeXParser 
authorsFromBibtexString:personStr withPublication:self];
+            NSArray *tmpPeople = [BDSKBibTeXParser 
authorsFromBibtexString:personStr withPublication:self forField:personStr];
             if([tmpPeople count])
                 [people setObject:tmpPeople forKey:personType];
         }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to