为Spotlight元数据查询配置NSPredicateEditor(RowTemplate) [英] Configuring NSPredicateEditor(RowTemplate) for Spotlight metadata queriesI'
问题描述
我正在尝试配置NSPredicateEditor
(在Interface Builder中)以编辑NSMetadataQuery
的谓词.
I'm trying to configure an NSPredicateEditor
(in Interface Builder) to edit the predicate for an NSMetadataQuery
.
第一步,我试图配置NSPredicateEditorRowTemplate
以接受左侧表达式的键路径,并尝试使用单个keyPath(kMDItemTextContent
)入门.
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.
我不知道如何将所有内容放入IB.我选择了行模板,然后在IB属性检查器中将左侧表达式"设置为关键路径".但是,以Apple的PhotoSearch示例为模型,看来我应该在此处输入用户可读的属性名称(例如,"Content");我不知道如何将其绑定到"kMDItemTextContent
".
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 example 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
".
我已经在PhotoSearch(*)中解剖了(正确配置的)NIB,并且在其中的NSKeyPathExpression
指定了附加到NSPopUpButton
/NSPopUpButtonCell
的元数据属性.
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
.
我不知道要在IB中导航找到NSPopUpButton
的位置,而且我不确定如何将其绑定到NSExpression
.
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
.
任何帮助表示赞赏.
(*)如果您想知道,我进入NIB的方法是将其转换为XIB,确认它仍然可以正确构建,然后使用BBEdit进行检查.
推荐答案
我发现在Interface Builder中与NSPredicateEditor
和朋友一起工作是一项非常繁琐的任务.因此,我在代码中完成了所有行模板的配置.
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)];
一旦有了模板,只需将其添加到predicateEditor:
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];
对于翻译"kMDItemTextContent
",如果它不是自动发生的(我认为可能会发生),则可以使用
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.
这篇关于为Spotlight元数据查询配置NSPredicateEditor(RowTemplate)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!