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; NSArray *oldResults;
} }
+ (void)setSearchController:(SpotlightWindowController *)aSearchController;
@property(copy) NSArray *oldResults; @property(copy) NSArray *oldResults;
@end @end

View File

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

View File

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