diff --git a/Spotlight/SpotlightTransformers.h b/Spotlight/SpotlightTransformers.h index 0350039a5..86717865b 100644 --- a/Spotlight/SpotlightTransformers.h +++ b/Spotlight/SpotlightTransformers.h @@ -16,5 +16,7 @@ NSArray *oldResults; } ++ (void)setSearchController:(SpotlightWindowController *)aSearchController; + @property(copy) NSArray *oldResults; @end \ No newline at end of file diff --git a/Spotlight/SpotlightTransformers.m b/Spotlight/SpotlightTransformers.m index c2005d761..f533ec26e 100644 --- a/Spotlight/SpotlightTransformers.m +++ b/Spotlight/SpotlightTransformers.m @@ -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 \ No newline at end of file diff --git a/Spotlight/SpotlightWindowController.m b/Spotlight/SpotlightWindowController.m index 873c4c2af..65a5976ed 100644 --- a/Spotlight/SpotlightWindowController.m +++ b/Spotlight/SpotlightWindowController.m @@ -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;