Revision: 29806
          http://sourceforge.net/p/bibdesk/svn/29806
Author:   hofman
Date:     2025-11-14 17:46:50 +0000 (Fri, 14 Nov 2025)
Log Message:
-----------
set macroResolver used for decoded complex strings in keyed unarchiver subclass

Modified Paths:
--------------
    trunk/bibdesk/BDSKComplexString.h
    trunk/bibdesk/BDSKComplexString.m
    trunk/bibdesk/BDSKSharedGroup.m
    trunk/bibdesk/BibItem.m

Modified: trunk/bibdesk/BDSKComplexString.h
===================================================================
--- trunk/bibdesk/BDSKComplexString.h   2025-11-14 17:25:11 UTC (rev 29805)
+++ trunk/bibdesk/BDSKComplexString.h   2025-11-14 17:46:50 UTC (rev 29806)
@@ -47,8 +47,6 @@
 
 @interface NSString (BDSKComplexStringExtensions)
 
-@property (class, nonatomic, nullable, strong) BDSKMacroResolver 
*macroResolverForUnarchiving;
-
 + (BOOL)isEmptyAsComplexString:(nullable NSString *)aString;
 
 /*!
@@ -191,4 +189,18 @@
 
 @end
 
+#pragma mark -
+
+@interface NSCoder (BDSKComplexString)
+// macroResolver used for decoded complex strings, nil by default
+@property (nonatomic, nullable, readonly) BDSKMacroResolver *macroResolver;
+@end
+
+// unarchiver that allows setting a macroResolver used for decoded complex 
strings
+@interface BDSKKeyedUnarchiver : NSKeyedUnarchiver {
+    BDSKMacroResolver *macroResolver;
+}
+@property (nonatomic, nullable, retain) BDSKMacroResolver *macroResolver;
+@end
+
 NS_ASSUME_NONNULL_END

Modified: trunk/bibdesk/BDSKComplexString.m
===================================================================
--- trunk/bibdesk/BDSKComplexString.m   2025-11-14 17:25:11 UTC (rev 29805)
+++ trunk/bibdesk/BDSKComplexString.m   2025-11-14 17:46:50 UTC (rev 29806)
@@ -44,8 +44,6 @@
 static NSCharacterSet *macroCharSet = nil;
 static Class BDSKComplexStringClass = Nil;
 
-static BDSKMacroResolver *macroResolverForUnarchiving = nil;
-
 /* BDSKComplexString is a string that may be a concatenation of strings, 
     some of which are macros.
    It's a concrete subclass of NSString, which means it can be used 
@@ -370,7 +368,7 @@
             nodes = [coder decodeObjectOfClasses:[NSSet 
setWithObjects:[NSArray class], [BDSKStringNode class], nil] forKey:@"nodes"];
             isComplex = [coder decodeBoolForKey:@"complex"];
             isInherited = [coder decodeBoolForKey:@"inherited"];
-            macroResolver = [[self class] macroResolverForUnarchiving];
+            macroResolver = [coder macroResolver];
             expandedString = nil;
             modification = 0;
             defaultModification = 0;
@@ -731,16 +729,6 @@
 
 @implementation NSString (BDSKComplexStringExtensions)
 
-+ (BDSKMacroResolver *)macroResolverForUnarchiving{
-    return macroResolverForUnarchiving;
-}
-
-+ (void)setMacroResolverForUnarchiving:(BDSKMacroResolver *)aMacroResolver{
-    if (macroResolverForUnarchiving != aMacroResolver) {
-        macroResolverForUnarchiving = aMacroResolver;
-    }
-}
-
 - (instancetype)initWithNodes:(NSArray *)nodesArray 
macroResolver:(BDSKMacroResolver *)aMacroResolver{
     if ([nodesArray count] == 1 && [(BDSKStringNode *)[nodesArray 
objectAtIndex:0] type] == BDSKStringNodeString) {
         self = [self initWithString:[(BDSKStringNode *)[nodesArray 
objectAtIndex:0] value]];
@@ -926,3 +914,13 @@
 }
 
 @end
+
+#pragma mark -
+ 
+@implementation NSCoder (BDSKComplexString)
+- (BDSKMacroResolver *)macroResolver { return nil; }
+@end
+
+@implementation BDSKKeyedUnarchiver
+@synthesize macroResolver;
+@end

Modified: trunk/bibdesk/BDSKSharedGroup.m
===================================================================
--- trunk/bibdesk/BDSKSharedGroup.m     2025-11-14 17:25:11 UTC (rev 29805)
+++ trunk/bibdesk/BDSKSharedGroup.m     2025-11-14 17:46:50 UTC (rev 29806)
@@ -176,11 +176,17 @@
     NSArray *pubs = nil;
     NSMapTable *macros = nil;
     
-    [NSString setMacroResolverForUnarchiving:[self macroResolver]];
-    if (pubsArchive)
-        pubs = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet 
setWithObjects:[NSArray class], [BibItem class], nil] fromData:pubsArchive 
error:NULL];
+    if (pubsArchive) {
+        BDSKKeyedUnarchiver *unarchiver = [[BDSKKeyedUnarchiver alloc] 
initForReadingFromData:pubsArchive error:NULL];
+        [unarchiver setMacroResolver:[self macroResolver]];
+        pubs = [unarchiver decodeObjectOfClasses:[NSSet 
setWithObjects:[NSArray class], [BibItem class], nil] 
forKey:NSKeyedArchiveRootObjectKey];
+        [unarchiver finishDecoding];
+    }
     if (macrosArchive) {
-        NSDictionary *dict = [NSKeyedUnarchiver 
unarchivedObjectOfClasses:[NSSet setWithObjects:[NSDictionary class], [NSString 
class], nil] fromData:macrosArchive error:NULL];
+        BDSKKeyedUnarchiver *unarchiver = [[BDSKKeyedUnarchiver alloc] 
initForReadingFromData:pubsArchive error:NULL];
+        [unarchiver setMacroResolver:[self macroResolver]];
+        NSDictionary *dict = [unarchiver decodeObjectOfClasses:[NSSet 
setWithObjects:[NSDictionary class], [NSString class], nil] 
forKey:NSKeyedArchiveRootObjectKey];
+        [unarchiver finishDecoding];
         if (dict) {
             macros = [[NSMapTable alloc] 
initWithKeyPointerFunctions:[NSPointerFunctions 
caseInsensitiveStringPointerFunctions] 
valuePointerFunctions:[NSPointerFunctions strongObjectPointerFunctions] 
capacity:0];
             [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString 
*value, BOOL *stop){
@@ -188,7 +194,6 @@
             }];
         }
     }
-    [NSString setMacroResolverForUnarchiving:nil];
     
     // we set the macroResolver so we know the fields of this item may refer 
to it, so we can prevent scripting from adding this to the wrong document
     [pubs setValue:macroResolver forKey:@"macroResolver"];

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2025-11-14 17:25:11 UTC (rev 29805)
+++ trunk/bibdesk/BibItem.m     2025-11-14 17:46:50 UTC (rev 29806)
@@ -492,16 +492,14 @@
 
 + (NSArray *)publicationsFromPasteboard:(NSPasteboard *)pboard 
macroResolver:(BDSKMacroResolver *)aMacroResolver {
     NSData *data = [pboard dataForType:BDSKPasteboardTypePublications];
-    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] 
initForReadingFromData:data error:NULL];
+    BDSKKeyedUnarchiver *unarchiver = [[BDSKKeyedUnarchiver alloc] 
initForReadingFromData:data error:NULL];
     
-    [NSString setMacroResolverForUnarchiving:aMacroResolver];
+    [unarchiver setMacroResolver:aMacroResolver];
     
     NSArray *pubs = [unarchiver decodeObjectOfClasses:[NSSet 
setWithObjects:[NSArray class], [BibItem class], nil] forKey:@"publications"];
     
     [unarchiver finishDecoding];
     
-    [NSString setMacroResolverForUnarchiving:nil];
-    
     // we set the macroResolver so we know the fields of this item may refer 
to it, so we can prevent scripting from adding this to the wrong document
     [pubs setValue:aMacroResolver forKey:@"macroResolver"];
     

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to