I've got around it by implementing a kind of "man in the middle" subclass of NSPredicateEditorRowTemplate. I set the class of the row template to my subclass in IB and it automatically adds the "ANY" modifier to whatever is already configured. It removes the "ANY" modifier from the predicate before calling superclass function, and puts it back on the return values of super class functions. I've included the overridden functions below.

It would be much easier if there was an option called "Predicate Modifier" in IB for row templates.


-(NSComparisonPredicate*)copyPredicate: (NSComparisonPredicate*)aPredicate andChangeModifierTo: (NSComparisonPredicateModifier)aMod
{
        NSComparisonPredicate* aCopy = nil;
aCopy = (NSComparisonPredicate*)[NSComparisonPredicate predicateWithLeftExpression:[aPredicate leftExpression]
                                                                        
rightExpression:[aPredicate rightExpression]
                                                                        
modifier:aMod
                                                                        
type:[aPredicate predicateOperatorType]
                                                                        
options:[aPredicate options]];
        return aCopy;
}

- (double)matchForPredicate:(NSPredicate *)predicate
{
        //if the modifier is "ANY", then strip it off and pass it to super
        if([predicate isKindOfClass:[NSComparisonPredicate class]]){
                NSComparisonPredicate* p = (NSComparisonPredicate*)predicate;
                if([p comparisonPredicateModifier] == NSAnyPredicateModifier){
return [super matchForPredicate:[self copyPredicate:p andChangeModifierTo:NSDirectPredicateModifier]];
                }
        }
        
        //else, don't handle it
        return 0.0;
}

- (void)setPredicate:(NSPredicate *)predicate
{
        //strip off "ANY" modifier and pass it to super
        NSComparisonPredicate* p = (NSComparisonPredicate*)predicate;
[super setPredicate:[self copyPredicate:p andChangeModifierTo:NSDirectPredicateModifier]];
}

- (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates
{
        //add the "ANY" modifier back onto the predicate
NSComparisonPredicate* ret = (NSComparisonPredicate*)[super predicateWithSubpredicates:subpredicates]; return [self copyPredicate:ret andChangeModifierTo:NSAnyPredicateModifier];
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to