Re: NSPredicateEditorRowTemplate and dynamic popups
Re: NSPredicateEditorRowTemplate and dynamic popups
- Subject: Re: NSPredicateEditorRowTemplate and dynamic popups
- From: Jim Turner <email@hidden>
- Date: Fri, 13 Nov 2009 16:35:06 -0600
Try this:
Create an outlet to your row template. When you need to update the
popups, make a copy of that template. Make a copy of the rowTemplates
the predicate editor currently tracks and iterate over them replacing
the template in the list that is the same class as your custom
template. Then set this new list of templates back onto the predicate
editor.
The net effect is that the predicate editor will rebuild all the
templates it's currently using which gives you a chance to update the
popups as needed. I don't know what'll happen when the popup
transitions to/from the text field... there's little you can do with
that as its an optimization the predicate editor does when building
it's templates (if there's only one option, why offer a choice?)
cheap-n-dirty code sample
-(void) updateTemplates {
MyRowTemplate *_newTemplate = [[myRowTemplateOutlet copy] autorelease];
NSMutableArray *rowTemplates = [[[predicateEditor rowTemplates]
mutableCopy] autorelease];
NSInteger ctr;
for( ctr=0; ctr<[rowTemplates count]; ctr++ ) {
if( [[rowTemplates objectAtIndex:ctr] isKindOfClass:[MyRowTemplate class]] ) {
[rowTemplates replaceObjectAtIndex:ctr withObject:_newTemplate];
break;
}
}
[predicateEditor setRowTemplates:rowTemplates];
}
--
Jim
http://nukethemfromorbit.com
On Fri, Nov 13, 2009 at 10:48 AM, Dave DeLong <email@hidden> wrote:
> Hi everyone,
>
> I have an NSPredicateEditor, with some standard row templates. I'd like to add a custom row template with three views: a popup button (indicating the attributes this template references), a second popup button (with the operators), and a third popup button that's populated with a list of possible values.
>
> This is very similar to a regular row template, except that the list of possible values is computed at runtime and can change periodically based on system events.
>
> I've tried subclassing NSPredicateEditorRowTemplate, overriding -templateViews, and returning my 3 popup buttons (all properly populated). This works once, but after the row is created, I haven't been able to figure out how to repopulate the popup button when the list of possible values changes. I've tried setting the popup button's menu's delegate to an object that will repopulate it, but the delegate methods are never called.
>
> I've also seen that when there's only one possible value, my popup button is replaced with a textfield. I suppose that's OK, except that if the list of possible values changes, I need that textfield to change to a popup button.
>
> How can I achieve my dynamic popup button in an NSPredicateEditorRowTemplate?
>
> Thanks!
>
> Dave DeLong
> _______________________________________________
>
> 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
>
_______________________________________________
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