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
|
2022-02-07 05:49:27 +00:00
|
|
|
static SpotlightWindowController *searchController;
|
2008-02-17 09:56:44 +00:00
|
|
|
|
2008-02-16 22:59:27 +00:00
|
|
|
@implementation PausingQueryTransformer
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (Class)transformedValueClass {
|
|
|
|
return [NSArray class];
|
|
|
|
}
|
|
|
|
+ (BOOL)allowsReverseTransformation {
|
|
|
|
return NO;
|
|
|
|
}
|
2008-02-16 22:59:27 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (void)setSearchController:(SpotlightWindowController *)aSearchController {
|
|
|
|
searchController = aSearchController;
|
2008-02-17 09:56:44 +00:00
|
|
|
}
|
|
|
|
|
2008-02-16 22:59:27 +00:00
|
|
|
- (id)transformedValue:(id)value {
|
2022-02-07 05:49:27 +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])) {
|
|
|
|
self.oldResults = (NSArray *)value;
|
|
|
|
}
|
|
|
|
return self.oldResults;
|
2008-02-16 22:59:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)dealloc {
|
|
|
|
self.oldResults = nil;
|
2008-02-17 09:56:44 +00:00
|
|
|
}
|
|
|
|
|
2008-02-16 22:59:27 +00:00
|
|
|
@synthesize oldResults;
|
|
|
|
|
2008-02-18 12:59:20 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AuthorToArtistTransformer
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (Class)transformedValueClass {
|
|
|
|
return [NSString class];
|
|
|
|
}
|
|
|
|
+ (BOOL)allowsReverseTransformation {
|
|
|
|
return NO;
|
|
|
|
}
|
2008-02-18 12:59:20 +00:00
|
|
|
- (id)transformedValue:(id)value {
|
2022-02-07 05:49:27 +00:00
|
|
|
return [value objectAtIndex:0];
|
2008-02-18 12:59:20 +00:00
|
|
|
}
|
2008-02-18 16:55:31 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PathToURLTransformer
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (Class)transformedValueClass {
|
|
|
|
return [NSURL class];
|
|
|
|
}
|
|
|
|
+ (BOOL)allowsReverseTransformation {
|
|
|
|
return YES;
|
|
|
|
}
|
2008-02-18 16:55:31 +00:00
|
|
|
|
|
|
|
// Convert from path to NSURL
|
|
|
|
- (id)transformedValue:(id)value {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(value == nil) return nil;
|
2008-02-18 16:55:31 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return [NSURL fileURLWithPath:value];
|
2008-02-18 16:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from NSURL to path
|
|
|
|
- (id)reverseTransformedValue:(id)value {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(value == nil) return nil;
|
|
|
|
|
|
|
|
return [value path];
|
2008-02-18 16:55:31 +00:00
|
|
|
}
|
2008-02-18 12:59:20 +00:00
|
|
|
|
2008-02-18 20:09:02 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation StringToSearchScopeTransformer
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (Class)transformedValueClass {
|
|
|
|
return [NSArray class];
|
|
|
|
}
|
|
|
|
+ (BOOL)allowsReverseTransformation {
|
|
|
|
return NO;
|
|
|
|
}
|
2008-02-18 20:09:02 +00:00
|
|
|
|
|
|
|
// Convert from URL string to Search Scope
|
|
|
|
- (id)transformedValue:(id)value {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(value == nil) return nil;
|
|
|
|
|
|
|
|
NSURL *scope = [NSURL URLWithString:value];
|
|
|
|
return @[scope];
|
2008-02-18 20:09:02 +00:00
|
|
|
}
|
|
|
|
|
2008-03-03 23:02:52 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NumberToStringTransformer
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (Class)transformedValueClass {
|
|
|
|
return [NSString class];
|
|
|
|
}
|
|
|
|
+ (BOOL)allowsReverseTransformation {
|
|
|
|
return NO;
|
|
|
|
}
|
2008-03-03 23:02:52 +00:00
|
|
|
|
|
|
|
// Convert from NSNumber to NSString
|
|
|
|
- (id)transformedValue:(id)value {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(value == nil) return nil;
|
|
|
|
|
|
|
|
// If there's an NS/CFNumber hiding in here...
|
|
|
|
if([value respondsToSelector:@selector(stringValue)]) {
|
|
|
|
return [value stringValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2008-03-03 23:02:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 02:45:02 +00:00
|
|
|
@end
|