Changing Spotlight search path works properly.
parent
c04f9565d6
commit
c25dfa6535
File diff suppressed because it is too large
Load Diff
|
@ -16,15 +16,16 @@
|
||||||
IBOutlet NSPathControl *pathControl;
|
IBOutlet NSPathControl *pathControl;
|
||||||
NSMetadataQuery *query;
|
NSMetadataQuery *query;
|
||||||
NSString *searchString;
|
NSString *searchString;
|
||||||
|
NSString *spotlightSearchPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)addToPlaylist:(id)sender;
|
- (IBAction)addToPlaylist:(id)sender;
|
||||||
- (IBAction)changeSearchPath:(id)sender;
|
|
||||||
|
|
||||||
- (void)performSearch;
|
- (void)performSearch;
|
||||||
- (NSPredicate *)processSearchString;
|
- (NSPredicate *)processSearchString;
|
||||||
|
|
||||||
@property(retain) NSMetadataQuery *query;
|
@property(retain) NSMetadataQuery *query;
|
||||||
@property(copy) NSString *searchString;
|
@property(copy) NSString *searchString;
|
||||||
|
@property(copy) NSString *spotlightSearchPath;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -60,8 +60,10 @@ static NSPredicate * musicOnlyPredicate = nil;
|
||||||
[NSArray arrayWithObjects: musicOnlyPredicate,
|
[NSArray arrayWithObjects: musicOnlyPredicate,
|
||||||
searchPredicate,
|
searchPredicate,
|
||||||
nil]];
|
nil]];
|
||||||
// Only preform a new search if the predicate has changed
|
// Only preform a new search if the predicate has changed or there is a new path
|
||||||
if(![self.query.predicate isEqual:spotlightPredicate])
|
if(![self.query.predicate isEqual:spotlightPredicate]
|
||||||
|
|| ![self.query.searchScopes isEqualToArray:
|
||||||
|
[NSArray arrayWithObjects:pathControl.URL, nil]])
|
||||||
{
|
{
|
||||||
if([self.query isStarted])
|
if([self.query isStarted])
|
||||||
[self.query stopQuery];
|
[self.query stopQuery];
|
||||||
|
@ -136,14 +138,6 @@ static NSPredicate * musicOnlyPredicate = nil;
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)changeSearchPath:(id)sender
|
|
||||||
{
|
|
||||||
// When the search path is changed, restart search
|
|
||||||
if([self.query isStarted]) {
|
|
||||||
[self performSearch];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (IBAction)addToPlaylist:(id)sender
|
- (IBAction)addToPlaylist:(id)sender
|
||||||
{
|
{
|
||||||
[self.query disableUpdates];
|
[self.query disableUpdates];
|
||||||
|
@ -171,11 +165,34 @@ replacementObjectForResultObject:(NSMetadataItem*)result
|
||||||
- (void)setSearchString:(NSString *)aString
|
- (void)setSearchString:(NSString *)aString
|
||||||
{
|
{
|
||||||
// Make sure the string is changed
|
// Make sure the string is changed
|
||||||
if (searchString != aString)
|
if (![searchString isEqualToString:aString])
|
||||||
{
|
{
|
||||||
searchString = [aString copy];
|
searchString = [aString copy];
|
||||||
[self performSearch];
|
[self performSearch];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@dynamic spotlightSearchPath;
|
||||||
|
// getter reads from user defaults
|
||||||
|
- (NSString *)spotlightSearchPath
|
||||||
|
{
|
||||||
|
return [[[NSUserDefaults standardUserDefaults]
|
||||||
|
stringForKey:@"spotlightSearchPath"]copy];
|
||||||
|
}
|
||||||
|
// Normally, our nspathcontrol would just bind to the user defaults
|
||||||
|
// However, this does not allow us to perform a new search when
|
||||||
|
// the path changes. This getter/setter combo wraps around the user
|
||||||
|
// defaults while performing a new search when the value changes.
|
||||||
|
- (void)setSpotlightSearchPath:(NSString *)aString
|
||||||
|
{
|
||||||
|
// Make sure the string is changed
|
||||||
|
if (![spotlightSearchPath isEqualToString: aString])
|
||||||
|
{
|
||||||
|
spotlightSearchPath = [aString copy];
|
||||||
|
[[NSUserDefaults standardUserDefaults] setObject:spotlightSearchPath
|
||||||
|
forKey:@"spotlightSearchPath"];
|
||||||
|
[self performSearch];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue