Fixed: token field autocomplete menu remaining after window closed.

Without this change, closing the window containing a token field showing an autocomplete menu would result in a detached autocomplete menu hanging around.

This fix checks for window close notifications and makes sure to dismiss the menu if the window closes.
This commit is contained in:
Alexander Ljungberg
2012-12-21 15:00:20 +00:00
parent 9705f1fe28
commit 8f8f1a0224
2 changed files with 27 additions and 1 deletions
+5
View File
@@ -651,6 +651,9 @@ var CPViewFlags = { },
if (_window === aWindow)
return;
// Unlike in Cocoa you can observe the window of a view.
[self willChangeValueForKey:@"window"];
[[self window] _dirtyKeyViewLoop];
// Clear out first responder if we're the first responder and leaving.
@@ -678,6 +681,8 @@ var CPViewFlags = { },
[self viewDidMoveToWindow];
[[self window] _dirtyKeyViewLoop];
[self didChangeValueForKey:@"window"];
}
/*!
+22 -1
View File
@@ -38,6 +38,7 @@ var _CPAutocompleteMenuMaximumHeight = 307;
float widestItemWidth;
CPWindow _menuWindow;
CPWindow _parentWindow @accessors(property=parentWindow);
CPScrollView scrollView;
CPTableView tableView;
@@ -48,7 +49,8 @@ var _CPAutocompleteMenuMaximumHeight = 307;
{
if (self = [super init])
{
textField = aTextField;
[self bind:@"parentWindow" toObject:self withKeyPath:@"textField.window" options:nil];
[self setTextField:aTextField];
_menuWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0, 0, 100, 100) styleMask:CPBorderlessWindowMask];
@@ -258,6 +260,25 @@ var _CPAutocompleteMenuMaximumHeight = 307;
[textField _complete:self];
}
- (void)setParentWindow:(CPWindow)aWindow
{
if (aWindow === _parentWindow)
return;
if (_parentWindow)
[[CPNotificationCenter defaultCenter] removeObserver:self];
_parentWindow = aWindow;
if (_parentWindow)
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(parentWindowWillClose:) name:CPWindowWillCloseNotification object:_parentWindow];
}
- (void)parentWindowWillClose:(CPNotification)aNotification
{
[self _hideCompletions];
}
@end