Chromium Code Reviews| Index: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| index 2c8a22324cf495473a723774790156fe4271c5b1..778c52720052cf52dbac71fc10c28f2e06ddf797 100644 |
| --- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| +++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm |
| @@ -618,7 +618,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| @end |
| // A custom text control that turns into a textfield for editing when clicked. |
| -@interface EditableProfileNameButton : HoverImageButton { |
| +@interface EditableProfileNameButton : HoverImageButton<NSTextFieldDelegate> { |
| @private |
| base::scoped_nsobject<NSTextField> profileNameTextField_; |
| Profile* profile_; // Weak. |
| @@ -635,7 +635,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| - (void)showEditableView:(id)sender; |
| // Called when enter is pressed in the text field. |
| -- (void)saveProfileName:(id)sender; |
| +- (void)saveProfileName; |
| @end |
| @@ -691,8 +691,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| NSLineBreakByTruncatingTail]; |
| [[profileNameTextField_ cell] setUsesSingleLineMode:YES]; |
| [self addSubview:profileNameTextField_]; |
| - [profileNameTextField_ setTarget:self]; |
| - [profileNameTextField_ setAction:@selector(saveProfileName:)]; |
| + [profileNameTextField_ setDelegate:self]; |
| // Hide the textfield until the user clicks on the button. |
| [profileNameTextField_ setHidden:YES]; |
| @@ -719,21 +718,22 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| return self; |
| } |
| -- (void)saveProfileName:(id)sender { |
| +- (void)saveProfileName { |
| base::string16 newProfileName = |
| base::SysNSStringToUTF16([profileNameTextField_ stringValue]); |
| - // Empty profile names are not allowed, and are treated as a cancel. |
| + // Empty profile names are not allowed, and do nothing. |
| base::TrimWhitespace(newProfileName, base::TRIM_ALL, &newProfileName); |
| if (!newProfileName.empty()) { |
| profiles::UpdateProfileName(profile_, newProfileName); |
| [controller_ |
| postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME]; |
| - } else { |
| - // Since the text is empty and not allowed, revert it from the textbox. |
| - [profileNameTextField_ setStringValue:[self title]]; |
| + [profileNameTextField_ setHidden:YES]; |
| + // Somehow this doesn't work if it's not async. Might need improving. |
|
groby-ooo-7-16
2015/02/27 23:32:37
I don't think I'm OK with code that is based on "s
|
| + dispatch_async(dispatch_get_main_queue(), ^{ |
| + [[self window] makeFirstResponder:nil]; |
| + }); |
| } |
| - [profileNameTextField_ setHidden:YES]; |
| } |
| - (void)showEditableView:(id)sender { |
| @@ -745,6 +745,10 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| return false; |
| } |
| +- (void)controlTextDidEndEditing:(NSNotification*)notification { |
| + [self saveProfileName]; |
| +} |
| + |
| @end |
| // A custom button that allows for setting a background color when hovered over. |