1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00
transmission/macosx/ExpandedPathToIconTransformer.mm
2023-02-11 14:49:42 -06:00

45 lines
1,002 B
Text

// This file Copyright © 2007-2023 Transmission authors and contributors.
// It may be used under the MIT (SPDX: MIT) license.
// License text can be found in the licenses/ folder.
@import AppKit;
#import "ExpandedPathToIconTransformer.h"
@implementation ExpandedPathToIconTransformer
+ (Class)transformedValueClass
{
return [NSImage class];
}
+ (BOOL)allowsReverseTransformation
{
return NO;
}
- (id)transformedValue:(id)value
{
if (!value)
{
return nil;
}
NSString* path = [value stringByExpandingTildeInPath];
NSImage* icon;
//show a folder icon if the folder doesn't exist
if ([path.pathExtension isEqualToString:@""] && ![NSFileManager.defaultManager fileExistsAtPath:path])
{
icon = [NSWorkspace.sharedWorkspace iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
}
else
{
icon = [NSWorkspace.sharedWorkspace iconForFile:path];
}
icon.size = NSMakeSize(16.0, 16.0);
return icon;
}
@end