diff options
author | maf@chromium.org <maf@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-09 01:39:46 +0000 |
---|---|---|
committer | maf@chromium.org <maf@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-09 01:39:46 +0000 |
commit | 1937e963795613aaec5e8cb6ec25bb8745558d34 (patch) | |
tree | efd7bf5538b0cd3391a004c4ac13ec8c070ea822 /chrome/browser | |
parent | 3a95d11692d594cedaa312ee420189b13621038f (diff) | |
download | chromium_src-1937e963795613aaec5e8cb6ec25bb8745558d34.zip chromium_src-1937e963795613aaec5e8cb6ec25bb8745558d34.tar.gz chromium_src-1937e963795613aaec5e8cb6ec25bb8745558d34.tar.bz2 |
Mac. Do not display "Other Bookmarks" folder or its preceding separator in any Bookmark menu if folder is empty.
Make BookmarkMenuBridge objects and BookMarkMenuCocoaController objects take the NSMenu at init time (BookmarkMenuCocoaController was unexpectedly hard-coded to hook onto the main menu bar Bookmarks menu as its delegate, causing previously mysterious sync problems and crashes).
Luckily, testing the small menu item hiding fix revealed the pre-existing bug in BookMarkMenuCocoaController, so these are both going in together.
R=sail@chromium.org
BUG=88793,87193
Review URL: http://codereview.chromium.org/7237063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91935 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
6 files changed, 28 insertions, 17 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index b1acdeb..61e8e09 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -461,7 +461,8 @@ void RecordLastRunAppBundlePath() { // Rebuild the menus with the new profile. lastProfile_ = profile; - bookmarkMenuBridge_.reset(new BookmarkMenuBridge(lastProfile_)); + bookmarkMenuBridge_.reset(new BookmarkMenuBridge(lastProfile_, + [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu])); bookmarkMenuBridge_->BuildMenu(); historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h index 2c332e7..9e295e3 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h @@ -37,7 +37,7 @@ class Profile; class BookmarkMenuBridge : public BookmarkModelObserver, public MainMenuItem { public: - BookmarkMenuBridge(Profile* profile); + BookmarkMenuBridge(Profile* profile, NSMenu* menu); virtual ~BookmarkMenuBridge(); // BookmarkModelObserver: diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.mm index 6dbf091..8ee2ffe 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.mm @@ -21,10 +21,12 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/mac/nsimage_cache.h" -BookmarkMenuBridge::BookmarkMenuBridge(Profile* profile) +BookmarkMenuBridge::BookmarkMenuBridge(Profile* profile, + NSMenu *menu) : menuIsValid_(false), profile_(profile), - controller_([[BookmarkMenuCocoaController alloc] initWithBridge:this]) { + controller_([[BookmarkMenuCocoaController alloc] initWithBridge:this + andMenu:menu]) { if (GetBookmarkModel()) ObserveBookmarkModel(); } @@ -77,14 +79,17 @@ void BookmarkMenuBridge::UpdateMenuInternal(NSMenu* bookmark_menu, AddNodeToMenu(barNode, bookmark_menu, !is_submenu); } - // Create a submenu for "other bookmarks", and fill it in. - NSString* other_items_title = - l10n_util::GetNSString(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME); - [bookmark_menu addItem:[NSMenuItem separatorItem]]; - AddNodeAsSubmenu(bookmark_menu, - model->other_node(), - other_items_title, - !is_submenu); + // If the "Other Bookmarks" folder has any content, make a submenu for it and + // fill it in. + if (!model->other_node()->empty()) { + NSString* other_items_title = + l10n_util::GetNSString(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME); + [bookmark_menu addItem:[NSMenuItem separatorItem]]; + AddNodeAsSubmenu(bookmark_menu, + model->other_node(), + other_items_title, + !is_submenu); + } menuIsValid_ = true; } diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h index 7a267ad..aeedcdb 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,6 +21,7 @@ class BookmarkMenuBridge; @interface BookmarkMenuCocoaController : NSObject<NSMenuDelegate> { @private BookmarkMenuBridge* bridge_; // weak; owns me + NSMenu *menu_; } // The Bookmarks menu @@ -33,7 +34,8 @@ class BookmarkMenuBridge; // Make a relevant tooltip string for node. + (NSString*)tooltipForNode:(const BookmarkNode*)node; -- (id)initWithBridge:(BookmarkMenuBridge *)bridge; +- (id)initWithBridge:(BookmarkMenuBridge *)bridge + andMenu:(NSMenu*)menu; // Called by any Bookmark menu item. // The menu item's tag is the bookmark ID. diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm index c100ba9..484d267 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm @@ -49,10 +49,12 @@ const NSUInteger kMaximumMenuPixelsWide = 300; return [NSString stringWithFormat:@"%@\n%@", title, url]; } -- (id)initWithBridge:(BookmarkMenuBridge *)bridge { +- (id)initWithBridge:(BookmarkMenuBridge *)bridge + andMenu:(NSMenu*)menu { if ((self = [super init])) { bridge_ = bridge; DCHECK(bridge_); + menu_ = menu; [[self menu] setDelegate:self]; } return self; @@ -64,7 +66,7 @@ const NSUInteger kMaximumMenuPixelsWide = 300; } - (NSMenu*)menu { - return [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu]; + return menu_; } - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm index f025fec..7eeff81 100644 --- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm +++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm @@ -116,7 +116,8 @@ class ZoomLevelObserver : public NotificationObserver { if (!bookmarkMenuBridge_.get()) { bookmarkMenuBridge_.reset( - new BookmarkMenuBridge([self wrenchMenuModel]->browser()->profile())); + new BookmarkMenuBridge([self wrenchMenuModel]->browser()->profile(), + bookmarkMenu)); } DCHECK(bookmarkMenuBridge_.get() != NULL); |