-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchFormatter.m
57 lines (43 loc) · 1.36 KB
/
SwitchFormatter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// SwitchFormatter.m
// CronniX
//
// Created by sas on Sat Sep 15 2001.
// Copyright (c) 2001 __CompanyName__. All rights reserved.
//
#import "SwitchFormatter.h"
@implementation SwitchFormatter
- (NSString *)stringForObjectValue: (id)obj {
//NSLog( @"inside SwitchFormatter:stringForObjectValue: %@", [ obj description ] );
if ( ! [ obj isKindOfClass: [ NSButtonCell class ] ] ) {
return [ obj description ];
}
return [ obj stringValue ];
}
/*- (BOOL)getObjectValue: (id *)obj
forString: (NSString *)string
errorDescription: (NSString **)error { */
- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string errorDescription:(NSString **)error {
BOOL retval = NO;
NSString *err = nil;
NSLog( @"inside SwitchFormatter:getObjectValue" );
if (obj) {
if ( [ string isEqualTo: @"1" ] ) {
[ *obj setState: 1 ];
} else {
[ *obj setState: 0 ];
}
retval = YES;
} else {
err = NSLocalizedString(@"Couldn't convert value", @"Error converting");
}
if (error) {
*error = err;
}
return retval;
}
- (NSAttributedString *)attributedStringForObjectValue: (id)obj
withDefaultAttributes: (NSDictionary *)attr {
return [ [ [ NSAttributedString alloc ] initWithString: [ self stringForObjectValue: obj ] ] autorelease ];
}
@end