Revision: 29005 http://sourceforge.net/p/bibdesk/svn/29005 Author: hofman Date: 2025-02-16 16:22:01 +0000 (Sun, 16 Feb 2025) Log Message: ----------- use static variable for class instead of macro. Don't use copy or new for method names
Modified Paths: -------------- trunk/bibdesk/BDSKLinkedFile.m Modified: trunk/bibdesk/BDSKLinkedFile.m =================================================================== --- trunk/bibdesk/BDSKLinkedFile.m 2025-02-16 15:39:09 UTC (rev 29004) +++ trunk/bibdesk/BDSKLinkedFile.m 2025-02-16 16:22:01 UTC (rev 29005) @@ -64,12 +64,12 @@ @interface BDSKAlias : NSObject { AliasHandle alias; } -+ (instancetype)newWithData:(NSData *)data; -+ (instancetype)newWithFSRef:(const FSRef *)aRef baseRef:(const FSRef *)baseRef; -+ (instancetype)newWithPath:(NSString *)path basePath:(NSString *)basePath; ++ (instancetype)aliasWithData:(NSData *)data; ++ (instancetype)aliasWithFSRef:(const FSRef *)aRef baseRef:(const FSRef *)baseRef; ++ (instancetype)aliasWithPath:(NSString *)path basePath:(NSString *)basePath; - (BOOL)getFSRef:(FSRef *)outRef baseRef:(const FSRef *)baseRef shouldUpdate:(BOOL *)shouldUpdate; - (void)updateWithFSRef:(const FSRef *)aRef baseRef:(const FSRef *)baseRef; -- (NSData *)copyData; +@property (nonatomic, readonly) NSData *data; @end #pragma mark - @@ -93,8 +93,8 @@ __weak id delegate; } - (void)updateFileURL; -- (NSData *)copyAliasDataRelativeToPath:(NSString *)newBasePath; -- (NSData *)copyDataRelativeToPath:(NSString *)newBasePath isBookmark:(BOOL *)isBookmark; +- (NSData *)aliasDataRelativeToPath:(NSString *)newBasePath; +- (NSData *)dataRelativeToPath:(NSString *)newBasePath isBookmark:(BOOL *)isBookmark; @end #pragma mark - @@ -128,21 +128,19 @@ @dynamic URL, file, displayURL, path, stringValue, bibTeXString, relativePath, delegate, hasSkimNotes; static Class BDSKLinkedFileClass = Nil; +static Class BDSKConcreteLinkedAliasFileClass = Nil; static BOOL saveRelativePathOnly = NO; static BOOL saveArchivedData = NO; -static BOOL wantsAlias = NO; -#define BDSKLinkedAliasFile_alloc (wantsAlias ? [BDSKAliasLinkedFile alloc] : [BDSKBookmarkLinkedFile alloc]) - + (void)initialize { BDSKINITIALIZE; BDSKLinkedFileClass = self; saveRelativePathOnly = [[NSUserDefaults standardUserDefaults] boolForKey:BDSKSaveLinkedFilesAsRelativePathOnlyKey]; saveArchivedData = [[NSUserDefaults standardUserDefaults] boolForKey:BDSKSaveLinkedFilesAsArchivedDataKey]; - wantsAlias = saveArchivedData || [[NSUserDefaults standardUserDefaults] boolForKey:BDSKSaveLinkedFilesAsAliasKey]; - NSString *fileClassName = wantsAlias ? @"BDSKAliasLinkedFile" : @"BDSKBookmarkLinkedFile"; - [NSKeyedUnarchiver setClass:NSClassFromString(fileClassName) forClassName:@"BDSKLinkedAliasFile"]; + NSString *fileClassName = (saveArchivedData || [[NSUserDefaults standardUserDefaults] boolForKey:BDSKSaveLinkedFilesAsAliasKey]) ? @"BDSKAliasLinkedFile" : @"BDSKBookmarkLinkedFile"; + BDSKConcreteLinkedAliasFileClass = NSClassFromString(fileClassName); + [NSKeyedUnarchiver setClass:BDSKConcreteLinkedAliasFileClass forClassName:@"BDSKLinkedAliasFile"]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" [NSUnarchiver decodeClassName:@"BDSKLinkedAliasFile" asClassName:fileClassName]; @@ -263,7 +261,7 @@ - (id)initWithURL:(NSURL *)aURL delegate:(id<BDSKLinkedFileDelegate>)aDelegate { if([aURL isFileURL]) - return (id)[BDSKLinkedAliasFile_alloc initWithURL:aURL delegate:aDelegate]; + return (id)[[BDSKConcreteLinkedAliasFileClass alloc] initWithURL:aURL delegate:aDelegate]; else if (aURL) return (id)[[BDSKLinkedURL alloc] initWithURL:aURL delegate:aDelegate]; else @@ -271,7 +269,7 @@ } - (id)initWithBase64String:(NSString *)base64String delegate:(id<BDSKLinkedFileDelegate>)aDelegate { - return (id)[BDSKLinkedAliasFile_alloc initWithBase64String:base64String delegate:aDelegate]; + return (id)[[BDSKConcreteLinkedAliasFileClass alloc] initWithBase64String:base64String delegate:aDelegate]; } - (id)initWithURLString:(NSString *)aString { @@ -357,7 +355,7 @@ } if (data) { NSDictionary *dictionary = BDSKDictionaryFromData(data); - anAlias = [dictionary objectForKey:BOOKMARK_KEY] ?: [BDSKAlias newWithData:[dictionary objectForKey:ALIASDATA_KEY]]; + anAlias = [dictionary objectForKey:BOOKMARK_KEY] ?: [BDSKAlias aliasWithData:[dictionary objectForKey:ALIASDATA_KEY]]; relPath = [dictionary objectForKey:RELATIVEPATH_KEY]; } } else { @@ -376,15 +374,15 @@ - (instancetype)initWithCoder:(NSCoder *)coder { if ([self isMemberOfClass:BDSKLinkedAliasFileClass]) { BDSKASSERT_NOT_REACHED("Attempt to decode a BDSKLinkedAliasFile instance"); - self = BDSKLinkedAliasFile_alloc; + self = [BDSKConcreteLinkedAliasFileClass alloc]; } id anAlias = nil; NSString *relPath = nil; if ([coder allowsKeyedCoding]) { - anAlias = [coder decodeObjectForKey:BOOKMARK_KEY] ?: [BDSKAlias newWithData:[coder decodeObjectForKey:ALIASDATA_KEY]]; + anAlias = [coder decodeObjectForKey:BOOKMARK_KEY] ?: [BDSKAlias aliasWithData:[coder decodeObjectForKey:ALIASDATA_KEY]]; relPath = [coder decodeObjectForKey:RELATIVEPATH_KEY]; } else { - anAlias = [BDSKAlias newWithData:[coder decodeObject]]; + anAlias = [BDSKAlias aliasWithData:[coder decodeObject]]; relPath = [coder decodeObject]; } self = [self initWithAlias:anAlias relativePath:relPath delegate:nil]; @@ -396,11 +394,11 @@ [self updateFileURL]; if ([coder allowsKeyedCoding]) { BOOL isBookmark = NO; - NSData *data = [self copyDataRelativeToPath:[delegate basePathForLinkedFile:self] isBookmark:&isBookmark]; + NSData *data = [self dataRelativeToPath:[delegate basePathForLinkedFile:self] isBookmark:&isBookmark]; [coder encodeObject:relativePath forKey:RELATIVEPATH_KEY]; [coder encodeObject:data forKey:isBookmark ? BOOKMARK_KEY : ALIASDATA_KEY]; } else { - NSData *data = [self copyAliasDataRelativeToPath:[delegate basePathForLinkedFile:self]]; + NSData *data = [self aliasDataRelativeToPath:[delegate basePathForLinkedFile:self]]; [coder encodeObject:data]; [coder encodeObject:relativePath]; } @@ -415,13 +413,13 @@ // make sure the fileRef is valid [self updateFileURL]; BOOL isBookmark = NO; - NSData *data = [self copyDataRelativeToPath:[delegate basePathForLinkedFile:self] isBookmark:&isBookmark]; + NSData *data = [self dataRelativeToPath:[delegate basePathForLinkedFile:self] isBookmark:&isBookmark]; id anAlias = nil; if (data) { if (isBookmark) { anAlias = data; } else { - anAlias = [BDSKAlias newWithData:data]; + anAlias = [BDSKAlias aliasWithData:data]; if (anAlias == nil && [alias isKindOfClass:[NSData class]]) anAlias = alias; } @@ -508,7 +506,7 @@ path = path && newBasePath ? [path relativePathFromPath:newBasePath] : relativePath; if (noAlias == NO || path == nil) { BOOL isBookmark = NO; - NSData *data = [self copyDataRelativeToPath:newBasePath isBookmark:&isBookmark]; + NSData *data = [self dataRelativeToPath:newBasePath isBookmark:&isBookmark]; if (data) { dictionary = [NSDictionary dictionaryWithObjectsAndKeys:data, (isBookmark ? BOOKMARK_KEY : ALIASDATA_KEY), path, RELATIVEPATH_KEY, nil]; } @@ -522,10 +520,10 @@ } // implemented by the subclasses -- (NSData *)copyAliasDataRelativeToPath:(NSString *)newBasePath { return nil; } +- (NSData *)aliasDataRelativeToPath:(NSString *)newBasePath { return nil; } // implemented by the subclasses -- (NSData *)copyDataRelativeToPath:(NSString *)newBasePath isBookmark:(BOOL *)isBookmark { return nil; } +- (NSData *)dataRelativeToPath:(NSString *)newBasePath isBookmark:(BOOL *)isBookmark { return nil; } // implemented by the subclasses - (void)updateFileURL {} @@ -550,7 +548,7 @@ NSString *basePath = [aDelegate basePathForLinkedFile:self]; NSString *relPath = basePath ? [aPath relativePathFromPath:basePath] : nil; - id anAlias = [BDSKAlias newWithPath:aPath basePath:basePath]; + id anAlias = [BDSKAlias aliasWithPath:aPath basePath:basePath]; self = [self initWithAlias:anAlias relativePath:relPath delegate:aDelegate]; if (self && basePath) [self updateFileRef]; @@ -584,7 +582,7 @@ if ([alias isKindOfClass:[BDSKAlias class]]) { [alias updateWithFSRef:fileRef baseRef:baseRef]; } else { - BDSKAlias *anAlias = [BDSKAlias newWithFSRef:fileRef baseRef:baseRef]; + BDSKAlias *anAlias = [BDSKAlias aliasWithFSRef:fileRef baseRef:baseRef]; if (anAlias) { alias = nil; alias = anAlias; @@ -681,7 +679,7 @@ } - (void)setAliasWithPath:(NSString *)aPath basePath:(NSString *)basePath { - id anAlias = [BDSKAlias newWithPath:aPath basePath:basePath]; + id anAlias = [BDSKAlias aliasWithPath:aPath basePath:basePath]; if (anAlias != nil) { id saveAlias = alias; alias = anAlias; @@ -755,25 +753,25 @@ isInitial = NO; } -- (NSData *)copyAliasDataRelativeToPath:(NSString *)basePath { +- (NSData *)aliasDataRelativeToPath:(NSString *)basePath { BDSKAlias *anAlias = NULL; if (fileRef) { FSRef baseRef; BOOL hasBaseRef = BDSKPathToFSRef(basePath, &baseRef); - anAlias = [BDSKAlias newWithFSRef:fileRef baseRef:hasBaseRef ? &baseRef : NULL]; + anAlias = [BDSKAlias aliasWithFSRef:fileRef baseRef:hasBaseRef ? &baseRef : NULL]; } else if (relativePath && basePath) { NSString *path = [relativePath isAbsolutePath] ? relativePath : [[basePath stringByAppendingPathComponent:relativePath] stringByStandardizingPath]; - anAlias = [BDSKAlias newWithPath:path basePath:basePath]; + anAlias = [BDSKAlias aliasWithPath:path basePath:basePath]; } if (anAlias == NULL && [alias isKindOfClass:[BDSKAlias class]]) anAlias = alias; - return [anAlias copyData]; + return [anAlias data]; } -- (NSData *)copyDataRelativeToPath:(NSString *)newBasePath isBookmark:(BOOL *)isBookmark { - NSData *data = [self copyAliasDataRelativeToPath:newBasePath]; +- (NSData *)dataRelativeToPath:(NSString *)newBasePath isBookmark:(BOOL *)isBookmark { + NSData *data = [self aliasDataRelativeToPath:newBasePath]; if (data) { *isBookmark = NO; } else if ([alias isKindOfClass:[NSData class]]) { @@ -928,22 +926,22 @@ isInitial = NO; } -- (NSData *)copyAliasDataRelativeToPath:(NSString *)basePath { +- (NSData *)aliasDataRelativeToPath:(NSString *)basePath { BDSKAlias *anAlias = NULL; if (fileURL) { - anAlias = [BDSKAlias newWithPath:[fileURL path] basePath:basePath]; + anAlias = [BDSKAlias aliasWithPath:[fileURL path] basePath:basePath]; } else if (relativePath && basePath) { NSString *path = [relativePath isAbsolutePath] ? relativePath : [[basePath stringByAppendingPathComponent:relativePath] stringByStandardizingPath]; - anAlias = [BDSKAlias newWithPath:path basePath:basePath]; + anAlias = [BDSKAlias aliasWithPath:path basePath:basePath]; } if (anAlias != NULL && [alias isKindOfClass:[BDSKAlias class]]) anAlias = alias; - return [anAlias copyData]; + return [anAlias data]; } -- (NSData *)copyDataRelativeToPath:(NSString *)newBasePath isBookmark:(BOOL *)isBookmark { +- (NSData *)dataRelativeToPath:(NSString *)newBasePath isBookmark:(BOOL *)isBookmark { NSData *data = nil; if (fileURL) { @@ -958,7 +956,7 @@ if (data) { *isBookmark = YES; } else if ([alias isKindOfClass:[BDSKAlias class]]) { - data = [alias copyData]; + data = [alias data]; *isBookmark = NO; } return data; @@ -1093,6 +1091,8 @@ @implementation BDSKAlias +@dynamic data; + - (instancetype)initWithAliasHandle:(AliasHandle)handle { self = [super init]; if (self) { @@ -1101,12 +1101,12 @@ return self; } -+ (instancetype)newWithPath:(NSString *)path basePath:(NSString *)basePath { ++ (instancetype)aliasWithPath:(NSString *)path basePath:(NSString *)basePath { FSRef ref, baseRef; if (BDSKPathToFSRef(path, &ref) && (basePath == nil || BDSKPathToFSRef(basePath, &baseRef))) - return [self newWithFSRef:&ref baseRef:&baseRef]; + return [self aliasWithFSRef:&ref baseRef:&baseRef]; return nil; } @@ -1113,7 +1113,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" -+ (instancetype)newWithData:(NSData *)data { ++ (instancetype)aliasWithData:(NSData *)data { CFIndex len; Handle handle = NULL; @@ -1131,7 +1131,7 @@ return handle == NULL ? nil : [[self alloc] initWithAliasHandle:(AliasHandle)handle]; } -+ (instancetype)newWithFSRef:(const FSRef *)aRef baseRef:(const FSRef *)baseRef { ++ (instancetype)aliasWithFSRef:(const FSRef *)aRef baseRef:(const FSRef *)baseRef { OSStatus err = noErr; AliasHandle handle = NULL; @@ -1162,7 +1162,7 @@ return noErr == err; } -- (NSData *)copyData { +- (NSData *)data { Handle handle = (Handle)alias; CFDataRef data = NULL; CFIndex len; 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