From: <ho...@us...> - 2006-05-10 13:45:38
|
Revision: 6499 Author: hofman Date: 2006-05-10 06:45:29 -0700 (Wed, 10 May 2006) ViewCVS: http://svn.sourceforge.net/bibdesk/?rev=6499&view=rev Log Message: ----------- Reorganize file and add some pragma marks. Modified Paths: -------------- trunk/bibdesk/BibItem.m Modified: trunk/bibdesk/BibItem.m =================================================================== --- trunk/bibdesk/BibItem.m 2006-05-10 12:29:06 UTC (rev 6498) +++ trunk/bibdesk/BibItem.m 2006-05-10 13:45:29 UTC (rev 6499) @@ -77,14 +77,14 @@ - (void)setDateModified:(NSCalendarDate *)newDateModified; - (void)setDate: (NSCalendarDate *)newDate; +- (id)stringCache; + // updates derived info from the dictionary - (void)updateMetadataForKey:(NSString *)key; @end -#define addkey(s) if([pubFields objectForKey: s usingLock:bibLock] == nil){[pubFields setObject:@"" forKey: s usingLock:bibLock];} [removeKeys removeObject: s usingLock:bibLock]; - CFHashCode BibItemCaseInsensitiveCiteKeyHash(const void *item) { OBASSERT([(id)item isKindOfClass:[BibItem class]]); @@ -110,6 +110,8 @@ static NSParagraphStyle* keyParagraphStyle = nil; static NSParagraphStyle* bodyParagraphStyle = nil; +#pragma mark - + @implementation BibItem + (void)initialize @@ -257,40 +259,6 @@ return [encoder isByref] ? (id)[NSDistantObject proxyWithLocal:self connection:[encoder connection]] : self; } -- (void)makeType{ - NSString *fieldString; - BibTypeManager *typeMan = [BibTypeManager sharedManager]; - NSEnumerator *reqFieldsE = [[typeMan requiredFieldsForType:pubType] objectEnumerator]; - NSEnumerator *optFieldsE = [[typeMan optionalFieldsForType:pubType] objectEnumerator]; - NSEnumerator *defFieldsE = [[typeMan userDefaultFieldsForType:pubType] objectEnumerator]; - - NSMutableArray *removeKeys = [NSMutableArray array]; - NSEnumerator *keyE = [[pubFields allKeysUsingLock:bibLock] objectEnumerator]; - NSString *key; - - while (key = [keyE nextObject]) { - if ([[pubFields objectForKey:key usingLock:bibLock] isEqualAsComplexString:@""]) - [removeKeys addObject:key]; - } - - while(fieldString = [reqFieldsE nextObject]){ - addkey(fieldString) - } - while(fieldString = [optFieldsE nextObject]){ - addkey(fieldString) - } - while(fieldString = [defFieldsE nextObject]){ - addkey(fieldString) - } - - //I don't enforce Keywords, but since there's GUI depending on them, I will enforce these others: - addkey(BDSKLocalUrlString) addkey(BDSKUrlString) addkey(BDSKAnnoteString) addkey(BDSKAbstractString) addkey(BDSKRssDescriptionString) - - // now remove everything that's left in remove keys from pubfields - [pubFields removeObjectsForKeys:removeKeys usingLock:bibLock]; - -} - - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; [[self undoManager] removeAllActionsWithTarget:self]; @@ -309,20 +277,6 @@ [super dealloc]; } -- (BibDocument *)document { - return document; -} - -- (void)setDocument:(BibDocument *)newDocument { - if (document != newDocument) { - document = newDocument; - } -} - -- (NSUndoManager *)undoManager { // this may be nil - return [document undoManager]; -} - - (NSString *)description{ return [NSString stringWithFormat:@"%@ %@", [self citeKey], [pubFields description]]; } @@ -406,6 +360,71 @@ (unsigned int) self << (32 - 4)); } +#pragma mark - + +#pragma mark Type info + +#define addkey(s) if([pubFields objectForKey: s usingLock:bibLock] == nil){[pubFields setObject:@"" forKey: s usingLock:bibLock];} [removeKeys removeObject: s usingLock:bibLock]; + +- (void)makeType{ + NSString *fieldString; + BibTypeManager *typeMan = [BibTypeManager sharedManager]; + NSEnumerator *reqFieldsE = [[typeMan requiredFieldsForType:pubType] objectEnumerator]; + NSEnumerator *optFieldsE = [[typeMan optionalFieldsForType:pubType] objectEnumerator]; + NSEnumerator *defFieldsE = [[typeMan userDefaultFieldsForType:pubType] objectEnumerator]; + + NSMutableArray *removeKeys = [NSMutableArray array]; + NSEnumerator *keyE = [[pubFields allKeysUsingLock:bibLock] objectEnumerator]; + NSString *key; + + while (key = [keyE nextObject]) { + if ([[pubFields objectForKey:key usingLock:bibLock] isEqualAsComplexString:@""]) + [removeKeys addObject:key]; + } + + while(fieldString = [reqFieldsE nextObject]){ + addkey(fieldString) + } + while(fieldString = [optFieldsE nextObject]){ + addkey(fieldString) + } + while(fieldString = [defFieldsE nextObject]){ + addkey(fieldString) + } + + //I don't enforce Keywords, but since there's GUI depending on them, I will enforce these others: + addkey(BDSKLocalUrlString) addkey(BDSKUrlString) addkey(BDSKAnnoteString) addkey(BDSKAbstractString) addkey(BDSKRssDescriptionString) + + // now remove everything that's left in remove keys from pubfields + [pubFields removeObjectsForKeys:removeKeys usingLock:bibLock]; + +} + +- (void)typeInfoDidChange:(NSNotification *)aNotification{ + [self makeType]; +} + +- (void)customFieldsDidChange:(NSNotification *)aNotification{ + [self makeType]; + [groups removeAllObjects]; +} + +#pragma mark Document + +- (BibDocument *)document { + return document; +} + +- (void)setDocument:(BibDocument *)newDocument { + if (document != newDocument) { + document = newDocument; + } +} + +- (NSUndoManager *)undoManager { // this may be nil + return [document undoManager]; +} + // accessors for fileorder - (NSNumber *)fileOrder{ if (document == nil) @@ -423,6 +442,7 @@ [bibLock unlock]; } +#pragma mark - #pragma mark Generic person handling code - (void)rebuildPeople{ @@ -706,6 +726,7 @@ return [BibAuthor emptyAuthor]; } +#pragma mark - #pragma mark Accessors - (BibItem *)crossrefParent{ @@ -779,6 +800,18 @@ return [title stringByRemovingTeX]; } +- (void)duplicateTitleToBooktitleOverwriting:(BOOL)overwrite{ + NSString *title = [pubFields objectForKey:BDSKTitleString usingLock:bibLock]; + + if([NSString isEmptyString:title]) + return; + + NSString *booktitle = [pubFields objectForKey:BDSKBooktitleString usingLock:bibLock]; + if(![NSString isEmptyString:booktitle] && !overwrite) + return; + [self setField:BDSKBooktitleString toValue:title]; +} + - (NSCalendarDate *)date{ return [self dateInheriting:YES]; } @@ -867,99 +900,56 @@ [self setRatingField:BDSKRatingString toValue:rating]; } -- (void)setRatingField:(NSString *)field toValue:(unsigned int)rating{ - if (rating > 5) - rating = 5; - [self setField:field toValue:[NSString stringWithFormat:@"%i", rating]]; +- (void)setHasBeenEdited:(BOOL)yn{ + //NSLog(@"set has been edited %@", (yn)?@"YES":@"NO"); + hasBeenEdited = yn; } -- (int)ratingValueOfField:(NSString *)field{ - return [[pubFields objectForKey:field usingLock:bibLock] intValue]; +- (BOOL)hasBeenEdited{ + return hasBeenEdited; } -- (BOOL)boolValueOfField:(NSString *)field{ - // stored as a string - return [(NSString *)[pubFields objectForKey:field usingLock:bibLock] booleanValue]; +- (void)setCiteKey:(NSString *)newCiteKey{ + [self setCiteKey:newCiteKey withModDate:[NSCalendarDate date]]; } -- (void)setBooleanField:(NSString *)field toValue:(BOOL)boolValue{ - [self setField:field toValue:[NSString stringWithBool:boolValue]]; -} - -- (NSCellStateValue)triStateValueOfField:(NSString *)field{ - return [(NSString *)[pubFields objectForKey:field usingLock:bibLock] triStateValue]; -} - -- (void)setTriStateField:(NSString *)field toValue:(NSCellStateValue)triStateValue{ - if(![[pubFields allKeysUsingLock:bibLock] containsObject:field]) - [self addField:field]; - [self setField:field toValue:[NSString stringWithTriStateValue:triStateValue]]; -} - -- (int)intValueOfField:(NSString *)field { - BibTypeManager *typeManager = [BibTypeManager sharedManager]; - - if([typeManager isRatingField:field]){ - return [self ratingValueOfField:field]; - }else if([typeManager isBooleanField:field]){ - return (int)[self boolValueOfField:field]; - }else if([typeManager isTriStateField:field]){ - return (int)[self triStateValueOfField:field]; - }else{ - return 0; +- (void)setCiteKey:(NSString *)newCiteKey withModDate:(NSCalendarDate *)date{ + if ([self undoManager]) { + [[[self undoManager] prepareWithInvocationTarget:self] setCiteKey:citeKey + withModDate:[self dateModified]]; } -} - -- (NSString *)valueOfGenericField:(NSString *)field { - return [self valueOfGenericField:field inherit:YES]; -} - -- (NSString *)valueOfGenericField:(NSString *)field inherit:(BOOL)inherit { - BibTypeManager *typeManager = [BibTypeManager sharedManager]; + NSString *oldCiteKey = [citeKey retain]; + + [self setCiteKeyString:newCiteKey]; + if (date != nil) { + [pubFields setObject:[date description] forKey:BDSKDateModifiedString usingLock:bibLock]; + } else { + [pubFields removeObjectForKey:BDSKDateModifiedString usingLock:bibLock]; + } + [self updateMetadataForKey:BDSKCiteKeyString]; - if([typeManager isRatingField:field]){ - return [NSString stringWithFormat:@"%i", [self ratingValueOfField:field]]; - }else if([typeManager isBooleanField:field]){ - return [NSString stringWithBool:[self boolValueOfField:field]]; - }else if([typeManager isTriStateField:field]){ - return [NSString stringWithTriStateValue:[self triStateValueOfField:field]]; - }else if([field isEqualToString:BDSKTypeString]){ - return [self type]; - }else if([field isEqualToString:BDSKCiteKeyString]){ - return [self citeKey]; - }else if([field isEqualToString:BDSKAllFieldsString]){ - return [self allFieldsString]; - }else{ - return [self valueOfField:field inherit:inherit]; - } -} + NSDictionary *notifInfo = [NSDictionary dictionaryWithObjectsAndKeys:citeKey, @"value", BDSKCiteKeyString, @"key", @"Change", @"type", document, @"document", oldCiteKey, @"oldCiteKey", nil]; -- (void)setGenericField:(NSString *)field toValue:(NSString *)value{ - OBASSERT([field isEqualToString:BDSKAllFieldsString] == NO); - BibTypeManager *typeManager = [BibTypeManager sharedManager]; - - if([typeManager isBooleanField:field]){ - [self setBooleanField:field toValue:[value booleanValue]]; - }else if([typeManager isTriStateField:field]){ - [self setTriStateField:field toValue:[value triStateValue]]; - }else if([typeManager isRatingField:field]){ - [self setRatingField:field toValue:[value intValue]]; - }else if([field isEqualToString:BDSKTypeString]){ - [self setType:value]; - }else if([field isEqualToString:BDSKCiteKeyString]){ - [self setCiteKey:value]; - }else{ - [self setField:field toValue:value]; - } + if(floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_3){} + else + [[NSFileManager defaultManager] removeSpotlightCacheForItemNamed:oldCiteKey]; + + [oldCiteKey release]; + [[NSNotificationCenter defaultCenter] postNotificationName:BDSKBibItemChangedNotification + object:self + userInfo:notifInfo]; } -- (void)setHasBeenEdited:(BOOL)yn{ - //NSLog(@"set has been edited %@", (yn)?@"YES":@"NO"); - hasBeenEdited = yn; +- (void)setCiteKeyString:(NSString *)newCiteKey{ + [bibLock lock]; + [citeKey autorelease]; + citeKey = [newCiteKey copy]; + [bibLock unlock]; + [[NSApp delegate] addString:newCiteKey forCompletionEntry:BDSKCrossrefString]; } -- (BOOL)hasBeenEdited{ - return hasBeenEdited; +- (NSString *)citeKey{ + return (citeKey != nil ? citeKey : @""); } - (NSString *)suggestedCiteKey @@ -998,47 +988,17 @@ return YES; } -- (void)setCiteKey:(NSString *)newCiteKey{ - [self setCiteKey:newCiteKey withModDate:[NSCalendarDate date]]; -} +#pragma mark Pub Fields -- (void)setCiteKey:(NSString *)newCiteKey withModDate:(NSCalendarDate *)date{ - if ([self undoManager]) { - [[[self undoManager] prepareWithInvocationTarget:self] setCiteKey:citeKey - withModDate:[self dateModified]]; - } - NSString *oldCiteKey = [citeKey retain]; - - [self setCiteKeyString:newCiteKey]; - if (date != nil) { - [pubFields setObject:[date description] forKey:BDSKDateModifiedString usingLock:bibLock]; - } else { - [pubFields removeObjectForKey:BDSKDateModifiedString usingLock:bibLock]; - } - [self updateMetadataForKey:BDSKCiteKeyString]; - - NSDictionary *notifInfo = [NSDictionary dictionaryWithObjectsAndKeys:citeKey, @"value", BDSKCiteKeyString, @"key", @"Change", @"type", document, @"document", oldCiteKey, @"oldCiteKey", nil]; - - if(floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_3){} - else - [[NSFileManager defaultManager] removeSpotlightCacheForItemNamed:oldCiteKey]; - - [oldCiteKey release]; - [[NSNotificationCenter defaultCenter] postNotificationName:BDSKBibItemChangedNotification - object:self - userInfo:notifInfo]; -} - -- (void)setCiteKeyString:(NSString *)newCiteKey{ +- (NSDictionary *)pubFields{ [bibLock lock]; - [citeKey autorelease]; - citeKey = [newCiteKey copy]; + NSDictionary *copy = [[pubFields copy] autorelease]; [bibLock unlock]; - [[NSApp delegate] addString:newCiteKey forCompletionEntry:BDSKCrossrefString]; + return copy; } -- (NSString *)citeKey{ - return (citeKey != nil ? citeKey : @""); +- (NSArray *)allFields{ + return [pubFields allKeysUsingLock:bibLock]; } - (void)setPubFields: (NSDictionary *)newFields{ @@ -1066,8 +1026,6 @@ } } -#pragma mark Key Value Coding - - (void)setField: (NSString *)key toValue: (NSString *)value{ [self setField:key toValue:value withModDate:[NSCalendarDate date]]; } @@ -1118,10 +1076,6 @@ [pubFields setObject:value forKey:key usingLock:bibLock]; } -- (id)valueForUndefinedKey:(NSString *)key{ - return [self valueOfGenericField:key]; -} - - (NSString *)valueOfField: (NSString *)key{ return [self valueOfField:key inherit:YES]; } @@ -1224,20 +1178,203 @@ } -- (NSDictionary *)pubFields{ - [bibLock lock]; - NSDictionary *copy = [[pubFields copy] autorelease]; - [bibLock unlock]; - return copy; +#pragma mark Derived field values + +- (id)valueForUndefinedKey:(NSString *)key{ + return [self valueOfGenericField:key]; } -- (NSArray *)allFields{ - return [pubFields allKeysUsingLock:bibLock]; +- (NSString *)valueOfGenericField:(NSString *)field { + return [self valueOfGenericField:field inherit:YES]; } +- (NSString *)valueOfGenericField:(NSString *)field inherit:(BOOL)inherit { + BibTypeManager *typeManager = [BibTypeManager sharedManager]; + + if([typeManager isRatingField:field]){ + return [NSString stringWithFormat:@"%i", [self ratingValueOfField:field]]; + }else if([typeManager isBooleanField:field]){ + return [NSString stringWithBool:[self boolValueOfField:field]]; + }else if([typeManager isTriStateField:field]){ + return [NSString stringWithTriStateValue:[self triStateValueOfField:field]]; + }else if([field isEqualToString:BDSKTypeString]){ + return [self type]; + }else if([field isEqualToString:BDSKCiteKeyString]){ + return [self citeKey]; + }else if([field isEqualToString:BDSKAllFieldsString]){ + return [self allFieldsString]; + }else{ + return [self valueOfField:field inherit:inherit]; + } +} + +- (void)setGenericField:(NSString *)field toValue:(NSString *)value{ + OBASSERT([field isEqualToString:BDSKAllFieldsString] == NO); + BibTypeManager *typeManager = [BibTypeManager sharedManager]; + + if([typeManager isBooleanField:field]){ + [self setBooleanField:field toValue:[value booleanValue]]; + }else if([typeManager isTriStateField:field]){ + [self setTriStateField:field toValue:[value triStateValue]]; + }else if([typeManager isRatingField:field]){ + [self setRatingField:field toValue:[value intValue]]; + }else if([field isEqualToString:BDSKTypeString]){ + [self setType:value]; + }else if([field isEqualToString:BDSKCiteKeyString]){ + [self setCiteKey:value]; + }else{ + [self setField:field toValue:value]; + } +} + +- (int)intValueOfField:(NSString *)field { + BibTypeManager *typeManager = [BibTypeManager sharedManager]; + + if([typeManager isRatingField:field]){ + return [self ratingValueOfField:field]; + }else if([typeManager isBooleanField:field]){ + return (int)[self boolValueOfField:field]; + }else if([typeManager isTriStateField:field]){ + return (int)[self triStateValueOfField:field]; + }else{ + return 0; + } +} + +- (int)ratingValueOfField:(NSString *)field{ + return [[pubFields objectForKey:field usingLock:bibLock] intValue]; +} + +- (void)setRatingField:(NSString *)field toValue:(unsigned int)rating{ + if (rating > 5) + rating = 5; + [self setField:field toValue:[NSString stringWithFormat:@"%i", rating]]; +} + +- (BOOL)boolValueOfField:(NSString *)field{ + // stored as a string + return [(NSString *)[pubFields objectForKey:field usingLock:bibLock] booleanValue]; +} + +- (void)setBooleanField:(NSString *)field toValue:(BOOL)boolValue{ + [self setField:field toValue:[NSString stringWithBool:boolValue]]; +} + +- (NSCellStateValue)triStateValueOfField:(NSString *)field{ + return [(NSString *)[pubFields objectForKey:field usingLock:bibLock] triStateValue]; +} + +- (void)setTriStateField:(NSString *)field toValue:(NSCellStateValue)triStateValue{ + if(![[pubFields allKeysUsingLock:bibLock] containsObject:field]) + [self addField:field]; + [self setField:field toValue:[NSString stringWithTriStateValue:triStateValue]]; +} + #pragma mark - -#pragma mark Text Representations +#pragma mark BibTeX strings +- (NSString *)bibTeXStringByExpandingMacros:(BOOL)expand dropInternal:(BOOL)drop texify:(BOOL)shouldTeXify{ + OFPreferenceWrapper *pw = [OFPreferenceWrapper sharedPreferenceWrapper]; + NSMutableSet *knownKeys = nil; + NSSet *urlKeys = nil; + NSString *field; + NSString *value; + NSMutableString *s = [[[NSMutableString alloc] init] autorelease]; + NSMutableArray *keys = [[pubFields allKeysUsingLock:bibLock] mutableCopy]; + NSEnumerator *e; + + BibTypeManager *btm = [BibTypeManager sharedManager]; + NSString *type = [self type]; + NSAssert1(type != nil, @"Tried to use a nil pubtype in %@. You will need to quit and relaunch BibDesk after fixing the error manually.", self ); + [keys sortUsingSelector:@selector(caseInsensitiveCompare:)]; + if ([pw boolForKey:BDSKSaveAnnoteAndAbstractAtEndOfItemKey]) { + NSArray *finalKeys = [[btm noteFieldsSet] allObjects]; + [keys removeObjectsInArray:finalKeys]; // make sure these fields are at the end, as they can be long + [keys addObjectsFromArray:finalKeys]; + } + if (drop) { + knownKeys = [[NSMutableSet alloc] initWithCapacity:14]; + [knownKeys addObjectsFromArray:[btm requiredFieldsForType:type]]; + [knownKeys addObjectsFromArray:[btm optionalFieldsForType:type]]; + [knownKeys addObject:BDSKCrossrefString]; + } + if(shouldTeXify) + urlKeys = [[BibTypeManager sharedManager] allURLFieldsSet]; + + e = [keys objectEnumerator]; + [keys release]; + + //build BibTeX entry: + [s appendString:@"@"]; + + [s appendString:type]; + [s appendString:@"{"]; + [s appendString:[self citeKey]]; + while(field = [e nextObject]){ + if (drop && ![knownKeys containsObject:field]) + continue; + + value = [pubFields objectForKey:field usingLock:bibLock]; + NSString *valString; + + if([field isEqualToString:BDSKAuthorString] && [pw boolForKey:BDSKShouldSaveNormalizedAuthorNamesKey] && ![value isComplex]){ // only if it's not complex, use the normalized author name + value = [self bibTeXAuthorStringNormalized:YES inherit:NO]; + } + + if(shouldTeXify && ![urlKeys containsObject:field]){ + + @try{ + value = [[BDSKConverter sharedConverter] stringByTeXifyingString:value]; + } + @catch(id localException){ + if([localException isKindOfClass:[NSException class]] && [[localException name] isEqualToString:BDSKTeXifyException]){ + // the exception from the converter has a description of the unichar that couldn't convert; we add some useful context to it, then rethrow + NSException *exception = [NSException exceptionWithName:BDSKTeXifyException reason:[NSString stringWithFormat: NSLocalizedString(@"Character \"%@\" in the %@ of %@ can't be converted to TeX.", @"character conversion warning"), [localException reason], field, [self citeKey]] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:self, @"item", field, @"field", nil]]; + @throw exception; + } else @throw; + } + } + + if(expand == YES) + valString = [value stringAsExpandedBibTeXString]; + else + valString = [value stringAsBibTeXString]; + + if(![value isEqualToString:@""]){ + [s appendString:@",\n\t"]; + [s appendString:field]; + [s appendString:@" = "]; + [s appendString:valString]; + } + } + [s appendString:@"}"]; + [knownKeys release]; + return s; +} + +- (NSString *)bibTeXStringByExpandingMacros:(BOOL)expand dropInternal:(BOOL)drop{ + BOOL shouldTeXify = [[OFPreferenceWrapper sharedPreferenceWrapper] boolForKey:BDSKShouldTeXifyWhenSavingAndCopyingKey]; + return [self bibTeXStringByExpandingMacros:expand dropInternal:drop texify:shouldTeXify]; +} + +- (NSString *)bibTeXString{ + return [self bibTeXStringByExpandingMacros:NO dropInternal:NO]; +} + +- (NSString *)bibTeXStringDroppingInternal:(BOOL)drop{ + return [self bibTeXStringByExpandingMacros:NO dropInternal:drop]; +} + +- (NSString *)bibTeXStringByExpandingMacros{ + return [self bibTeXStringByExpandingMacros:YES dropInternal:NO]; +} + +- (NSString *)bibTeXStringUnexpandedAndDeTeXifiedWithoutInternalFields{ + return [self bibTeXStringByExpandingMacros:NO dropInternal:YES texify:NO]; +} + +#pragma mark Other text representations + - (NSData *)RTFValue{ NSAttributedString *aStr = [self attributedStringValue]; return [aStr RTFFromRange:NSMakeRange(0,[aStr length]) documentAttributes:nil]; @@ -1501,108 +1638,6 @@ return s; } -#pragma mark BibTeX strings - -- (NSString *)bibTeXStringByExpandingMacros:(BOOL)expand dropInternal:(BOOL)drop texify:(BOOL)shouldTeXify{ - OFPreferenceWrapper *pw = [OFPreferenceWrapper sharedPreferenceWrapper]; - NSMutableSet *knownKeys = nil; - NSSet *urlKeys = nil; - NSString *field; - NSString *value; - NSMutableString *s = [[[NSMutableString alloc] init] autorelease]; - NSMutableArray *keys = [[pubFields allKeysUsingLock:bibLock] mutableCopy]; - NSEnumerator *e; - - BibTypeManager *btm = [BibTypeManager sharedManager]; - NSString *type = [self type]; - NSAssert1(type != nil, @"Tried to use a nil pubtype in %@. You will need to quit and relaunch BibDesk after fixing the error manually.", self ); - [keys sortUsingSelector:@selector(caseInsensitiveCompare:)]; - if ([pw boolForKey:BDSKSaveAnnoteAndAbstractAtEndOfItemKey]) { - NSArray *finalKeys = [[btm noteFieldsSet] allObjects]; - [keys removeObjectsInArray:finalKeys]; // make sure these fields are at the end, as they can be long - [keys addObjectsFromArray:finalKeys]; - } - if (drop) { - knownKeys = [[NSMutableSet alloc] initWithCapacity:14]; - [knownKeys addObjectsFromArray:[btm requiredFieldsForType:type]]; - [knownKeys addObjectsFromArray:[btm optionalFieldsForType:type]]; - [knownKeys addObject:BDSKCrossrefString]; - } - if(shouldTeXify) - urlKeys = [[BibTypeManager sharedManager] allURLFieldsSet]; - - e = [keys objectEnumerator]; - [keys release]; - - //build BibTeX entry: - [s appendString:@"@"]; - - [s appendString:type]; - [s appendString:@"{"]; - [s appendString:[self citeKey]]; - while(field = [e nextObject]){ - if (drop && ![knownKeys containsObject:field]) - continue; - - value = [pubFields objectForKey:field usingLock:bibLock]; - NSString *valString; - - if([field isEqualToString:BDSKAuthorString] && [pw boolForKey:BDSKShouldSaveNormalizedAuthorNamesKey] && ![value isComplex]){ // only if it's not complex, use the normalized author name - value = [self bibTeXAuthorStringNormalized:YES inherit:NO]; - } - - if(shouldTeXify && ![urlKeys containsObject:field]){ - - @try{ - value = [[BDSKConverter sharedConverter] stringByTeXifyingString:value]; - } - @catch(id localException){ - if([localException isKindOfClass:[NSException class]] && [[localException name] isEqualToString:BDSKTeXifyException]){ - // the exception from the converter has a description of the unichar that couldn't convert; we add some useful context to it, then rethrow - NSException *exception = [NSException exceptionWithName:BDSKTeXifyException reason:[NSString stringWithFormat: NSLocalizedString(@"Character \"%@\" in the %@ of %@ can't be converted to TeX.", @"character conversion warning"), [localException reason], field, [self citeKey]] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:self, @"item", field, @"field", nil]]; - @throw exception; - } else @throw; - } - } - - if(expand == YES) - valString = [value stringAsExpandedBibTeXString]; - else - valString = [value stringAsBibTeXString]; - - if(![value isEqualToString:@""]){ - [s appendString:@",\n\t"]; - [s appendString:field]; - [s appendString:@" = "]; - [s appendString:valString]; - } - } - [s appendString:@"}"]; - [knownKeys release]; - return s; -} - -- (NSString *)bibTeXStringByExpandingMacros:(BOOL)expand dropInternal:(BOOL)drop{ - BOOL shouldTeXify = [[OFPreferenceWrapper sharedPreferenceWrapper] boolForKey:BDSKShouldTeXifyWhenSavingAndCopyingKey]; - return [self bibTeXStringByExpandingMacros:expand dropInternal:drop texify:shouldTeXify]; -} - -- (NSString *)bibTeXString{ - return [self bibTeXStringByExpandingMacros:NO dropInternal:NO]; -} - -- (NSString *)bibTeXStringDroppingInternal:(BOOL)drop{ - return [self bibTeXStringByExpandingMacros:NO dropInternal:drop]; -} - -- (NSString *)bibTeXStringByExpandingMacros{ - return [self bibTeXStringByExpandingMacros:YES dropInternal:NO]; -} - -- (NSString *)bibTeXStringUnexpandedAndDeTeXifiedWithoutInternalFields{ - return [self bibTeXStringByExpandingMacros:NO dropInternal:YES texify:NO]; -} - #define AddXMLField(t,f) value = [self valueOfField:f]; if ([NSString isEmptyString:value] == NO) [s appendFormat:@"<%@>%@</%@>\n", t, [value stringByEscapingBasicXMLEntitiesUsingUTF8], t] - (NSString *)MODSString{ @@ -2059,27 +2094,9 @@ return NO; } -- (void)typeInfoDidChange:(NSNotification *)aNotification{ - [self makeType]; -} +#pragma mark - +#pragma mark Groups -- (void)customFieldsDidChange:(NSNotification *)aNotification{ - [self makeType]; - [groups removeAllObjects]; -} - -- (void)duplicateTitleToBooktitleOverwriting:(BOOL)overwrite{ - NSString *title = [pubFields objectForKey:BDSKTitleString usingLock:bibLock]; - - if([NSString isEmptyString:title]) - return; - - NSString *booktitle = [pubFields objectForKey:BDSKBooktitleString usingLock:bibLock]; - if(![NSString isEmptyString:booktitle] && !overwrite) - return; - [self setField:BDSKBooktitleString toValue:title]; -} - - (NSSet *)groupsForField:(NSString *)field{ // first see if we had it cached NSSet *groupSet = [groups objectForKey:field]; @@ -2436,11 +2453,11 @@ - (void)invalidateGroupNames{ [groups removeAllObjects]; } - -- (id)stringCache { return stringCache; } @end +#pragma mark - + @implementation BibItem (PDFMetadata) + (BibItem *)itemWithPDFMetadata:(PDFMetadata *)metadata; @@ -2481,6 +2498,8 @@ @end +#pragma mark - + @implementation BibItem (Private) // The date setters should only be used at initialization or from updateMetadata:forKey:. If you want to change the date, change the value in pubFields, and let updateMetadata handle the ivar. @@ -2510,6 +2529,8 @@ [bibLock unlock]; } +- (id)stringCache { return stringCache; } + - (void)updateMetadataForKey:(NSString *)key{ [self setHasBeenEdited:YES]; @@ -2594,6 +2615,7 @@ @end +#pragma mark - @implementation BDSKBibItemStringCache This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |