From: <ho...@us...> - 2009-11-27 19:43:25
|
Revision: 16175 http://bibdesk.svn.sourceforge.net/bibdesk/?rev=16175&view=rev Author: hofman Date: 2009-11-27 18:38:28 +0000 (Fri, 27 Nov 2009) Log Message: ----------- simplify getting old/new values for scripthooks when generating cite keys Modified Paths: -------------- trunk/bibdesk/BibDocument_Actions.m Modified: trunk/bibdesk/BibDocument_Actions.m =================================================================== --- trunk/bibdesk/BibDocument_Actions.m 2009-11-27 18:24:44 UTC (rev 16174) +++ trunk/bibdesk/BibDocument_Actions.m 2009-11-27 18:38:28 UTC (rev 16175) @@ -1485,29 +1485,17 @@ return; } - NSUInteger numberOfPubs = [pubs count]; - BibItem *aPub; - NSMutableArray *arrayOfPubs = [NSMutableArray arrayWithCapacity:numberOfPubs]; - NSMutableArray *arrayOfOldValues = [NSMutableArray arrayWithCapacity:numberOfPubs]; - NSMutableArray *arrayOfNewValues = [NSMutableArray arrayWithCapacity:numberOfPubs]; + NSArray *arrayOfPubs = [pubs copy]; // copy in case we were passed a mutable aray and the order changes + NSArray *arrayOfOldValues = [arrayOfPubs valueForKey:@"citeKey"]; + NSArray *arrayOfNewValues = [arrayOfPubs valueForKey:@"suggestedCiteKey"]; - // put these pubs into an array, since the indices can change after we set the cite key, due to sorting or searching - for (aPub in pubs) { - [arrayOfPubs addObject:aPub]; - [arrayOfOldValues addObject:[aPub citeKey]]; - [arrayOfNewValues addObject:[aPub suggestedCiteKey]]; - } - [[BDSKScriptHookManager sharedManager] runScriptHookWithName:BDSKWillGenerateCiteKeyScriptHookName forPublications:arrayOfPubs document:self field:BDSKCiteKeyString oldValues:arrayOfOldValues newValues:arrayOfNewValues]; - [arrayOfOldValues removeAllObjects]; - [arrayOfNewValues removeAllObjects]; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - for (aPub in arrayOfPubs){ + for (BibItem *aPub in arrayOfPubs){ NSString *newKey = [aPub suggestedCiteKey]; NSString *crossref = [aPub valueOfField:BDSKCrossrefString inherit:NO]; if (crossref != nil && [crossref caseInsensitiveCompare:newKey] == NSOrderedSame) { @@ -1524,9 +1512,6 @@ } [aPub setCiteKey:newKey]; - [arrayOfOldValues addObject:[aPub citeKey]]; - [arrayOfNewValues addObject:newKey]; - [pool release]; pool = [[NSAutoreleasePool alloc] init]; } @@ -1534,11 +1519,15 @@ // should be safe to release here since arrays were created outside the scope of this local pool [pool release]; - [[self undoManager] setActionName:(numberOfPubs > 1 ? NSLocalizedString(@"Generate Cite Keys", @"Undo action name") : NSLocalizedString(@"Generate Cite Key", @"Undo action name"))]; + [[self undoManager] setActionName:([arrayOfPubs count] > 1 ? NSLocalizedString(@"Generate Cite Keys", @"Undo action name") : NSLocalizedString(@"Generate Cite Key", @"Undo action name"))]; + arrayOfNewValues = [arrayOfPubs valueForKey:@"citeKey"]; + [[BDSKScriptHookManager sharedManager] runScriptHookWithName:BDSKDidGenerateCiteKeyScriptHookName forPublications:arrayOfPubs document:self field:BDSKCiteKeyString oldValues:arrayOfOldValues newValues:arrayOfNewValues]; + + [arrayOfPubs release]; } - (void)generateCiteKeyAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |