Probably final, probably ideal fix to Spotlight flicker!

CQTexperiment
matthewleon 2008-02-17 09:56:44 +00:00
parent ba0746b503
commit 438467000a
3 changed files with 25 additions and 2 deletions

View File

@ -16,5 +16,7 @@
NSArray *oldResults;
}
+ (void)setSearchController:(SpotlightWindowController *)aSearchController;
@property(copy) NSArray *oldResults;
@end

View File

@ -28,18 +28,36 @@
}
@end
// This is what we use instead of an outlet for PausingQueryTransformer
static SpotlightWindowController * searchController;
@implementation PausingQueryTransformer
+ (Class)transformedValueClass { return [NSArray class]; }
+ (BOOL)allowsReverseTransformation { return NO; }
+ (void)setSearchController:(SpotlightWindowController *)aSearchController
{
searchController = aSearchController;
}
// Convert from string to NSURL
- (id)transformedValue:(id)value {
if([(NSArray *)value count] > 0) {
// 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;
}
- (void)dealloc
{
self.oldResults = nil;
[super dealloc];
}
@synthesize oldResults;
@end

View File

@ -44,7 +44,7 @@ static NSPredicate * musicOnlyPredicate = nil;
forName:@"StringToURLTransformer"];
NSValueTransformer *pausingQueryTransformer = [[[PausingQueryTransformer alloc] init] autorelease];
[NSValueTransformer setValueTransformer:pausingQueryTransformer forName:@"PausingQueryTransformer"];
[defaults registerDefaults:searchDefault];
}
@ -64,6 +64,9 @@ static NSPredicate * musicOnlyPredicate = nil;
ascending:YES
selector:@selector(compareTrackNumbers:)],
nil];
// hook my query transformer up to me
[PausingQueryTransformer setSearchController:self];
}
return self;