2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2007-2023 Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// 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
|
|
|
|
2022-06-29 00:15:52 +00:00
|
|
|
@import AppKit;
|
2016-09-10 17:08:58 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "ExpandedPathToIconTransformer.h"
|
|
|
|
|
|
|
|
@implementation ExpandedPathToIconTransformer
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
+ (Class)transformedValueClass
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return [NSImage class];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
+ (BOOL)allowsReverseTransformation
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)transformedValue:(id)value
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (!value)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path = [value stringByExpandingTildeInPath];
|
|
|
|
NSImage* icon;
|
2007-09-16 01:02:06 +00:00
|
|
|
//show a folder icon if the folder doesn't exist
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([path.pathExtension isEqualToString:@""] && ![NSFileManager.defaultManager fileExistsAtPath:path])
|
|
|
|
{
|
|
|
|
icon = [NSWorkspace.sharedWorkspace iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
icon = [NSWorkspace.sharedWorkspace iconForFile:path];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
icon.size = NSMakeSize(16.0, 16.0);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
@end
|