diff options
Diffstat (limited to 'chrome/browser/cocoa/bookmark_editor_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_editor_controller.mm | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/bookmark_editor_controller.mm b/chrome/browser/cocoa/bookmark_editor_controller.mm index 79cd1dc..bfa8156 100644 --- a/chrome/browser/cocoa/bookmark_editor_controller.mm +++ b/chrome/browser/cocoa/bookmark_editor_controller.mm @@ -67,8 +67,9 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd, [nameField_ setStringValue:initialName_]; [urlField_ setStringValue:initialUrl_]; - // Get a ping when the URL text changes; + // Get a ping when the URL or name text fields change; // trigger an initial ping to set things up. + [nameField_ setDelegate:self]; [urlField_ setDelegate:self]; [self controlTextDidChange:nil]; @@ -136,7 +137,17 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd, // the notification.) - (void)controlTextDidChange:(NSNotification *)aNotification { GURL newURL = [self GURLFromUrlField]; - if (newURL.is_valid()) { + NSString* name = [nameField_ stringValue]; + + // if empty or only whitespace, name is not valid. + bool name_valid = true; + if (([name length] == 0) || + ([[name stringByTrimmingCharactersInSet:[NSCharacterSet + whitespaceAndNewlineCharacterSet]] length] == 0)) { + name_valid = false; + } + + if (newURL.is_valid() && name_valid) { [okButton_ setEnabled:YES]; } else { [okButton_ setEnabled:NO]; @@ -182,6 +193,7 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd, // This is probably unnecessary but it feels cleaner since the // delegate of a text field can be automatically registered for // notifications. + [nameField_ setDelegate:nil]; [urlField_ setDelegate:nil]; [[self window] orderOut:self]; @@ -202,6 +214,7 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd, - (void)setDisplayName:(NSString*)name { [nameField_ setStringValue:name]; + [self controlTextDidChange:nil]; } - (void)setDisplayURL:(NSString*)name { |