CPSearchField: register for textDidChange notifications instead of hijacking the delegate. Post the notification in -canCelOperation: (triggered by escape key OR cancel button). Fixes issue #1160

This commit is contained in:
cacaodev
2011-03-17 01:18:25 -04:00
committed by Randall Luecke
parent a3e70a56c5
commit d5b2ccbc30
2 changed files with 13 additions and 4 deletions
+6 -4
View File
@@ -109,8 +109,9 @@ var RECENT_SEARCH_PREFIX = @" ";
[self setBezelStyle:CPTextFieldRoundedBezel];
[self setBordered:YES];
[self setEditable:YES];
[self setDelegate:self];
[self setContinuous:YES];
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_searchFieldTextDidChange:) name:CPControlTextDidChangeNotification object:self];
var bounds = [self bounds],
cancelButton = [[CPButton alloc] initWithFrame:[self cancelButtonRectForBounds:bounds]],
@@ -198,7 +199,7 @@ var RECENT_SEARCH_PREFIX = @" ";
/*!
Resets the cancel button to its default attributes.
This method resets the target, action, regular image, and pressed image. By default, when users click the cancel button, the delete: action message is sent up the responder chain. This method gives you a way to customize the cancel button for specific situations and then reset the button defaults without having to undo changes individually.
This method resets the target, action, regular image, and pressed image. This method gives you a way to customize the cancel button for specific situations and then reset the button defaults without having to undo changes individually.
*/
- (void)resetCancelButton
{
@@ -420,7 +421,7 @@ var RECENT_SEARCH_PREFIX = @" ";
[_cancelButton setHidden:([[self stringValue] length] === 0)];
}
- (void)controlTextDidChange:(CPNotification)aNotification
- (void)_searchFieldTextDidChange:(CPNotification)aNotification
{
if (![self sendsWholeSearchString])
{
@@ -680,7 +681,8 @@ var RECENT_SEARCH_PREFIX = @" ";
- (void)cancelOperation:(id)sender
{
[self setObjectValue:@""];
[self _sendPartialString];
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
[self _updateCancelButtonVisibility];
}
@@ -73,11 +73,18 @@ var categories = ["firstName","lastName"],
[self changeCategory:[[searchField menu] itemAtIndex:1]];
[self updateFilter:searchField];
[searchField setDelegate:self];
[theWindow center];
[theWindow orderFront:self];
}
- (void)controlTextDidChange:(id)note
{
CPLogConsole(_cmd);
}
- (void)awakeFromCib
{
[theWindow setBackgroundColor:[CPColor colorWithHexString:@"f3f4f5"]];