Re: NSPredicateEditorRowTemplate and dynamic templateViews
Re: NSPredicateEditorRowTemplate and dynamic templateViews
- Subject: Re: NSPredicateEditorRowTemplate and dynamic templateViews
- From: Peter Ammon <email@hidden>
- Date: Fri, 12 Mar 2010 13:57:11 -0800
On Mar 12, 2010, at 1:47 PM, Dave DeLong wrote:
> Hi everyone,
>
> I'm trying to build a custom predicate editor row template that lets me do predicates like "in the last 30 days" or "since {aDate}". For the simple date comparison, I'm returning an NSDatePicker as the third view in my templateViews.
>
> My problem is that I only want to return the NSDatePicker if the operator is =, !=, <, <=, >, or >=. If the operator is "in the last" (a custom operator), I want to return 4 template views: the first two being the standard keypath + operator views, but the last two being an NSTextField (with NSNumberFormatter attached) and an NSPopUpButton (with the units: days, weeks, months, etc).
>
> I thought that I'd just be able to check which item was selected in the operators popup and return the appropriate views based on the current operator.
>
> Unfortunately, it seems like the predicateEditor invokes templateViews *before* the operator actually changes. In other words, if the operator is =, and I switch it to >=, then when templateViews is invoked, the operators popup still says =, and won't say >= until it's changed again.
>
> So my question is this: how can I dynamically modify my row's templateViews to accurately reflect the current operator? I *could* post a notification from the RowTemplate that the editor needs redrawing, and then have my controller capture that notification and invoke reloadPredicate on my predicate editor, but that seems like a really hackish work-around.
>
> Any recommendations?
>
> (for an example of what I'm describing, try creating a new smart playlist in iTunes and fiddling around with the operators corresponding to the Date Added attribute)
>
> Thanks!
What you want to do here is to create two separate templates. One "looks like" this:
[Creation Date, Modification Date] [=, !=, <, <=, >, >=] {NSDatePicker}
The other looks like this:
[Creation Date, Modification Date] [in the last] {NSTextField} [days, weeks, months]
The first template is responsible for predicates with the standard operators, and the second one is responsible for predicates with the custom operator. At runtime, NSPredicateEditor will merge the templates together, and the second popup will show a union of all the operators of your date templates.
Hope that helps,
-Peter
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden