-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskArrayController.m
56 lines (47 loc) · 1.67 KB
/
TaskArrayController.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
53
54
55
56
//
// TaskArrayController.m
// TODO
//
// Created by 下村 翔 on 5/14/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "TaskArrayController.h"
#import "Predicate.h"
@implementation TaskArrayController
- (void) awakeFromNib
{
[super awakeFromNib];
NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(onPredicateChangeAction:)
name:NSTableViewSelectionDidChangeNotification object:listTableView];
[nc addObserver:self selector:@selector(onPredicateChangeAction:)
name:NSControlTextDidChangeNotification object:searchField];
}
- (void) updatePredicate
{
NSMutableArray *allPredicates = [NSMutableArray arrayWithCapacity:3];
// predicate of list
if ([[predicateController selectedObjects] count]) {
NSArray *preds = [predicateController selectedObjects];
Predicate *listpred = [preds objectAtIndex:0];
if (![listpred.predicateString isEqualToString:@""])
{
[allPredicates addObject:[NSPredicate predicateWithFormat:listpred.predicateString]];
}
}
// predicate of searchfield
if (![[searchField stringValue] isEqualToString:@""]) {
NSString *searchpred = [NSString stringWithFormat:@"((title like[cd] '*%@*') OR (any notes.content like[cd] '*%@*'))",
[searchField stringValue], [searchField stringValue]];
[allPredicates addObject:[NSPredicate predicateWithFormat:searchpred]];
}
// end of predicates array
//[allPredicates addObject:nil];
[self setFilterPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:allPredicates]];
NSLog(@"Predicate: %@", [self filterPredicate]);
}
- (void) onPredicateChangeAction:(NSNotification *)ntf
{
[self updatePredicate];
}
@end