transmission/macosx/ExpandedPathToIconTransform...

46 lines
992 B
Plaintext
Raw Normal View History

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