1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 18:18:10 +00:00
transmission/macosx/ExpandedPathToIconTransformer.mm

46 lines
1,012 B
Text
Raw Normal View History

// This file Copyright © 2007-2022 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/AppKit.h>
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