开发者

Configuring NSPredicateEditor(RowTemplate) for Spotlight metadata queriesI'

I'm trying to configure an NSPredicateEditor (in Interface Builder) to edit the predicate for an NSMetadataQuery.

As a first step, I'm trying to configure an NSPredicateEditorRowTemplate to accept key path(s) for the left-side expression, trying a single keyPath (kMDItemTextContent) to get started.

I can't figure out how to get all the pieces into IB. I've selected the row template, and set "Left Exprs" to "Key Paths" in the IB Attributes Inspector. But, using Apple's PhotoSearch exam开发者_JAVA百科ple as a model, it appears that I should enter a user-readable attribute name (say, "Content") here; I can't figure out how to bind it to "kMDItemTextContent".

I've dissected the (correctly-configured) NIB in PhotoSearch(*), and inside it there is an NSKeyPathExpression specifying a metadata attribute attached to an NSPopUpButton/NSPopUpButtonCell.

I can't figure out where to navigate in IB to find the NSPopUpButton, and I'm not sure what I'd do to bind it to an NSExpression.

Any help appreciated.

(*) In case you're wondering, I got inside the NIB by converting it to a XIB, confirming that it still builds correctly, then examining it with BBEdit.


I've found that working with NSPredicateEditor and friends in Interface Builder is an exceedingly tedious task. For that reason, I do all of my row template configuration in code.

For your situation, it doesn't sound like you need a custom row template subclass, so you could probably just do:

#define NSPERT NSPredicateEditorRowTemplate
NSPERT * template = [[NSPERT alloc] initWithLeftExpressions:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:kMDItemTextContent]] 
                               rightExpressionAttributeType:NSStringAttributeType
                                                   modifier:NSDirectPredicateModifier
                                                  operators:[NSArray arrayWithObject:
                                                             [NSNumber numberWithUnsignedInteger:NSContainsPredicateOperatorType]]
                                                    options:(NSCaseInsensitivePredicateOption|NSDiacriticInsensitivePredicateOption)];

Once you've got the template, simply add it to the predicateEditor:

NSMutableArray * templates = [[myPredicateEditor rowTemplates] mutableCopy];
[templates addObject:template];
[template release];
[myPredicateEditor setRowTemplates:templates];
[templates release];

As for translating the "kMDItemTextContent", if it doesn't happen automatically (and I think it might), you could use the NSPredicateEditor localization options to display a different name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜