Ticket #167: AliasDataToIconTransformer.m

File AliasDataToIconTransformer.m, 718 bytes (added by cluthi81, 15 years ago)

Transformer for bindings

Line 
1
2#import "AliasDataToIconTransformer.h"
3#import "BDAlias.h"
4#import "StringAdditions.h"
5
6@implementation AliasDataToIconTransformer
7
8+ (Class) transformedValueClass
9{
10    return [NSImage class];
11}
12
13+ (BOOL) allowsReverseTransformation
14{
15    return NO;
16}
17
18- (id) transformedValue: (id) value
19{
20    if (!value)
21        return nil;
22
23    BDAlias * alias = [BDAlias aliasWithData: value];
24    NSImage * icon = [alias isValidAlias] ? [[NSWorkspace sharedWorkspace] iconForFile: [alias fullPathWithDefault: [NSString desktopPath]]]
25                                          : [NSImage imageNamed: @"Error.tiff"];
26    [icon setScalesWhenResized: YES];
27    [icon setSize: NSMakeSize(16.0, 16.0)];
28   
29    return icon;
30}
31
32@end