Revision: 29082 http://sourceforge.net/p/bibdesk/svn/29082 Author: hofman Date: 2025-03-01 15:09:57 +0000 (Sat, 01 Mar 2025) Log Message: ----------- Set evaluation errors when failing to evaluate group specifiers
Modified Paths: -------------- trunk/bibdesk/BibDocument+Scripting.m Modified: trunk/bibdesk/BibDocument+Scripting.m =================================================================== --- trunk/bibdesk/BibDocument+Scripting.m 2025-02-28 14:43:51 UTC (rev 29081) +++ trunk/bibdesk/BibDocument+Scripting.m 2025-03-01 15:09:57 UTC (rev 29082) @@ -722,15 +722,15 @@ if ((startSpec == nil) && (endSpec == nil)) // We need to have at least one of these... - return nil; + return [super scriptingValueForSpecifier:rangeSpec]; if ([startSpec containerSpecifier] == nil && [startKey isEqualToString:key] && [endSpec containerSpecifier] == nil && [endKey isEqualToString:key]) // Just an ordinary range of (a type of) groups. Let the scripting engine handle this. - return nil; + return [super scriptingValueForSpecifier:rangeSpec]; if ((startSpec && [groupKeys() containsObject:startKey] == NO) || (endSpec && [groupKeys() containsObject:endKey]) == NO) // The start or end key is not a group key. - return nil; + return [super scriptingValueForSpecifier:rangeSpec]; NSArray *allGroups = [self scriptingGroups]; BOOL keyIsGroups = [key isEqual:@"scriptingGroups"]; @@ -754,14 +754,19 @@ object = [startSpec objectsByEvaluatingWithContainers:self]; if ([object isKindOfClass:[NSArray class]]) object = [object firstObject]; - if (object == nil) + if (object == nil) { // Oops. We could not find the start object. + if ([startSpec evaluationErrorNumber] == NSNoSpecifierError) + [rangeSpec setEvaluationErrorNumber:NSInvalidIndexSpecifierError]; return nil; + } startIndex = [allGroups indexOfObjectIdenticalTo:object]; - if (startIndex == NSNotFound) + if (startIndex == NSNotFound) { // Oops. We couldn't find the start object in the groups array. This should not happen. + [rangeSpec setEvaluationErrorNumber:NSInternalSpecifierError]; return nil; + } } else { startIndex = 0; } @@ -771,14 +776,19 @@ object = [endSpec objectsByEvaluatingWithContainers:self]; if ([object isKindOfClass:[NSArray class]]) object = [object lastObject]; - if (object == nil) + if (object == nil) { // Oops. We could not find the end object. + if ([endSpec evaluationErrorNumber] == NSNoSpecifierError) + [rangeSpec setEvaluationErrorNumber:NSInvalidIndexSpecifierError]; return nil; + } endIndex = [allGroups indexOfObjectIdenticalTo:object]; - if (endIndex == NSNotFound) + if (endIndex == NSNotFound) { // Oops. We couldn't find the end object in the groups array. This should not happen. + [rangeSpec setEvaluationErrorNumber:NSInternalSpecifierError]; return nil; + } } else { endIndex = [allGroups count] - 1; } @@ -795,9 +805,11 @@ // Restrict to the requested group range NSUInteger rangeStartIndex = [allGroups indexOfObjectIdenticalTo:[rangeKeyObjects firstObject]]; NSUInteger rangeEndIndex = [allGroups indexOfObjectIdenticalTo:[rangeKeyObjects lastObject]]; - if (rangeStartIndex == NSNotFound || rangeEndIndex == NSNotFound) + if (rangeStartIndex == NSNotFound || rangeEndIndex == NSNotFound) { // Oops. We couldn't find the range objects in the groups array. This should not happen. + [rangeSpec setEvaluationErrorNumber:NSInternalSpecifierError]; return nil; + } if (startIndex > rangeEndIndex || endIndex < rangeStartIndex) // The requested range does not include any of the requested type of groups. return @[]; @@ -818,15 +830,15 @@ if (baseSpec == nil) // We need to have one of these... - return nil; + return [super scriptingValueForSpecifier:relSpec]; if ([allGroups count] == 0) // If there are no groups, there can be no match. Just return now. - return [NSNull null]; + return nil; if ([groupKeys() containsObject:baseKey] == NO) // The base key is not a group key. - return nil; + return [super scriptingValueForSpecifier:relSpec]; NSInteger baseIndex; @@ -837,14 +849,19 @@ id baseObject = [baseSpec objectsByEvaluatingWithContainers:self]; if ([baseObject isKindOfClass:[NSArray class]]) baseObject = (isBefore ? [baseObject firstObject] : [baseObject lastObject]); - if (baseObject == nil) + if (baseObject == nil) { // Oops. We could not find the base object. + if ([baseSpec evaluationErrorNumber] != NSNoSpecifierError) + [relSpec setEvaluationErrorNumber:NSInvalidIndexSpecifierError]; return nil; + } baseIndex = [allGroups indexOfObjectIdenticalTo:baseObject]; - if (baseIndex == NSNotFound) + if (baseIndex == NSNotFound) { // Oops. We couldn't find the base object in the groups array. This should not happen. + [relSpec setEvaluationErrorNumber:NSInternalSpecifierError]; return nil; + } // Now baseIndex specifies the base object for the relative spec in the groups array. // We will start either right before or right after and look for an object that matches the type we want. @@ -859,7 +876,7 @@ return curObj; } - return [NSNull null]; + return nil; } - (id)scriptingValueForSpecifier:(NSScriptObjectSpecifier *)specifier { @@ -866,13 +883,12 @@ // We want to handle some range and relative specifiers ourselves in order to support such things as "groups from static group 3 to static group 5" or "static groups from groups 7 to groups 10" or "static group before smart group 1". // Returning nil from this method will cause the specifier to try to evaluate itself using its default evaluation strategy. - id result = nil; if ([specifier isKindOfClass:[NSRangeSpecifier class]] && [groupKeys() containsObject:[specifier key]]) - result = [self scriptingValueForGroupRangeSpecifier:(NSRangeSpecifier *)specifier]; + return [self scriptingValueForGroupRangeSpecifier:(NSRangeSpecifier *)specifier]; else if ([specifier isKindOfClass:[NSRelativeSpecifier class]] && [groupKeys() containsObject:[specifier key]]) - result = [self scriptingValueForGroupRelativeSpecifier:(NSRelativeSpecifier *)specifier]; + return [self scriptingValueForGroupRelativeSpecifier:(NSRelativeSpecifier *)specifier]; - return result == [NSNull null] ? nil : (result ?: [super scriptingValueForSpecifier:specifier]); + return [super scriptingValueForSpecifier:specifier]; } #pragma mark Commands This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit