Re: NSPredicateEditorRowTemplate and NSTokenField
Re: NSPredicateEditorRowTemplate and NSTokenField
- Subject: Re: NSPredicateEditorRowTemplate and NSTokenField
- From: Vitaly Ovchinnikov <email@hidden>
- Date: Sat, 31 Jan 2009 10:43:14 +0300
I finally found a solution that seems to work. I subclassed NSTokenField:
======================
@implementation MyTokenField
- (void) notifyTarget: (id) sender {
NSControl *t = [self target];
[t sendAction:nil to:t];
}
- (void)textDidEndEditing:(NSNotification *)aNotification {
[super textDidEndEditing:aNotification];
[self performSelector:@selector(notifyTarget:) withObject:self
afterDelay:0];
}
@end
======================
-textDidEndEditing gets called after I change something, I send
nil-action to the predicate editor and it finally calls my observer.
The only problem is that it needs some time to build predcate, so I
call it with delay.
The only thing I can't understand is why do I need to call
[t sendAction:nil to:t]
and can't call
[self sendAction:nil to:t]
the second line doesn't work (observer doesn't get called). Who should
be " sender" of the action for predicate editor? Control? Row
template?
On Fri, Jan 30, 2009 at 11:21 AM, Vitaly Ovchinnikov
<email@hidden> wrote:
>
> Hello all, that's me again with my predicate editor problems :)
>
> I subclassed predicate editor's row and replaced default text editor
> with my NSTokenField in -templateViews.
>
> Predicates, that match my template, look like: ANY Tags IN {"tag1",
> "tag2", "tag3"}
>
> In -setPredicate I fill token field with tags from predicate:
> NSExpression *right = .....;
> [pMyTokenField setObjectValue:[right constantValue]];
>
> In -predicateWithSubPredicates I create predicate described above with
> right part from my token field. I added traces there and it builds
> exactly what I need.
>
> Now, the problem: I added observer to the predicate that I edit and it
> gets called at every change of predicate, but not for my token field
> template!
>
> Predicate editor has several rows, some of them are "standard" -
> numeric, text etc. If I change any of them - my observer gets called.
> If I edit my token field, observer doesn't get called at all. If I add
> some token and switch focus to another row, predicate editor calls
> -predicateWithSubPredicate, I build correct predicate and... nothing.
> Observer doesn't get called. If I press "Enter" after adding token -
> observer will be called. If I switch to some other row (not with my
> template) and then switch back - observer will be called. If I switch
> to another row with the same template and when switch back - observer
> will not be called.
>
> I added one more control to the row - a button. It does nothing, just
> takes some place. I can change my token fields and observer will not
> be called. But if I press this button - observer will be called
> immediately.
>
> I tried to override -rightExpressions method and return my list of
> tags, I tried to call -will/didChangeValueForKey: - nothing helped. It
> seems that I need to notify somebody about the change, but have no
> idea - how to do that?
>
> Please, help me :)
>
> P.S.: Things are a bit more complex, I have Filter objects, that hold
> predicates. Predicate editor is bound to the filter and my observer
> observes those filters, not the predicates themselves. I tell this to
> cut ideas about incorrect observing. Observing works perfect for any
> other row.
_______________________________________________
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