| 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 #import <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/nsimage_cache_mac.h" | 9 #include "base/nsimage_cache_mac.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 void BookmarkMenuBridge::Loaded(BookmarkModel* model) { | 42 void BookmarkMenuBridge::Loaded(BookmarkModel* model) { |
| 43 InvalidateMenu(); | 43 InvalidateMenu(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void BookmarkMenuBridge::UpdateMenu(NSMenu* bookmark_menu) { | 46 void BookmarkMenuBridge::UpdateMenu(NSMenu* bookmark_menu) { |
| 47 DCHECK(bookmark_menu); | 47 DCHECK(bookmark_menu); |
| 48 if (menuIsValid_) | 48 if (menuIsValid_) |
| 49 return; | 49 return; |
| 50 BookmarkModel* model = GetBookmarkModel(); |
| 51 if (!model || !model->IsLoaded()) |
| 52 return; |
| 50 | 53 |
| 51 if (!folder_image_) { | 54 if (!folder_image_) { |
| 52 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 55 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 53 folder_image_.reset([rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER) retain]); | 56 folder_image_.reset([rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER) retain]); |
| 54 } | 57 } |
| 55 | 58 |
| 56 ClearBookmarkMenu(bookmark_menu); | 59 ClearBookmarkMenu(bookmark_menu); |
| 57 | 60 |
| 58 // Add bookmark bar items, if any. | 61 // Add bookmark bar items, if any. |
| 59 const BookmarkNode* barNode = GetBookmarkModel()->GetBookmarkBarNode(); | 62 const BookmarkNode* barNode = model->GetBookmarkBarNode(); |
| 63 CHECK(barNode); |
| 60 if (barNode->GetChildCount()) { | 64 if (barNode->GetChildCount()) { |
| 61 [bookmark_menu addItem:[NSMenuItem separatorItem]]; | 65 [bookmark_menu addItem:[NSMenuItem separatorItem]]; |
| 62 AddNodeToMenu(barNode, bookmark_menu); | 66 AddNodeToMenu(barNode, bookmark_menu); |
| 63 } | 67 } |
| 64 | 68 |
| 65 // Create a submenu for "other bookmarks", and fill it in. | 69 // Create a submenu for "other bookmarks", and fill it in. |
| 66 NSString* other_items_title = base::SysWideToNSString( | 70 NSString* other_items_title = base::SysWideToNSString( |
| 67 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME)); | 71 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME)); |
| 68 [bookmark_menu addItem:[NSMenuItem separatorItem]]; | 72 [bookmark_menu addItem:[NSMenuItem separatorItem]]; |
| 69 AddNodeAsSubmenu(bookmark_menu, | 73 AddNodeAsSubmenu(bookmark_menu, |
| 70 GetBookmarkModel()->other_node(), | 74 model->other_node(), |
| 71 other_items_title); | 75 other_items_title); |
| 72 | 76 |
| 73 menuIsValid_ = true; | 77 menuIsValid_ = true; |
| 74 } | 78 } |
| 75 | 79 |
| 76 void BookmarkMenuBridge::BookmarkModelBeingDeleted(BookmarkModel* model) { | 80 void BookmarkMenuBridge::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| 77 NSMenu* bookmark_menu = BookmarkMenu(); | 81 NSMenu* bookmark_menu = BookmarkMenu(); |
| 78 if (bookmark_menu == nil) | 82 if (bookmark_menu == nil) |
| 79 return; | 83 return; |
| 80 | 84 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 236 |
| 233 NSMenuItem* BookmarkMenuBridge::MenuItemForNode(const BookmarkNode* node) { | 237 NSMenuItem* BookmarkMenuBridge::MenuItemForNode(const BookmarkNode* node) { |
| 234 if (!node) | 238 if (!node) |
| 235 return nil; | 239 return nil; |
| 236 std::map<const BookmarkNode*, NSMenuItem*>::iterator it = | 240 std::map<const BookmarkNode*, NSMenuItem*>::iterator it = |
| 237 bookmark_nodes_.find(node); | 241 bookmark_nodes_.find(node); |
| 238 if (it == bookmark_nodes_.end()) | 242 if (it == bookmark_nodes_.end()) |
| 239 return nil; | 243 return nil; |
| 240 return it->second; | 244 return it->second; |
| 241 } | 245 } |
| OLD | NEW |