diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-25 03:54:40 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-25 03:54:40 +0000 |
commit | 40f04797e143e6b3fe59dbccdf7053aa2a7a2fe6 (patch) | |
tree | 0037cf6381a4876ee66f1f6330b0d1aef551815e /chrome/browser/sync/sync_ui_util_mac.mm | |
parent | 6a7e698052d3b0d0aafebd5ac6af0ef2f95ff2a9 (diff) | |
download | chromium_src-40f04797e143e6b3fe59dbccdf7053aa2a7a2fe6.zip chromium_src-40f04797e143e6b3fe59dbccdf7053aa2a7a2fe6.tar.gz chromium_src-40f04797e143e6b3fe59dbccdf7053aa2a7a2fe6.tar.bz2 |
Changed SyncStatusUIHelper namespace class into a real namespace (sync_ui_util), per style guide.
Changed static functions into anonymous-namespace functions.
Renamed files/namespaces from sync_status_ui_helper to sync_ui_util.
Moved sync_ui_util_mac.mm functions into sync_ui_util namespace.
Updated all callers.
BUG=none
TEST=trybots
Review URL: http://codereview.chromium.org/414065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33044 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/sync_ui_util_mac.mm')
-rw-r--r-- | chrome/browser/sync/sync_ui_util_mac.mm | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/chrome/browser/sync/sync_ui_util_mac.mm b/chrome/browser/sync/sync_ui_util_mac.mm new file mode 100644 index 0000000..1e04b22 --- /dev/null +++ b/chrome/browser/sync/sync_ui_util_mac.mm @@ -0,0 +1,75 @@ +// Copyright (c) 2009 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. + +#include "chrome/browser/sync/sync_ui_util_mac.h" + +#import <Cocoa/Cocoa.h> + +#include "app/l10n_util_mac.h" +#include "base/logging.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/sync/sync_ui_util.h" +#include "grit/generated_resources.h" + +namespace sync_ui_util { + +void UpdateSyncItem(id syncItem, BOOL syncEnabled, Profile* profile) { + ProfileSyncService* syncService = + profile->GetOriginalProfile()->GetProfileSyncService(); + // TODO(timsteele): Need a ui helper method to just get the type + // without needing labels. + string16 label, link; + sync_ui_util::MessageType status = + sync_ui_util::GetStatusLabels(syncService, &label, &link); + UpdateSyncItemForStatus(syncItem, syncEnabled, status); +} + +void UpdateSyncItemForStatus(id syncItem, BOOL syncEnabled, + sync_ui_util::MessageType status) { + DCHECK([syncItem isKindOfClass:[NSMenuItem class]]); + NSMenuItem* syncMenuItem = static_cast<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 sync_ui_util::SYNCED: + titleId = IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL; + break; + case sync_ui_util::SYNC_ERROR: + titleId = IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL; + break; + case sync_ui_util::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]; +} + +} // namespace sync_ui_util |