+#pragma mark textMode value transformer
+
+// A value transformer for mapping "url" to "3" and vice versa in the
+// "textMode" preference, since NSMatrix uses NSInteger selectedIndex.
+
+#ifndef USE_IPHONE
+@interface TextModeTransformer: NSValueTransformer {}
+@end
+@implementation TextModeTransformer
++ (Class)transformedValueClass { return [NSString class]; }
++ (BOOL)allowsReverseTransformation { return YES; }
+
+- (id)transformedValue:(id)value {
+ if ([value isKindOfClass:[NSString class]]) {
+ int i = -1;
+ if ([value isEqualToString:@"date"]) { i = 0; }
+ else if ([value isEqualToString:@"literal"]) { i = 1; }
+ else if ([value isEqualToString:@"file"]) { i = 2; }
+ else if ([value isEqualToString:@"url"]) { i = 3; }
+ else if ([value isEqualToString:@"program"]) { i = 4; }
+ if (i != -1)
+ value = [NSNumber numberWithInt: i];
+ }
+ return value;
+}
+
+- (id)reverseTransformedValue:(id)value {
+ if ([value isKindOfClass:[NSNumber class]]) {
+ switch ((int) [value doubleValue]) {
+ case 0: value = @"date"; break;
+ case 1: value = @"literal"; break;
+ case 2: value = @"file"; break;
+ case 3: value = @"url"; break;
+ case 4: value = @"program"; break;
+ }
+ }
+ return value;
+}
+@end
+#endif // USE_IPHONE
+
+