OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" |
6 | 6 |
7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_model_observer_for_cocoa.h" | 10 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_model_observer_for_cocoa.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 modalDelegate:self | 81 modalDelegate:self |
82 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) | 82 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) |
83 contextInfo:nil]; | 83 contextInfo:nil]; |
84 } | 84 } |
85 | 85 |
86 - (IBAction)cancel:(id)sender { | 86 - (IBAction)cancel:(id)sender { |
87 [NSApp endSheet:[self window]]; | 87 [NSApp endSheet:[self window]]; |
88 } | 88 } |
89 | 89 |
90 - (IBAction)ok:(id)sender { | 90 - (IBAction)ok:(id)sender { |
91 NSString* name = [nameField_ stringValue]; | |
92 BookmarkModel* model = profile_->GetBookmarkModel(); | 91 BookmarkModel* model = profile_->GetBookmarkModel(); |
92 NSMutableString* name = | |
93 [[NSMutableString alloc] initWithString:[nameField_ stringValue]]; | |
94 | |
95 // Replace occurrences of multiple newlines with single newlines. | |
96 while (NSNotFound != [name rangeOfString:@"\n\n"].location) { | |
97 [name replaceOccurrencesOfString:@"\n\n" | |
98 withString:@"\n" | |
99 options:0 | |
100 range:NSMakeRange(0, [name length])]; | |
101 } | |
102 | |
103 // Replace single newlines with single spaces. | |
104 [name replaceOccurrencesOfString:@"\n" | |
105 withString:@" " | |
106 options:0 | |
107 range:NSMakeRange(0, [name length])]; | |
108 | |
109 // Make the clean string immutable again and release the mutable object. | |
110 NSString* clean_name = [name copy]; | |
111 [name release]; | |
112 | |
93 if (node_) { | 113 if (node_) { |
94 model->SetTitle(node_, base::SysNSStringToUTF16(name)); | 114 model->SetTitle(node_, base::SysNSStringToUTF16(clean_name)); |
Ilya Sherman
2011/11/18 22:51:29
Since I don't think our other platforms can displa
| |
95 } else { | 115 } else { |
96 model->AddFolder(parent_, | 116 model->AddFolder(parent_, |
97 newIndex_, | 117 newIndex_, |
98 base::SysNSStringToUTF16(name)); | 118 base::SysNSStringToUTF16(clean_name)); |
99 } | 119 } |
120 | |
100 [NSApp endSheet:[self window]]; | 121 [NSApp endSheet:[self window]]; |
101 } | 122 } |
102 | 123 |
103 - (void)didEndSheet:(NSWindow*)sheet | 124 - (void)didEndSheet:(NSWindow*)sheet |
104 returnCode:(int)returnCode | 125 returnCode:(int)returnCode |
105 contextInfo:(void*)contextInfo { | 126 contextInfo:(void*)contextInfo { |
106 [[self window] orderOut:self]; | 127 [[self window] orderOut:self]; |
107 observer_.reset(NULL); | 128 observer_.reset(NULL); |
108 [self autorelease]; | 129 [self autorelease]; |
109 } | 130 } |
110 | 131 |
111 - (NSString*)folderName { | 132 - (NSString*)folderName { |
112 return [nameField_ stringValue]; | 133 return [nameField_ stringValue]; |
113 } | 134 } |
114 | 135 |
115 - (void)setFolderName:(NSString*)name { | 136 - (void)setFolderName:(NSString*)name { |
116 [nameField_ setStringValue:name]; | 137 [nameField_ setStringValue:name]; |
117 } | 138 } |
118 | 139 |
119 - (NSButton*)okButton { | 140 - (NSButton*)okButton { |
120 return okButton_; | 141 return okButton_; |
121 } | 142 } |
122 | 143 |
123 @end // BookmarkNameFolderController | 144 @end // BookmarkNameFolderController |
OLD | NEW |