Configure NSPredicateEditor (RowTemplate) for SpotlightI 'metadata requests

I am trying to configure NSPredicateEditor (in Interface Builder) to edit a predicate for NSMetadataQuery .

As a first step, I'm trying to configure NSPredicateEditorRowTemplate to accept key paths for the left expression by trying one keyPath ( kMDItemTextContent ) to start.

I cannot figure out how to get all the parts in IB. I selected the line pattern and set "Left Exprs" to "Key Paths" in the Inspector IB Attributes. But, using the Apple PhotoSearch example as a model, it seems that I should enter the name of the user to be read here (for example, β€œContent”); I cannot figure out how to bind it to " kMDItemTextContent ".

I parsed the (correctly configured) NIB in PhotoSearch (*), and inside it there is NSKeyPathExpression defining a metadata attribute attached to NSPopUpButton / NSPopUpButtonCell .

I cannot figure out where to go to IB to find NSPopUpButton , and I'm not sure what I would do to bind it to NSExpression .

Any help was appreciated.

(*) In case you are interested, I ended up in NIB, converting it to XIB, confirming that it is still building correctly, and then exploring it with BBEdit.

+2
source share
1 answer

I found that working with NSPredicateEditor and friends in Interface Builder is an extremely tedious task. For this reason, I am doing all the string template configuration in the code.

In your situation, this doesn't look like you need a custom subclass of string patterns, so you could 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 get the template, just add it to predicateEditor:

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

Regarding the translation of β€œ kMDItemTextContent ”, if this does not happen automatically (and I think it might be possible), you can use the NSPredicateEditor localization parameters to display a different name.

+1
source

Source: https://habr.com/ru/post/1262600/


All Articles