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

Side by Side Diff: chrome/browser/cocoa/bookmark_editor_controller.mm

Issue 361011: Clean up bookmark_editor_controller to so that is closes consistently as both... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "app/l10n_util.h" 5 #include "app/l10n_util.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/bookmarks/bookmark_editor.h" 9 #include "chrome/browser/bookmarks/bookmark_editor.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 [folderBrowser_ setDoubleAction:@selector(browserDoubleClicked:)]; 165 [folderBrowser_ setDoubleAction:@selector(browserDoubleClicked:)];
166 } 166 }
167 167
168 - (void)windowDidLoad { 168 - (void)windowDidLoad {
169 if (configuration_ == BookmarkEditor::SHOW_TREE) { 169 if (configuration_ == BookmarkEditor::SHOW_TREE) {
170 // Find and select the |parent| bookmark node in the folder tree browser. 170 // Find and select the |parent| bookmark node in the folder tree browser.
171 [self selectNodeInBrowser:parentNode_]; 171 [self selectNodeInBrowser:parentNode_];
172 } 172 }
173 } 173 }
174 174
175 - (void)windowWillClose:(NSNotification *)notification {
176 // If a folder name cell is being edited then force it to end editing
177 // so that any changes are recorded.
178 [[self window] makeFirstResponder:nil];
179
180 // This is probably unnecessary but it feels cleaner since the
181 // delegate of a text field can be automatically registered for
182 // notifications.
183 [nameField_ setDelegate:nil];
184 [urlField_ setDelegate:nil];
185 [self autorelease];
186 }
187
175 /* TODO(jrg): 188 /* TODO(jrg):
176 // Implementing this informal protocol allows us to open the sheet 189 // Implementing this informal protocol allows us to open the sheet
177 // somewhere other than at the top of the window. NOTE: this means 190 // somewhere other than at the top of the window. NOTE: this means
178 // that I, the controller, am also the window's delegate. 191 // that I, the controller, am also the window's delegate.
179 - (NSRect)window:(NSWindow*)window willPositionSheet:(NSWindow*)sheet 192 - (NSRect)window:(NSWindow*)window willPositionSheet:(NSWindow*)sheet
180 usingRect:(NSRect)rect { 193 usingRect:(NSRect)rect {
181 // adjust rect.origin.y to be the bottom of the toolbar 194 // adjust rect.origin.y to be the bottom of the toolbar
182 return rect; 195 return rect;
183 } 196 }
184 */ 197 */
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 254 }
242 255
243 #pragma mark New Folder Handler & Folder Cell Editing 256 #pragma mark New Folder Handler & Folder Cell Editing
244 257
245 - (void)editFolderNameInCell:(BookmarkTreeBrowserCell*)cell { 258 - (void)editFolderNameInCell:(BookmarkTreeBrowserCell*)cell {
246 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]); 259 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
247 [cell setEditable:YES]; 260 [cell setEditable:YES];
248 [cell setTarget:self]; 261 [cell setTarget:self];
249 [cell setAction:@selector(cellEditingCompleted:)]; 262 [cell setAction:@selector(cellEditingCompleted:)];
250 [cell setSendsActionOnEndEditing:YES]; 263 [cell setSendsActionOnEndEditing:YES];
251 currentEditCell_.reset([cell retain]);
252 NSMatrix* matrix = [cell matrix]; 264 NSMatrix* matrix = [cell matrix];
253 // Set the delegate so that we get called when editing wants to complete. 265 // Set the delegate so that we get called when editing wants to complete.
254 [matrix setDelegate:self]; 266 [matrix setDelegate:self];
255 [matrix selectText:self]; 267 [matrix selectText:self];
256 } 268 }
257 269
258 - (void)cellEditingCompleted:(id)sender { 270 - (void)cellEditingCompleted:(id)sender {
259 DCHECK([sender isKindOfClass:[NSMatrix class]]); 271 DCHECK([sender isKindOfClass:[NSMatrix class]]);
260 BookmarkTreeBrowserCell* cell = [sender selectedCell]; 272 BookmarkTreeBrowserCell* cell = [sender selectedCell];
261 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]); 273 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
262 [self saveFolderNameForCell:cell]; 274 [self saveFolderNameForCell:cell];
263 } 275 }
264 276
265 - (void)saveFolderNameForCell:(BookmarkTreeBrowserCell*)cell { 277 - (void)saveFolderNameForCell:(BookmarkTreeBrowserCell*)cell {
266 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]); 278 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
267 // It's possible that the cell can get reused so clean things up 279 // It's possible that the cell can get reused so clean things up
268 // to prevent inadvertant notifications. 280 // to prevent inadvertant notifications.
269 [cell setTarget:nil]; 281 [cell setTarget:nil];
270 [cell setAction:nil]; 282 [cell setAction:nil];
271 [cell setEditable:NO]; 283 [cell setEditable:NO];
272 [cell setSendsActionOnEndEditing:NO]; 284 [cell setSendsActionOnEndEditing:NO];
273 // Force a responder change here to force the editing of the cell's text 285 // Force a responder change here to force the editing of the cell's text
274 // to complete otherwise the call to -[cell title] could return stale text. 286 // to complete otherwise the call to -[cell title] could return stale text.
275 [[folderBrowser_ window] makeFirstResponder:folderBrowser_]; 287 [[folderBrowser_ window] makeFirstResponder:folderBrowser_];
276 const BookmarkNode* bookmarkNode = [cell bookmarkNode]; 288 const BookmarkNode* bookmarkNode = [cell bookmarkNode];
277 BookmarkModel* model = profile_->GetBookmarkModel(); 289 BookmarkModel* model = profile_->GetBookmarkModel();
278 NSString* newTitle = [cell title]; 290 NSString* newTitle = [cell title];
279 model->SetTitle(bookmarkNode, base::SysNSStringToWide(newTitle)); 291 model->SetTitle(bookmarkNode, base::SysNSStringToWide(newTitle));
280 currentEditCell_.reset();
281 } 292 }
282 293
283 - (void)browserDoubleClicked:(id)sender { 294 - (void)browserDoubleClicked:(id)sender {
284 BookmarkTreeBrowserCell* cell = [folderBrowser_ selectedCell]; 295 BookmarkTreeBrowserCell* cell = [folderBrowser_ selectedCell];
285 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]); 296 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
286 [self editFolderNameInCell:cell]; 297 [self editFolderNameInCell:cell];
287 } 298 }
288 299
289 - (IBAction)newFolder:(id)sender { 300 - (IBAction)newFolder:(id)sender {
290 BookmarkModel* model = profile_->GetBookmarkModel(); 301 BookmarkModel* model = profile_->GetBookmarkModel();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 [NSApp endSheet:[self window]]; 372 [NSApp endSheet:[self window]];
362 } 373 }
363 374
364 - (IBAction)cancel:(id)sender { 375 - (IBAction)cancel:(id)sender {
365 [NSApp endSheet:[self window]]; 376 [NSApp endSheet:[self window]];
366 } 377 }
367 378
368 - (void)didEndSheet:(NSWindow*)sheet 379 - (void)didEndSheet:(NSWindow*)sheet
369 returnCode:(int)returnCode 380 returnCode:(int)returnCode
370 contextInfo:(void*)contextInfo { 381 contextInfo:(void*)contextInfo {
371 // If a folder name cell is being edited then force it to end editing 382 [sheet close];
372 // so that any changes are recorded.
373 BookmarkTreeBrowserCell* currentEditCell = currentEditCell_.get();
374 if (currentEditCell) {
375 [self saveFolderNameForCell:currentEditCell];
376 currentEditCell_.reset();
377 }
378 // This is probably unnecessary but it feels cleaner since the
379 // delegate of a text field can be automatically registered for
380 // notifications.
381 [nameField_ setDelegate:nil];
382 [urlField_ setDelegate:nil];
383
384 [[self window] orderOut:self];
385
386 // BookmarkEditor::Show() will create us then run away. Unusually
387 // for a controller, we are responsible for deallocating ourself.
388 [self autorelease];
389 } 383 }
390 384
391 #pragma mark For Unit Test Use Only 385 #pragma mark For Unit Test Use Only
392 386
393 - (NSString*)displayName { 387 - (NSString*)displayName {
394 return [nameField_ stringValue]; 388 return [nameField_ stringValue];
395 } 389 }
396 390
397 - (NSString*)displayURL { 391 - (NSString*)displayURL {
398 return [urlField_ stringValue]; 392 return [urlField_ stringValue];
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 DCHECK(childNode); 457 DCHECK(childNode);
464 BookmarkTreeBrowserCell* browserCell = 458 BookmarkTreeBrowserCell* browserCell =
465 static_cast<BookmarkTreeBrowserCell*>(cell); 459 static_cast<BookmarkTreeBrowserCell*>(cell);
466 [browserCell setTitle:base::SysWideToNSString(childNode->GetTitle())]; 460 [browserCell setTitle:base::SysWideToNSString(childNode->GetTitle())];
467 [browserCell setBookmarkNode:childNode]; 461 [browserCell setBookmarkNode:childNode];
468 [browserCell setMatrix:[folderBrowser_ matrixInColumn:column]]; 462 [browserCell setMatrix:[folderBrowser_ matrixInColumn:column]];
469 } 463 }
470 464
471 @end // BookmarkEditorController 465 @end // BookmarkEditorController
472 466
OLDNEW
« 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