summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/browser_window_controller.mm
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 22:01:09 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 22:01:09 +0000
commit49f95e9eccbb3d1c9ce7b6a46adff337ef831fe2 (patch)
tree69883d8bb25c97a9a1f8f0598322a3e947d4a5cf /chrome/browser/cocoa/browser_window_controller.mm
parentc0d43029bbd23a2648589896ec1257f6a7c32b62 (diff)
downloadchromium_src-49f95e9eccbb3d1c9ce7b6a46adff337ef831fe2.zip
chromium_src-49f95e9eccbb3d1c9ce7b6a46adff337ef831fe2.tar.gz
chromium_src-49f95e9eccbb3d1c9ce7b6a46adff337ef831fe2.tar.bz2
Added menu item for sync to wrench menu.
Wrench menu item is right above "Preferences...". Chrome menu item will be added in a future CL right above "Clear Browsing Data...". Sync menu items are hidden if bookmark sync is disabled (the current default for OS X). UI decisions were made after consulting with Cole. Added code in browser_window_controller.mm to update sync menu item dynamically. Added unit tests. BUG=23073 TEST=manual testing, trybots, unittests Review URL: http://codereview.chromium.org/363017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/browser_window_controller.mm')
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm69
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