Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2023)

Unified Diff: chrome/browser/cocoa/bookmark_editor_controller.mm

Issue 160628: On bookmark edit, the OK button is now disabled if the entered URL is... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/bookmark_editor_controller.mm
===================================================================
--- chrome/browser/cocoa/bookmark_editor_controller.mm (revision 22277)
+++ chrome/browser/cocoa/bookmark_editor_controller.mm (working copy)
@@ -72,6 +72,11 @@
[nameField_ setStringValue:initialName_];
[urlField_ setStringValue:initialUrl_];
+ // Get a ping when the URL text changes;
+ // trigger an initial ping to set things up.
+ [urlField_ setDelegate:self];
+ [self controlTextDidChange:nil];
+
if (configuration_ == BookmarkEditor::SHOW_TREE) {
// build the tree et al
NOTIMPLEMENTED();
@@ -119,6 +124,30 @@
[NSApp endSheet:[self window]];
}
+// If possible, return a valid GURL from the URL text field.
+- (GURL)GURLFromUrlField {
+ NSString *url = [urlField_ stringValue];
+ GURL newURL = GURL([url UTF8String]);
+ if (!newURL.is_valid()) {
+ // Mimic observed friendliness from Windows
+ newURL = GURL([[NSString stringWithFormat:@"http://%@", url] UTF8String]);
+ }
+ return newURL;
+}
+
+// When the URL changes we may enable or disable the OK button.
+// We set ourselves as the delegate of urlField_ so this gets called.
+// (Yes, setting ourself as a delegate automatically registers us for
+// the notification.)
+- (void)controlTextDidChange:(NSNotification *)aNotification {
+ GURL newURL = [self GURLFromUrlField];
+ if (newURL.is_valid()) {
+ [okButton_ setEnabled:YES];
+ } else {
+ [okButton_ setEnabled:NO];
+ }
+}
+
// TODO(jrg): Once the tree is available edits may be more extensive
// than just name/url.
- (IBAction)ok:(id)sender {
@@ -128,15 +157,12 @@
if ((![name isEqual:initialName_]) ||
(![url isEqual:initialUrl_])) {
std::wstring newTitle = base::SysNSStringToWide(name);
- GURL newURL = GURL([url UTF8String]);
+ GURL newURL = [self GURLFromUrlField];
if (!newURL.is_valid()) {
- // Mimic observed friendliness from Windows
- newURL = GURL([[NSString stringWithFormat:@"http://%@", url] UTF8String]);
+ // Shouldn't be reached -- OK button disabled if not valid!
+ NOTREACHED();
+ return;
}
- if (!newURL.is_valid()) {
- // Silently ignoring a bad URL is unfriendly.
- newURL = GURL();
- }
int index = 0;
BookmarkModel* model = profile_->GetBookmarkModel();
if (node_) {
@@ -158,6 +184,11 @@
- (void)didEndSheet:(NSWindow*)sheet
returnCode:(int)returnCode
contextInfo:(void*)contextInfo {
+ // This is probably unnecessary but it feels cleaner since the
+ // delegate of a text field can be automatically registered for
+ // notifications.
+ [urlField_ setDelegate:nil];
+
[[self window] orderOut:self];
// BookmarkEditor::Show() will create us then run away. Unusually
@@ -180,7 +211,12 @@
- (void)setDisplayURL:(NSString*)name {
[urlField_ setStringValue:name];
+ [self controlTextDidChange:nil];
}
+- (BOOL)okButtonEnabled {
+ return [okButton_ isEnabled];
+}
+
@end // BookmarkEditorController
« no previous file with comments | « chrome/browser/cocoa/bookmark_editor_controller.h ('k') | chrome/browser/cocoa/bookmark_editor_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698