OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stack> | 5 #include <stack> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.h" | 7 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.h" |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller.h" | 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller.h" |
17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_cell_single_line.h" | 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_cell_single_line.h" |
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_tree_browser_cell.h" | 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_tree_browser_cell.h" |
20 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 21 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/l10n/l10n_util_mac.h" | 24 #include "ui/base/l10n/l10n_util_mac.h" |
24 | 25 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; | 291 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
291 } | 292 } |
292 | 293 |
293 - (void)windowWillClose:(NSNotification*)notification { | 294 - (void)windowWillClose:(NSNotification*)notification { |
294 [self autorelease]; | 295 [self autorelease]; |
295 } | 296 } |
296 | 297 |
297 #pragma mark Folder Tree Management | 298 #pragma mark Folder Tree Management |
298 | 299 |
299 - (BookmarkModel*)bookmarkModel { | 300 - (BookmarkModel*)bookmarkModel { |
300 return profile_->GetBookmarkModel(); | 301 return BookmarkModelFactory::GetForProfile(profile_); |
301 } | 302 } |
302 | 303 |
303 - (Profile*)profile { | 304 - (Profile*)profile { |
304 return profile_; | 305 return profile_; |
305 } | 306 } |
306 | 307 |
307 - (const BookmarkNode*)parentNode { | 308 - (const BookmarkNode*)parentNode { |
308 return parentNode_; | 309 return parentNode_; |
309 } | 310 } |
310 | 311 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 [self willChangeValueForKey:@"okEnabled"]; | 430 [self willChangeValueForKey:@"okEnabled"]; |
430 [self setTableSelectionPath:selectionPath]; | 431 [self setTableSelectionPath:selectionPath]; |
431 [self didChangeValueForKey:@"okEnabled"]; | 432 [self didChangeValueForKey:@"okEnabled"]; |
432 } | 433 } |
433 | 434 |
434 - (NSIndexPath*)selectionPathForNode:(const BookmarkNode*)desiredNode { | 435 - (NSIndexPath*)selectionPathForNode:(const BookmarkNode*)desiredNode { |
435 // Back up the parent chaing for desiredNode, building up a stack | 436 // Back up the parent chaing for desiredNode, building up a stack |
436 // of ancestor nodes. Then crawl down the folderTreeArray looking | 437 // of ancestor nodes. Then crawl down the folderTreeArray looking |
437 // for each ancestor in order while building up the selectionPath. | 438 // for each ancestor in order while building up the selectionPath. |
438 std::stack<const BookmarkNode*> nodeStack; | 439 std::stack<const BookmarkNode*> nodeStack; |
439 BookmarkModel* model = profile_->GetBookmarkModel(); | 440 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); |
440 const BookmarkNode* rootNode = model->root_node(); | 441 const BookmarkNode* rootNode = model->root_node(); |
441 const BookmarkNode* node = desiredNode; | 442 const BookmarkNode* node = desiredNode; |
442 while (node != rootNode) { | 443 while (node != rootNode) { |
443 DCHECK(node); | 444 DCHECK(node); |
444 nodeStack.push(node); | 445 nodeStack.push(node); |
445 node = node->parent(); | 446 node = node->parent(); |
446 } | 447 } |
447 NSUInteger stackSize = nodeStack.size(); | 448 NSUInteger stackSize = nodeStack.size(); |
448 | 449 |
449 NSIndexPath* path = nil; | 450 NSIndexPath* path = nil; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 childFolders = [NSMutableArray arrayWithObject:folderInfo]; | 485 childFolders = [NSMutableArray arrayWithObject:folderInfo]; |
485 else | 486 else |
486 [childFolders addObject:folderInfo]; | 487 [childFolders addObject:folderInfo]; |
487 } | 488 } |
488 } | 489 } |
489 return childFolders; | 490 return childFolders; |
490 } | 491 } |
491 | 492 |
492 - (void)buildFolderTree { | 493 - (void)buildFolderTree { |
493 // Build up a tree of the current folder configuration. | 494 // Build up a tree of the current folder configuration. |
494 BookmarkModel* model = profile_->GetBookmarkModel(); | 495 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); |
495 const BookmarkNode* rootNode = model->root_node(); | 496 const BookmarkNode* rootNode = model->root_node(); |
496 NSMutableArray* baseArray = [self addChildFoldersFromNode:rootNode]; | 497 NSMutableArray* baseArray = [self addChildFoldersFromNode:rootNode]; |
497 DCHECK(baseArray); | 498 DCHECK(baseArray); |
498 [self willChangeValueForKey:@"folderTreeArray"]; | 499 [self willChangeValueForKey:@"folderTreeArray"]; |
499 folderTreeArray_.reset([baseArray retain]); | 500 folderTreeArray_.reset([baseArray retain]); |
500 [self didChangeValueForKey:@"folderTreeArray"]; | 501 [self didChangeValueForKey:@"folderTreeArray"]; |
501 } | 502 } |
502 | 503 |
503 - (void)modelChangedPreserveSelection:(BOOL)preserve { | 504 - (void)modelChangedPreserveSelection:(BOOL)preserve { |
504 if (creatingNewFolders_) | 505 if (creatingNewFolders_) |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 } | 677 } |
677 | 678 |
678 // Implementing isEqual: allows the NSTreeController to preserve the selection | 679 // Implementing isEqual: allows the NSTreeController to preserve the selection |
679 // and open/shut state of outline items when the data changes. | 680 // and open/shut state of outline items when the data changes. |
680 - (BOOL)isEqual:(id)other { | 681 - (BOOL)isEqual:(id)other { |
681 return [other isKindOfClass:[BookmarkFolderInfo class]] && | 682 return [other isKindOfClass:[BookmarkFolderInfo class]] && |
682 folderNode_ == [(BookmarkFolderInfo*)other folderNode]; | 683 folderNode_ == [(BookmarkFolderInfo*)other folderNode]; |
683 } | 684 } |
684 | 685 |
685 @end | 686 @end |
OLD | NEW |