New fix to Spotlight flicker issue. Still not ideal.

CQTexperiment
matthewleon 2008-02-16 22:59:27 +00:00
parent ab520a8cb8
commit ba0746b503
8 changed files with 586 additions and 569 deletions

View File

@ -603,6 +603,7 @@
5604D45A0D60349B004F5C5D /* SpotlightWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpotlightWindowController.h; path = Spotlight/SpotlightWindowController.h; sourceTree = "<group>"; };
5604D4F40D60726E004F5C5D /* SpotlightPlaylistEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpotlightPlaylistEntry.h; path = Spotlight/SpotlightPlaylistEntry.h; sourceTree = "<group>"; };
5604D4F50D60726E004F5C5D /* SpotlightPlaylistEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpotlightPlaylistEntry.m; path = Spotlight/SpotlightPlaylistEntry.m; sourceTree = "<group>"; };
563EBE1D0D67987E00E12948 /* SpotlightTransformers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpotlightTransformers.h; path = Spotlight/SpotlightTransformers.h; sourceTree = "<group>"; };
56462DD80D61D71E000AB68C /* SpotlightPlaylistView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpotlightPlaylistView.h; path = Spotlight/SpotlightPlaylistView.h; sourceTree = "<group>"; };
56462DD90D61D71E000AB68C /* SpotlightPlaylistView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpotlightPlaylistView.m; path = Spotlight/SpotlightPlaylistView.m; sourceTree = "<group>"; };
56462EAE0D6341F6000AB68C /* SpotlightTransformers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpotlightTransformers.m; path = Spotlight/SpotlightTransformers.m; sourceTree = "<group>"; };
@ -1110,6 +1111,7 @@
56DB08340D67166000453B6A /* Categories */,
56462EB00D634206000AB68C /* SpotlightPlaylistController.h */,
56462EB10D634206000AB68C /* SpotlightPlaylistController.m */,
563EBE1D0D67987E00E12948 /* SpotlightTransformers.h */,
56462EAE0D6341F6000AB68C /* SpotlightTransformers.m */,
5604D45A0D60349B004F5C5D /* SpotlightWindowController.h */,
5604D4590D60349B004F5C5D /* SpotlightWindowController.m */,

File diff suppressed because it is too large Load Diff

View File

@ -10,11 +10,8 @@
#import "PlaylistController.h"
@interface SpotlightPlaylistController : PlaylistController {
NSArray *oldObjects;
}
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard;
@property(retain) NSArray *oldObjects;
@end

View File

@ -11,15 +11,6 @@
@implementation SpotlightPlaylistController
- (id)init
{
if(self = [super init])
{
oldObjects = nil;
}
return self;
}
// Allow drag and drop from Spotlight into main playlist
- (BOOL)tableView:(NSTableView *)tv
writeRowsWithIndexes:(NSIndexSet *)rowIndexes
@ -45,21 +36,4 @@
return NSDragOperationNone;
}
// Don't update until something has been found
- (NSArray *)arrangeObjects:(NSArray *)objects
{
if((![spotlightWindowController.query isGathering]) || ([objects count] > 0))
self.oldObjects = [super arrangeObjects:objects];
return self.oldObjects;
}
- (void)dealloc
{
[oldObjects release];
[super dealloc];
}
@synthesize oldObjects;
@end

View File

@ -0,0 +1,20 @@
//
// SpotlightTransformers.h
// Cog
//
// Created by Matthew Grinshpun on 16/02/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@class SpotlightWindowController;
@interface StringToURLTransformer: NSValueTransformer {}
@end
@interface PausingQueryTransformer: NSValueTransformer {
NSArray *oldResults;
}
@property(copy) NSArray *oldResults;
@end

View File

@ -6,10 +6,8 @@
// Copyright 2008 Matthew Leon Grinshpun. All rights reserved.
//
#include <Cocoa/Cocoa.h>
@interface StringToURLTransformer: NSValueTransformer {}
@end
#import "SpotlightTransformers.h"
#import "SpotlightWindowController.h"
@implementation StringToURLTransformer
+ (Class)transformedValueClass { return [NSURL class]; }
@ -18,7 +16,7 @@
// Convert from string to NSURL
- (id)transformedValue:(id)value {
if (value == nil) return nil;
return [NSURL URLWithString:value];
}
@ -28,4 +26,20 @@
return [value absoluteString];
}
@end
@implementation PausingQueryTransformer
+ (Class)transformedValueClass { return [NSArray class]; }
+ (BOOL)allowsReverseTransformation { return NO; }
// Convert from string to NSURL
- (id)transformedValue:(id)value {
if([(NSArray *)value count] > 0) {
self.oldResults = (NSArray *)value;
}
return self.oldResults;
}
@synthesize oldResults;
@end

View File

@ -18,7 +18,6 @@
NSMetadataQuery *query;
NSString *searchString;
NSString *spotlightSearchPath;
NSArray *oldResults;
}
- (IBAction)addToPlaylist:(id)sender;
@ -32,6 +31,5 @@
@property(retain) NSMetadataQuery *query;
@property(copy) NSString *searchString;
@property(copy) NSString *spotlightSearchPath;
@property(retain) NSArray *oldResults;
@end

View File

@ -13,6 +13,7 @@
#import "NSArray+CogSort.h"
#import "NSString+CogSort.h"
#import "NSNumber+CogSort.h"
#import "SpotlightTransformers.h"
// Minimum length of a search string (searching for very small strings gets ugly)
#define MINIMUM_SEARCH_STRING_LENGTH 3
@ -36,6 +37,14 @@ static NSPredicate * musicOnlyPredicate = nil;
NSDictionary *searchDefault =
[NSDictionary dictionaryWithObject:homeDir
forKey:@"spotlightSearchPath"];
// Register value transformers
NSValueTransformer *stringToURLTransformer = [[[StringToURLTransformer alloc]init]autorelease];
[NSValueTransformer setValueTransformer:stringToURLTransformer
forName:@"StringToURLTransformer"];
NSValueTransformer *pausingQueryTransformer = [[[PausingQueryTransformer alloc] init] autorelease];
[NSValueTransformer setValueTransformer:pausingQueryTransformer forName:@"PausingQueryTransformer"];
[defaults registerDefaults:searchDefault];
}
@ -54,7 +63,7 @@ static NSPredicate * musicOnlyPredicate = nil;
[[NSSortDescriptor alloc]initWithKey:@"kMDItemAudioTrackNumber"
ascending:YES
selector:@selector(compareTrackNumbers:)],
Nil];
nil];
}
return self;
@ -198,7 +207,7 @@ static NSPredicate * musicOnlyPredicate = nil;
}
if ([subpredicates count] == 0)
return Nil;
return nil;
else if ([subpredicates count] == 1)
return [subpredicates objectAtIndex: 0];
@ -226,7 +235,6 @@ static NSPredicate * musicOnlyPredicate = nil;
[self.query release];
[self.searchString release];
[musicOnlyPredicate release];
[self.oldResults release];
[super dealloc];
}
@ -289,6 +297,4 @@ replacementObjectForResultObject:(NSMetadataItem*)result
}
}
@synthesize oldResults;
@end