-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQSSpotlightSavedSearchSource.m
52 lines (45 loc) · 1.87 KB
/
QSSpotlightSavedSearchSource.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// QSSpotlightSavedSearchSource.m
// QSSpotlightPlugIn
//
// Created by Nicholas Jitkoff on 3/19/05.
//
#import "QSSpotlightSavedSearchSource.h"
#import "QSMDFindWrapper.h"
@implementation QSSpotlightSavedSearchSource
- (QSObject *)spotlightRunSavedQuery:(QSObject *)dObject
{
NSString *path = [dObject singleFilePath];
NSMutableArray *results = [[NSMutableArray alloc] init];
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:results, kQSResultArrayKey, nil];
NSNotificationCenter *dc = [NSNotificationCenter defaultCenter];
// let the user know results are being collected
QSObject *searching = [QSObject makeObjectWithIdentifier:@"QSSearchPending"];
[searching setName:[NSString stringWithFormat:@"Searching in \"%@\"...", [dObject displayName]]];
[searching setIcon:[QSResourceManager imageNamed:@"Find"]];
[results addObject:searching];
[dc postNotificationName:@"QSSourceArrayCreated" object:self userInfo:userInfo];
[results removeObject:searching];
[results addObjectsFromArray:[self targetArrayForSavedQueryAtPath:path]];
[dc postNotificationName:@"QSSourceArrayUpdated" object:self userInfo:userInfo];
return nil;
}
- (BOOL)loadChildrenForObject:(QSObject *)object
{
NSString *path = [object singleFilePath];
NSArray *results = [self targetArrayForSavedQueryAtPath:path];
[object setChildren:results];
return YES;
}
- (NSArray *)targetArrayForSavedQueryAtPath:(NSString *)path
{
NSDictionary *search = [NSDictionary dictionaryWithContentsOfFile:path];
NSString *predicateString = [search objectForKey:@"RawQuery"];
//NSLog(@"original query: %@", predicateString);
NSString *scope = [[search valueForKeyPath:@"SearchCriteria.FXScopeArrayOfPaths"] objectAtIndex:0];
QSMDFindWrapper *wrap = [QSMDFindWrapper findWrapperWithQuery:predicateString path:scope keepalive:NO];
NSArray *results = [wrap results];
[wrap startQuery];
return results;
}
@end