Revision: 28995 http://sourceforge.net/p/bibdesk/svn/28995 Author: hofman Date: 2025-02-07 10:23:39 +0000 (Fri, 07 Feb 2025) Log Message: ----------- static instance of groupKeys set
Modified Paths: -------------- trunk/bibdesk/BibDocument+Scripting.m Modified: trunk/bibdesk/BibDocument+Scripting.m =================================================================== --- trunk/bibdesk/BibDocument+Scripting.m 2025-02-07 10:03:46 UTC (rev 28994) +++ trunk/bibdesk/BibDocument+Scripting.m 2025-02-07 10:23:39 UTC (rev 28995) @@ -703,14 +703,20 @@ #pragma mark - +static NSSet *groupKeys() { + static NSSet *groupKeys = nil; + if (groupKeys == nil) + groupKeys = [NSSet setWithObjects:@"groups", @"staticGroups", @"smartGroups", @"fieldGroups", @"externalFileGroups", @"scriptGroups", @"searchGroups", @"sharedGroups", @"libraryGroups", @"lastImportGroups", @"webGroups", nil]; + return groupKeys; +} + // The following "indicesOf..." methods are in support of scripting. They allow more flexible range and relative specifiers to be used with the different group keys of a SKTDrawDocument. // The scripting engine does not know about the fact that the "static groups" key is really just a subset of the "groups" key, so script code like "groups from static group 1 to field group 4" don't make sense to it. But BibDesk does know and can answer such questions itself, with a little work. // This is copied from Apple's Sketch sample code - (NSArray *)indicesOfObjectsByEvaluatingRangeSpecifier:(NSRangeSpecifier *)rangeSpec { NSString *key = [rangeSpec key]; - NSSet *groupKeys = [NSSet setWithObjects:@"groups", @"staticGroups", @"smartGroups", @"fieldGroups", @"externalFileGroups", @"scriptGroups", @"searchGroups", @"sharedGroups", @"libraryGroups", @"lastImportGroups", @"webGroups", nil]; - - if ([groupKeys containsObject:key]) { + + if ([groupKeys() containsObject:key]) { // This is one of the keys we might want to deal with. NSScriptObjectSpecifier *startSpec = [rangeSpec startSpecifier]; NSScriptObjectSpecifier *endSpec = [rangeSpec endSpecifier]; @@ -726,7 +732,7 @@ // If there are no groups, there can be no match. Just return now. return @[]; - if ((startSpec == nil || [groupKeys containsObject:startKey]) && (endSpec == nil || [groupKeys containsObject:endKey])) { + if ((startSpec == nil || [groupKeys() containsObject:startKey]) && (endSpec == nil || [groupKeys() containsObject:endKey])) { NSInteger startIndex; NSInteger endIndex; @@ -807,9 +813,8 @@ - (NSArray *)indicesOfObjectsByEvaluatingRelativeSpecifier:(NSRelativeSpecifier *)relSpec { NSString *key = [relSpec key]; - NSSet *groupKeys = [NSSet setWithObjects:@"groups", @"staticGroups", @"smartGroups", @"fieldGroups", @"externalFileGroups", @"scriptGroups", @"searchGroups", @"sharedGroups", @"libraryGroups", @"lastImportGroups", @"webGroups", nil]; - - if ([groupKeys containsObject:key]) { + + if ([groupKeys() containsObject:key]) { // This is one of the keys we might want to deal with. NSScriptObjectSpecifier *baseSpec = [relSpec baseSpecifier]; NSString *baseKey = [baseSpec key]; @@ -824,7 +829,7 @@ // If there are no groups, there can be no match. Just return now. return @[]; - if ([groupKeys containsObject:baseKey]) { + if ([groupKeys() containsObject:baseKey]) { NSInteger baseIndex; // The base key is also one we want to handle. 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