diff --git a/Medianno/MADocWindow.h b/Medianno/MADocWindow.h
index 16bf838..f370096 100644
--- a/Medianno/MADocWindow.h
+++ b/Medianno/MADocWindow.h
@@ -26,8 +26,9 @@
QTTime lastMovieTime;
}
-@property BOOL exportAnnotations;
-@property BOOL exportTags;
+@property BOOL exportAnnotations;
+@property BOOL exportTags;
+@property (retain) NSString * searchString;
- (IBAction)addMediaFiles:(id)sender;
- (IBAction)importText:(id)sender;
diff --git a/Medianno/MADocWindow.mm b/Medianno/MADocWindow.mm
index de54e52..2bf4169 100644
--- a/Medianno/MADocWindow.mm
+++ b/Medianno/MADocWindow.mm
@@ -24,7 +24,7 @@ static const char * kMADocWindowObserver = "MADocWindowObserver";
@implementation MADocWindow
-@synthesize exportAnnotations, exportTags;
+@synthesize exportAnnotations, exportTags, searchString;
- (id)initWithWindow:(NSWindow *)window
{
@@ -504,6 +504,26 @@ static NSTimeInterval sLastSkip = 0.0;
}];
}
+#pragma mark Searching
+
+- (void)setSearchString:(NSString *)str
+{
+ [self willChangeValueForKey:@"searchString"];
+ searchString = str;
+ if (!searchString || [searchString isEqual:@""]) {
+ [mediaController setFilterPredicate:nil];
+ [annotationController setFilterPredicate:nil];
+ } else {
+ NSArray * matchingTags = [[self document] tagDescriptionsMatching:searchString];
+ [mediaController setFilterPredicate:
+ [NSPredicate predicateWithFormat:@"SUBQUERY(annotations,$a,$a.notes CONTAINS[cd] %@ OR ANY $a.tagDescriptions IN %@).@count > 0",
+ searchString, matchingTags]];
+ [annotationController setFilterPredicate:
+ [NSPredicate predicateWithFormat:@"notes CONTAINS[cd] %@ OR ANY tagDescriptions IN %@",
+ searchString, matchingTags]];
+ }
+ [self didChangeValueForKey:@"searchString"];
+}
@end
@implementation MADocumentWindow
diff --git a/Medianno/MADocument.h b/Medianno/MADocument.h
index 49e657d..e07a94d 100644
--- a/Medianno/MADocument.h
+++ b/Medianno/MADocument.h
@@ -23,5 +23,6 @@
- (MATagDescription *)tagDescriptionForName:(NSString *)name notes:(NSString *)notes;
- (NSArray *)tagNamesMatchingPrefix:(NSString *)prefix;
- (NSSet *)allTags;
+- (NSArray *)tagDescriptionsMatching:(NSString *)substring;
@end
diff --git a/Medianno/MADocument.mm b/Medianno/MADocument.mm
index f1984a8..4ea55e6 100644
--- a/Medianno/MADocument.mm
+++ b/Medianno/MADocument.mm
@@ -133,6 +133,16 @@
return names;
}
+- (NSArray *)tagDescriptionsMatching:(NSString *)substring
+{
+ NSManagedObjectContext *moc = [self managedObjectContext];
+ NSFetchRequest * fetch = [NSFetchRequest fetchRequestWithEntityName:@"MATagDescription"];
+ [fetch setPredicate:[NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@ OR notes CONTAINS[cd] %@",
+ substring, substring]];
+
+ return [moc executeFetchRequest:fetch error:nil];
+}
+
- (NSSet *)allTags
{
NSManagedObjectContext *moc = [self managedObjectContext];
diff --git a/Medianno/en.lproj/MADocument.xib b/Medianno/en.lproj/MADocument.xib
index b73f517..2212a88 100644
--- a/Medianno/en.lproj/MADocument.xib
+++ b/Medianno/en.lproj/MADocument.xib
@@ -162,6 +162,7 @@
268
{{0, 14}, {32, 32}}
+
_NS:1491
YES
@@ -255,6 +256,7 @@
268
{{0, 14}, {32, 32}}
+
_NS:1491
YES
@@ -322,6 +324,7 @@
268
{{0, 14}, {96, 22}}
+
_NS:123
100
@@ -329,8 +332,8 @@
-
+
+
+ value: searchString
+
+
+
+
+
+ value: searchString
+ value
+ searchString
+ 2
+
+
+ 100316
+
@@ -2619,7 +2638,7 @@
- 100308
+ 100316