| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/mac_util.h" | 6 #include "base/mac_util.h" |
| 7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_editor.h" | 8 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 std::string url_string = node_->GetURL().possibly_invalid_spec(); | 60 std::string url_string = node_->GetURL().possibly_invalid_spec(); |
| 61 initialUrl_.reset([[NSString stringWithUTF8String:url_string.c_str()] | 61 initialUrl_.reset([[NSString stringWithUTF8String:url_string.c_str()] |
| 62 retain]); | 62 retain]); |
| 63 } else { | 63 } else { |
| 64 initialName_.reset([@"" retain]); | 64 initialName_.reset([@"" retain]); |
| 65 initialUrl_.reset([@"" retain]); | 65 initialUrl_.reset([@"" retain]); |
| 66 } | 66 } |
| 67 [nameField_ setStringValue:initialName_]; | 67 [nameField_ setStringValue:initialName_]; |
| 68 [urlField_ setStringValue:initialUrl_]; | 68 [urlField_ setStringValue:initialUrl_]; |
| 69 | 69 |
| 70 // Get a ping when the URL text changes; | 70 // Get a ping when the URL or name text fields change; |
| 71 // trigger an initial ping to set things up. | 71 // trigger an initial ping to set things up. |
| 72 [nameField_ setDelegate:self]; |
| 72 [urlField_ setDelegate:self]; | 73 [urlField_ setDelegate:self]; |
| 73 [self controlTextDidChange:nil]; | 74 [self controlTextDidChange:nil]; |
| 74 | 75 |
| 75 if (configuration_ == BookmarkEditor::SHOW_TREE) { | 76 if (configuration_ == BookmarkEditor::SHOW_TREE) { |
| 76 // build the tree et al | 77 // build the tree et al |
| 77 NOTIMPLEMENTED(); | 78 NOTIMPLEMENTED(); |
| 78 } else { | 79 } else { |
| 79 // Remember the NSBrowser's height; we will shrink our frame by that | 80 // Remember the NSBrowser's height; we will shrink our frame by that |
| 80 // much. | 81 // much. |
| 81 NSRect frame = [[self window] frame]; | 82 NSRect frame = [[self window] frame]; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 130 } |
| 130 return newURL; | 131 return newURL; |
| 131 } | 132 } |
| 132 | 133 |
| 133 // When the URL changes we may enable or disable the OK button. | 134 // When the URL changes we may enable or disable the OK button. |
| 134 // We set ourselves as the delegate of urlField_ so this gets called. | 135 // We set ourselves as the delegate of urlField_ so this gets called. |
| 135 // (Yes, setting ourself as a delegate automatically registers us for | 136 // (Yes, setting ourself as a delegate automatically registers us for |
| 136 // the notification.) | 137 // the notification.) |
| 137 - (void)controlTextDidChange:(NSNotification *)aNotification { | 138 - (void)controlTextDidChange:(NSNotification *)aNotification { |
| 138 GURL newURL = [self GURLFromUrlField]; | 139 GURL newURL = [self GURLFromUrlField]; |
| 139 if (newURL.is_valid()) { | 140 NSString* name = [nameField_ stringValue]; |
| 141 |
| 142 // if empty or only whitespace, name is not valid. |
| 143 bool name_valid = true; |
| 144 if (([name length] == 0) || |
| 145 ([[name stringByTrimmingCharactersInSet:[NSCharacterSet |
| 146 whitespaceAndNewlineCharacterSet]] length] == 0)) { |
| 147 name_valid = false; |
| 148 } |
| 149 |
| 150 if (newURL.is_valid() && name_valid) { |
| 140 [okButton_ setEnabled:YES]; | 151 [okButton_ setEnabled:YES]; |
| 141 } else { | 152 } else { |
| 142 [okButton_ setEnabled:NO]; | 153 [okButton_ setEnabled:NO]; |
| 143 } | 154 } |
| 144 } | 155 } |
| 145 | 156 |
| 146 // TODO(jrg): Once the tree is available edits may be more extensive | 157 // TODO(jrg): Once the tree is available edits may be more extensive |
| 147 // than just name/url. | 158 // than just name/url. |
| 148 - (IBAction)ok:(id)sender { | 159 - (IBAction)ok:(id)sender { |
| 149 NSString *name = [nameField_ stringValue]; | 160 NSString *name = [nameField_ stringValue]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 175 | 186 |
| 176 [NSApp endSheet:[self window]]; | 187 [NSApp endSheet:[self window]]; |
| 177 } | 188 } |
| 178 | 189 |
| 179 - (void)didEndSheet:(NSWindow*)sheet | 190 - (void)didEndSheet:(NSWindow*)sheet |
| 180 returnCode:(int)returnCode | 191 returnCode:(int)returnCode |
| 181 contextInfo:(void*)contextInfo { | 192 contextInfo:(void*)contextInfo { |
| 182 // This is probably unnecessary but it feels cleaner since the | 193 // This is probably unnecessary but it feels cleaner since the |
| 183 // delegate of a text field can be automatically registered for | 194 // delegate of a text field can be automatically registered for |
| 184 // notifications. | 195 // notifications. |
| 196 [nameField_ setDelegate:nil]; |
| 185 [urlField_ setDelegate:nil]; | 197 [urlField_ setDelegate:nil]; |
| 186 | 198 |
| 187 [[self window] orderOut:self]; | 199 [[self window] orderOut:self]; |
| 188 | 200 |
| 189 // BookmarkEditor::Show() will create us then run away. Unusually | 201 // BookmarkEditor::Show() will create us then run away. Unusually |
| 190 // for a controller, we are responsible for deallocating ourself. | 202 // for a controller, we are responsible for deallocating ourself. |
| 191 [self autorelease]; | 203 [self autorelease]; |
| 192 } | 204 } |
| 193 | 205 |
| 194 | 206 |
| 195 - (NSString*)displayName { | 207 - (NSString*)displayName { |
| 196 return [nameField_ stringValue]; | 208 return [nameField_ stringValue]; |
| 197 } | 209 } |
| 198 | 210 |
| 199 - (NSString*)displayURL { | 211 - (NSString*)displayURL { |
| 200 return [urlField_ stringValue]; | 212 return [urlField_ stringValue]; |
| 201 } | 213 } |
| 202 | 214 |
| 203 - (void)setDisplayName:(NSString*)name { | 215 - (void)setDisplayName:(NSString*)name { |
| 204 [nameField_ setStringValue:name]; | 216 [nameField_ setStringValue:name]; |
| 217 [self controlTextDidChange:nil]; |
| 205 } | 218 } |
| 206 | 219 |
| 207 - (void)setDisplayURL:(NSString*)name { | 220 - (void)setDisplayURL:(NSString*)name { |
| 208 [urlField_ setStringValue:name]; | 221 [urlField_ setStringValue:name]; |
| 209 [self controlTextDidChange:nil]; | 222 [self controlTextDidChange:nil]; |
| 210 } | 223 } |
| 211 | 224 |
| 212 - (BOOL)okButtonEnabled { | 225 - (BOOL)okButtonEnabled { |
| 213 return [okButton_ isEnabled]; | 226 return [okButton_ isEnabled]; |
| 214 } | 227 } |
| 215 | 228 |
| 216 @end // BookmarkEditorController | 229 @end // BookmarkEditorController |
| 217 | 230 |
| OLD | NEW |