diff options
Diffstat (limited to 'chrome/browser/cocoa/browser_window_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index f310c07..73781e4 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -4,6 +4,7 @@ #include <Carbon/Carbon.h> +#include "app/l10n_util_mac.h" #include "base/mac_util.h" #include "base/scoped_nsdisable_screen_updates.h" #import "base/scoped_nsobject.h" @@ -39,8 +40,10 @@ #import "chrome/browser/cocoa/tab_view.h" #import "chrome/browser/cocoa/toolbar_controller.h" #import "chrome/browser/browser_theme_provider.h" +#include "chrome/browser/sync/sync_status_ui_helper.h" #include "chrome/common/pref_service.h" #import "chrome/browser/cocoa/background_gradient_view.h" +#include "grit/generated_resources.h" #include "grit/theme_resources.h" #import "third_party/GTM/AppKit/GTMTheme.h" @@ -579,6 +582,19 @@ willPositionSheet:(NSWindow*)sheet case IDC_FULLSCREEN: enable &= [self supportsFullscreen]; break; + case IDC_SYNC_BOOKMARKS: + { + Profile* profile = browser_->profile()->GetOriginalProfile(); + ProfileSyncService* syncService = profile->GetProfileSyncService(); + // TODO(timsteele): Need a ui helper method to just get the type + // without needing labels. + string16 label, link; + SyncStatusUIHelper::MessageType status = + SyncStatusUIHelper::GetLabels(syncService, &label, &link); + enable &= (syncService != NULL); + [self updateSyncItem:item syncEnabled:enable status:status]; + } + break; default: // Special handling for the contents of the Text Encoding submenu. On // Mac OS, instead of enabling/disabling the top-level menu item, we @@ -599,6 +615,59 @@ willPositionSheet:(NSWindow*)sheet return enable; } +// TODO(akalin): We need to add a menu item to the main Chrome menu (near +// "Clear browsing data..."). However, this is tricky as no browsers may +// actually be open. Refactor the sync UI code so that it doesn't depend +// on a browser being present. + +- (void)updateSyncItem:(id)syncItem + syncEnabled:(BOOL)syncEnabled + status:(SyncStatusUIHelper::MessageType)status { + DCHECK([syncItem isKindOfClass:[NSMenuItem class]]); + NSMenuItem* syncMenuItem = (NSMenuItem*)syncItem; + // Look for a separator immediately after the menu item. + NSMenuItem* followingSeparator = nil; + NSMenu* menu = [syncItem menu]; + if (menu) { + NSInteger syncItemIndex = [menu indexOfItem:syncMenuItem]; + DCHECK_NE(syncItemIndex, -1); + if ((syncItemIndex + 1) < [menu numberOfItems]) { + NSMenuItem* menuItem = [menu itemAtIndex:(syncItemIndex + 1)]; + if ([menuItem isSeparatorItem]) { + followingSeparator = menuItem; + } + } + } + + // TODO(akalin): consolidate this code with the equivalent Windows code in + // chrome/browser/views/toolbar_view.cc. + int titleId; + switch (status) { + case SyncStatusUIHelper::SYNCED: + titleId = IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL; + break; + case SyncStatusUIHelper::SYNC_ERROR: + titleId = IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL; + break; + case SyncStatusUIHelper::PRE_SYNCED: + titleId = IDS_SYNC_START_SYNC_BUTTON_LABEL; + break; + default: + NOTREACHED(); + // Needed to prevent release-mode warnings. + titleId = IDS_SYNC_START_SYNC_BUTTON_LABEL; + break; + } + NSString* title = l10n_util::GetNSStringWithFixup(titleId); + [syncMenuItem setTitle:title]; + + // If we don't have a sync service, hide any sync-related menu + // items. However, sync_menu_item is enabled/disabled outside of this + // function so we don't touch it here, and separators are always disabled. + [syncMenuItem setHidden:!syncEnabled]; + [followingSeparator setHidden:!syncEnabled]; +} + // Called when the user picks a menu or toolbar item when this window is key. // Calls through to the browser object to execute the command. This assumes that // the command is supported and doesn't check, otherwise it would have been |