mirror of
https://github.com/transmission/transmission
synced 2024-12-30 19:46:56 +00:00
45 lines
1,002 B
Text
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
|