From 69c004093dbed31ca17cce7bdf90b08a6ff2311e Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Tue, 23 Nov 2010 10:47:59 -0800 Subject: [PATCH] CPTokenField did not send its action on end edit. Also fixes that the CPNotification sent out was CPControlTextDidBeginEditingNotification, not CPControlTextDidEndEditingNotification. --- AppKit/CPTokenField.j | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index 0e3c99ef7..8a6e00ce4 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -79,6 +79,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", CPEvent _mouseDownEvent; BOOL _preventResign; + BOOL _shouldNotifyTarget; } + (CPCharacterSet)defaultTokenizingCharacterSet @@ -208,10 +209,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", [self _inputElement].value = @""; [self setNeedsLayout]; - var theBinding = [CPKeyValueBinding getBinding:CPValueBinding forObject:self]; - - if (theBinding) - [theBinding reverseSetValueFor:@"objectValue"]; + [self _controlTextDidChange]; } - (void)_autocomplete @@ -271,6 +269,8 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", [theBinding reverseSetValueFor:@"objectValue"]; [self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]]; + + _shouldNotifyTarget = YES; } - (void)_removeSelectedTokens:(id)sender @@ -401,7 +401,14 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", [self setNeedsLayout]; - [self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]]; + if (_shouldNotifyTarget) + { + _shouldNotifyTarget = NO; + [self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]]; + + if ([self sendsActionOnEndEditing]) + [self sendAction:[self action] to:[self target]]; + } return YES; } @@ -554,6 +561,12 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", [self setNeedsDisplay:YES]; } +- (void)sendAction:(SEL)anAction to:(id)anObject +{ + _shouldNotifyTarget = NO; + [super sendAction:anAction to:anObject]; +} + // Incredible hack to disable supers implementation // so it cannot change our object value and break the tokenfield - (void)_setStringValue:(id)aValue