Revision: 21507 http://sourceforge.net/p/bibdesk/svn/21507 Author: hofman Date: 2017-08-08 12:29:48 +0000 (Tue, 08 Aug 2017) Log Message: ----------- Don't assume there was no crossers chain before when checking for changing crossers and cite key. Separate check methods for crossers and cite key.
Modified Paths: -------------- trunk/bibdesk/BDSKEditor.m trunk/bibdesk/BDSKPublicationsArray.h trunk/bibdesk/BDSKPublicationsArray.m trunk/bibdesk/BibItem.h trunk/bibdesk/BibItem.m Modified: trunk/bibdesk/BDSKEditor.m =================================================================== --- trunk/bibdesk/BDSKEditor.m 2017-08-08 06:31:42 UTC (rev 21506) +++ trunk/bibdesk/BDSKEditor.m 2017-08-08 12:29:48 UTC (rev 21507) @@ -2073,7 +2073,7 @@ NSString *message = nil; // check whether we won't get a crossref chain - NSInteger errorCode = [publication canSetCrossref:value andCiteKey:[publication citeKey]]; + NSInteger errorCode = [publication canSetCrossref:value]; if (errorCode == BDSKSelfCrossrefError) message = NSLocalizedString(@"An item cannot cross reference to itself.", @"Informative text in alert dialog"); else if (errorCode == BDSKChainCrossrefError) @@ -2109,7 +2109,7 @@ } else { // check whether we won't crossref to the new citekey - NSInteger errorCode = [publication canSetCrossref:[publication valueOfField:BDSKCrossrefString inherit:NO] andCiteKey:[control stringValue]]; + NSInteger errorCode = [publication canSetCiteKey:[control stringValue]]; if (errorCode == BDSKSelfCrossrefError) message = NSLocalizedString(@"An item cannot cross reference to itself.", @"Informative text in alert dialog"); else if (errorCode != BDSKNoCrossrefError) // shouldn't happen @@ -2759,7 +2759,7 @@ NSString *message = nil; // first check if we don't create a Crossref chain - NSInteger errorCode = [publication canSetCrossref:crossref andCiteKey:[publication citeKey]]; + NSInteger errorCode = [publication canSetCrossref:crossref]; if (errorCode == BDSKSelfCrossrefError) message = NSLocalizedString(@"An item cannot cross reference to itself.", @"Informative text in alert dialog"); else if (errorCode == BDSKChainCrossrefError) @@ -2802,7 +2802,7 @@ if(shouldOverwrite || [NSString isEmptyString:oldValue]){ // if it's a crossref we should check if we don't create a crossref chain, otherwise we ignore if([key isEqualToString:BDSKCrossrefString] && - [publication canSetCrossref:newValue andCiteKey:[publication citeKey]] != BDSKNoCrossrefError) + [publication canSetCrossref:newValue] != BDSKNoCrossrefError) continue; if ([key hasPrefix:@"Bdsk-File-"]) { BDSKLinkedFile *aFile = [[BDSKLinkedFile alloc] initWithBase64String:newValue delegate:publication]; @@ -2825,7 +2825,7 @@ // check cite key here in case we didn't autogenerate, or we're supposed to overwrite if((shouldOverwrite || [publication hasEmptyOrDefaultCiteKey]) && [tempBI hasEmptyOrDefaultCiteKey] == NO && hasTemporaryCiteKey == NO && - [publication canSetCrossref:[publication valueOfField:BDSKCrossrefString inherit:NO] andCiteKey:[tempBI citeKey]] == BDSKNoCrossrefError) { + [publication canSetCiteKey:[tempBI citeKey]] == BDSKNoCrossrefError) { oldValue = [[[publication citeKey] retain] autorelease]; newValue = [tempBI citeKey]; [publication setCiteKey:newValue]; @@ -3073,7 +3073,7 @@ return NO; // first check if we don't create a Crossref chain - NSInteger errorCode = [publication canSetCrossref:crossref andCiteKey:[publication citeKey]]; + NSInteger errorCode = [publication canSetCrossref:crossref]; NSString *message = nil; if (errorCode == BDSKSelfCrossrefError) message = NSLocalizedString(@"An item cannot cross reference to itself.", @"Informative text in alert dialog"); Modified: trunk/bibdesk/BDSKPublicationsArray.h =================================================================== --- trunk/bibdesk/BDSKPublicationsArray.h 2017-08-08 06:31:42 UTC (rev 21506) +++ trunk/bibdesk/BDSKPublicationsArray.h 2017-08-08 12:29:48 UTC (rev 21507) @@ -53,7 +53,7 @@ - (BOOL)citeKeyIsUsed:(NSString *)key byItemOtherThan:(BibItem *)anItem; - (void)changeCiteKey:(NSString *)oldKey toCiteKey:(NSString *)newKey forItem:(BibItem *)anItem; -- (BOOL)citeKeyIsCrossreffed:(NSString *)key; +- (BOOL)citeKeyIsCrossreffed:(NSString *)key byItemOtherThan:(BibItem *)item; - (id)itemForIdentifierURL:(NSURL *)aURL; - (NSArray *)itemsForIdentifierURLs:(NSArray *)anArray; - (NSArray *)itemsForAuthor:(BibAuthor *)anAuthor; Modified: trunk/bibdesk/BDSKPublicationsArray.m =================================================================== --- trunk/bibdesk/BDSKPublicationsArray.m 2017-08-08 06:31:42 UTC (rev 21506) +++ trunk/bibdesk/BDSKPublicationsArray.m 2017-08-08 12:29:48 UTC (rev 21507) @@ -260,13 +260,13 @@ #pragma mark Crossref support -- (BOOL)citeKeyIsCrossreffed:(NSString *)key; +- (BOOL)citeKeyIsCrossreffed:(NSString *)key byItemOtherThan:(BibItem *)item; { if ([NSString isEmptyString:key]) return NO; for (BibItem *pub in publications) { - if ([key isCaseInsensitiveEqual:[pub valueOfField:BDSKCrossrefString inherit:NO]]) { + if (pub != item && [key isCaseInsensitiveEqual:[pub valueOfField:BDSKCrossrefString inherit:NO]]) { return YES; } } Modified: trunk/bibdesk/BibItem.h =================================================================== --- trunk/bibdesk/BibItem.h 2017-08-08 06:31:42 UTC (rev 21506) +++ trunk/bibdesk/BibItem.h 2017-08-08 12:29:48 UTC (rev 21507) @@ -605,13 +605,21 @@ - (BOOL)canGenerateAndSetCiteKey; /* - @method canSetCrossref:andCiteKey: - @abstract Returns an integer error code indicating whether the combination of crossref and citekey would lead to a crossref chain - @discussion - - @result 0: no problem, 1: crossref to self, 2: crossref to item with crossref, 3: self is crossreffed -*/ -- (NSInteger)canSetCrossref:(NSString *)aCrossref andCiteKey:(NSString *)aCiteKey; + @method canSetCrossref: + @abstract Returns an integer error code indicating whether the combination of the current crossref and citekey would lead to a crossref chain + @discussion - + @result 0: no problem, 1: crossref to self, 2: crossref to item with crossref, 3: self is crossreffed + */ +- (NSInteger)canSetCrossref:(NSString *)aCrossref; +/* + @method canSetCiteKey: + @abstract Returns an integer error code indicating whether the combination of crossref and the current citekey would lead to a crossref chain + @discussion - + @result 0: no problem, 1: crossref to self, 2: crossref to item with crossref, 3: self is crossreffed + */ +- (NSInteger)canSetCiteKey:(NSString *)aCiteKey; + /*! @method setCiteKey: @abstract basic setter for the cite key, with notification and undo and current modified date. Modified: trunk/bibdesk/BibItem.m =================================================================== --- trunk/bibdesk/BibItem.m 2017-08-08 06:31:42 UTC (rev 21506) +++ trunk/bibdesk/BibItem.m 2017-08-08 12:29:48 UTC (rev 21507) @@ -1118,14 +1118,27 @@ return ([[owner publications] citeKeyIsUsed:proposedCiteKey byItemOtherThan:self] == NO); } -- (NSInteger)canSetCrossref:(NSString *)aCrossref andCiteKey:(NSString *)aCiteKey{ +- (NSInteger)canSetCrossref:(NSString *)aCrossref{ NSInteger errorCode = BDSKNoCrossrefError; if ([NSString isEmptyString:aCrossref] == NO) { + NSString *aCiteKey = [self citeKey]; if ([aCiteKey isCaseInsensitiveEqual:aCrossref]) errorCode = BDSKSelfCrossrefError; + else if ([[owner publications] citeKeyIsCrossreffed:aCiteKey byItemOtherThan:self]) + errorCode = BDSKIsCrossreffedCrossrefError; + } + return errorCode; +} + +- (NSInteger)canSetCiteKey:(NSString *)aCiteKey{ + NSInteger errorCode = BDSKNoCrossrefError; + NSString *aCrossref = [self valueOfField:BDSKCrossrefString inherit:NO]; + if ([NSString isEmptyString:aCrossref] == NO) { + if ([aCiteKey isCaseInsensitiveEqual:aCrossref]) + errorCode = BDSKSelfCrossrefError; else if ([NSString isEmptyString:[[[owner publications] itemForCiteKey:aCrossref] valueOfField:BDSKCrossrefString inherit:NO]] == NO) errorCode = BDSKChainCrossrefError; - else if ([[owner publications] citeKeyIsCrossreffed:aCiteKey]) + else if ([[owner publications] citeKeyIsCrossreffed:aCiteKey byItemOtherThan:self]) errorCode = BDSKIsCrossreffedCrossrefError; } return errorCode; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit