I'm creating an NSPredicateEditor in code and trying to achieve what I had hoped would be a fairly simple task. Basically, I would like to display a compound NSPredicateEditorRowTemplate (giving the user the option to perform matches when "All/Any/None of the following are true") and a number of fairly basic subrows beneath it. To do this, I construct my NSPredicateEditor and bind its value in order to save changes as the user edits their predicate.
The issue I'm experiencing is that, no matter what, I cannot make a compound NSPredicateEditorRowTemplate show by default as the parent row with a single subrow. When I create the predicate initially I pass a bogus empty predicate, like so:
filename BEGINSWITH[cd] ''
In order to force the display of a compound row I have to create two subrows:
filename BEGINSWITH[cd] '' && path ==[cd] ''
For reference, here's how I'm constructing the NSPredicateEditor:
NSArray *keyPaths = [NSArray arrayWithObjects:[NSExpression expressionForKeyPath:@"filename"], [NSExpression expressionForKeyPath:@"path"], nil];
NSArray *operators = [NSArray arrayWithObjects:[NSNumber numberWithInteger:NSEqualToPredicateOperatorType],
[NSNumber numberWithInteger:NSNotEqualToPredicateOperatorType],
[NSNumber numberWithInteger:NSBeginsWithPredicateOperatorType],
[NSNumber numberWithInteger:NSEndsWithPredicateOperatorType],
[NSNumber numberWithInteger:NSContainsPredicateOperatorType],
nil];
NSPredicateEditorRowTemplate *template = [[NSPredicateEditorRowTemplate alloc] initWithLeftExpressions:keyPaths
rightExpressionAttributeType:NSStringAttributeType
modifier:NSDirectPredicateModifier
operators:operators
options:(NSCaseInsensitivePredicateOption | NSDiacriticInsensitivePredicateOption)];
NSArray *compoundTypes = [NSArray arrayWithObjects:[NSNumber numberWithInteger:NSNotPredicateType],
[NSNumber numberWithInteger:NSAndPredicateType],
[NSNumber numberWithInteger:NSOrPredicateType],
nil];
NSPredicateEditorRowTemplate *compound = [[NSPredicateEditorRowTemplate alloc] initWithCompoundTypes:compoundTypes];
NSArray *rowTemplates = [NSArray arrayWithObjects:compound, template, nil];
[template release];
[compound release];
predicateEditor = [[NSPredicateEditor alloc] init];
[predicateEditor setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[predicateEditor setRowTemplates:rowTemplates];
[predicateEditor setCanRemoveAllRows:NO];
[predicateEditor setContinuous:YES];
[predicateEditor setFrame:[[scrollView contentView] bounds]];
// Create a custom binding for our NSPredicateEditor
SIPredicateStringValueTransformer *transformer = [[[SIPredicateStringValueTransformer alloc] init] autorelease];
NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionaryWithObjectsAndKeys:transformer, NSValueTransformerBindingOption, [NSNumber numberWithBool:YES], NSValidatesImmediatelyBindingOption, nil];
[predicateEditor bind:@"value" toObject:self withKeyPath:@"self.filter.predicate" options:bindingOptions];
// Add our NSPredicateEditor to our NSScrollView
[scrollView setDocumentView:predicateEditor];