Implement Media / Annotation search

This commit is contained in:
Matthias Neeracher 2011-08-24 04:30:49 +02:00
parent a41504067d
commit b121d4f4ed
5 changed files with 60 additions and 9 deletions

View File

@ -28,6 +28,7 @@
@property BOOL exportAnnotations;
@property BOOL exportTags;
@property (retain) NSString * searchString;
- (IBAction)addMediaFiles:(id)sender;
- (IBAction)importText:(id)sender;

View File

@ -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

View File

@ -23,5 +23,6 @@
- (MATagDescription *)tagDescriptionForName:(NSString *)name notes:(NSString *)notes;
- (NSArray *)tagNamesMatchingPrefix:(NSString *)prefix;
- (NSSet *)allTags;
- (NSArray *)tagDescriptionsMatching:(NSString *)substring;
@end

View File

@ -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];

View File

@ -162,6 +162,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{0, 14}, {32, 32}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:1491</string>
<bool key="NSEnabled">YES</bool>
@ -255,6 +256,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{0, 14}, {32, 32}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:1491</string>
<bool key="NSEnabled">YES</bool>
@ -322,6 +324,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{0, 14}, {96, 22}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:123</string>
<int key="NSTag">100</int>
@ -329,8 +332,8 @@
<object class="NSSearchFieldCell" key="NSCell" id="774960126">
<int key="NSCellFlags">343014976</int>
<int key="NSCellFlags2">268436544</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="23905036"/>
<string key="NSPlaceholderString">predicate</string>
<string key="NSCellIdentifier">_NS:123</string>
<reference key="NSControlView" ref="891639952"/>
<bool key="NSDrawsBackground">YES</bool>
@ -498,7 +501,7 @@
</object>
</object>
</object>
<object class="NSMutableArray" key="NSToolbarIBAllowedItems">
<object class="NSArray" key="NSToolbarIBAllowedItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="271164239"/>
<reference ref="962020774"/>
@ -508,11 +511,11 @@
<reference ref="1015085479"/>
<reference ref="957210769"/>
<reference ref="89055059"/>
<reference ref="916551158"/>
<reference ref="202060684"/>
<reference ref="585433049"/>
<reference ref="916551158"/>
</object>
<object class="NSArray" key="NSToolbarIBDefaultItems">
<object class="NSMutableArray" key="NSToolbarIBDefaultItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="490181719"/>
<reference ref="585433049"/>
@ -1094,7 +1097,7 @@
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="196617426"/>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{450, 478}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<int key="NSWindowCollectionBehavior">128</int>
@ -1903,6 +1906,22 @@
</object>
<int key="connectionID">100308</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: searchString</string>
<reference key="source" ref="891639952"/>
<reference key="destination" ref="512844837"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="891639952"/>
<reference key="NSDestination" ref="512844837"/>
<string key="NSLabel">value: searchString</string>
<string key="NSBinding">value</string>
<string key="NSKeyPath">searchString</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">100316</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -2619,7 +2638,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">100308</int>
<int key="maxID">100316</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">