2008-02-11 18:51:51 +00:00
|
|
|
//
|
|
|
|
// SpotlightTransformers.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Matthew Grinshpun on 11/02/08.
|
2008-02-14 14:07:10 +00:00
|
|
|
// Copyright 2008 Matthew Leon Grinshpun. All rights reserved.
|
2008-02-11 18:51:51 +00:00
|
|
|
//
|
|
|
|
|
2008-02-16 22:59:27 +00:00
|
|
|
#import "SpotlightTransformers.h"
|
|
|
|
#import "SpotlightWindowController.h"
|
2008-02-14 23:09:51 +00:00
|
|
|
|
2008-02-17 09:56:44 +00:00
|
|
|
// This is what we use instead of an outlet for PausingQueryTransformer
|
|
|
|
static SpotlightWindowController * searchController;
|
|
|
|
|
2008-02-16 22:59:27 +00:00
|
|
|
@implementation PausingQueryTransformer
|
|
|
|
+ (Class)transformedValueClass { return [NSArray class]; }
|
|
|
|
+ (BOOL)allowsReverseTransformation { return NO; }
|
|
|
|
|
2008-02-17 09:56:44 +00:00
|
|
|
+ (void)setSearchController:(SpotlightWindowController *)aSearchController
|
|
|
|
{
|
|
|
|
searchController = aSearchController;
|
|
|
|
}
|
|
|
|
|
2008-02-16 22:59:27 +00:00
|
|
|
- (id)transformedValue:(id)value {
|
2008-02-17 09:56:44 +00:00
|
|
|
// Rather unintuitively, this piece of code eliminates the "flicker"
|
|
|
|
// when searching for new results, which resulted from a pause when the
|
|
|
|
// search query stops gathering and sends an empty results array through KVO.
|
|
|
|
if(([value count] > 0) || ([searchController.query isGathering]))
|
|
|
|
{
|
2008-02-16 22:59:27 +00:00
|
|
|
self.oldResults = (NSArray *)value;
|
|
|
|
}
|
|
|
|
return self.oldResults;
|
|
|
|
}
|
|
|
|
|
2008-02-17 09:56:44 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
self.oldResults = nil;
|
|
|
|
}
|
|
|
|
|
2008-02-16 22:59:27 +00:00
|
|
|
@synthesize oldResults;
|
|
|
|
|
2008-02-18 12:59:20 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AuthorToArtistTransformer
|
|
|
|
+ (Class)transformedValueClass { return [NSString class]; }
|
|
|
|
+ (BOOL)allowsReverseTransformation { return NO; }
|
|
|
|
- (id)transformedValue:(id)value {
|
|
|
|
return [value objectAtIndex:0];
|
|
|
|
}
|
2008-02-18 16:55:31 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PathToURLTransformer
|
|
|
|
|
|
|
|
+ (Class)transformedValueClass { return [NSURL class]; }
|
|
|
|
+ (BOOL)allowsReverseTransformation { return YES; }
|
|
|
|
|
|
|
|
// Convert from path to NSURL
|
|
|
|
- (id)transformedValue:(id)value {
|
|
|
|
if (value == nil) return nil;
|
|
|
|
|
|
|
|
return [NSURL fileURLWithPath:value];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from NSURL to path
|
|
|
|
- (id)reverseTransformedValue:(id)value {
|
|
|
|
if (value == nil) return nil;
|
|
|
|
|
|
|
|
return [value path];
|
|
|
|
}
|
2008-02-18 12:59:20 +00:00
|
|
|
|
2008-02-18 20:09:02 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation StringToSearchScopeTransformer
|
|
|
|
|
|
|
|
+ (Class)transformedValueClass { return [NSArray class]; }
|
|
|
|
+ (BOOL)allowsReverseTransformation { return NO; }
|
|
|
|
|
|
|
|
// Convert from URL string to Search Scope
|
|
|
|
- (id)transformedValue:(id)value {
|
|
|
|
if (value == nil) return nil;
|
|
|
|
|
|
|
|
NSURL *scope = [NSURL URLWithString:value];
|
2022-01-19 02:12:57 +00:00
|
|
|
return @[scope];
|
2008-02-18 20:09:02 +00:00
|
|
|
}
|
|
|
|
|
2008-03-03 23:02:52 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NumberToStringTransformer
|
|
|
|
|
|
|
|
+ (Class)transformedValueClass { return [NSString class]; }
|
|
|
|
+ (BOOL)allowsReverseTransformation { return NO; }
|
|
|
|
|
|
|
|
// Convert from NSNumber to NSString
|
|
|
|
- (id)transformedValue:(id)value {
|
|
|
|
if (value == nil) return nil;
|
|
|
|
|
|
|
|
// If there's an NS/CFNumber hiding in here...
|
2021-01-27 02:45:02 +00:00
|
|
|
if([value respondsToSelector:@selector(stringValue)])
|
2008-03-03 23:02:52 +00:00
|
|
|
{
|
|
|
|
return [value stringValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-01-27 02:45:02 +00:00
|
|
|
@end
|