summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_menu_model.cc
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 20:51:14 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 20:51:14 +0000
commiteb39d5b4208b4fe3d83da55dc47be03bdc7b68ba (patch)
treeab2dc9c5c840c9cdc0293f2e906794e391fa67a1 /chrome/browser/app_menu_model.cc
parent24d00151add1a7ac160a502638f2841ccf9edb9f (diff)
downloadchromium_src-eb39d5b4208b4fe3d83da55dc47be03bdc7b68ba.zip
chromium_src-eb39d5b4208b4fe3d83da55dc47be03bdc7b68ba.tar.gz
chromium_src-eb39d5b4208b4fe3d83da55dc47be03bdc7b68ba.tar.bz2
Made MenuController handle dynamic labels.
Made AppMenuModel handle sync item dynamically. BUG=31691 TEST=made sure wrench menu item dynamically updates sync menu item Review URL: http://codereview.chromium.org/523147 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/app_menu_model.cc')
-rw-r--r--chrome/browser/app_menu_model.cc39
1 files changed, 34 insertions, 5 deletions
diff --git a/chrome/browser/app_menu_model.cc b/chrome/browser/app_menu_model.cc
index 38aca15..f42c920 100644
--- a/chrome/browser/app_menu_model.cc
+++ b/chrome/browser/app_menu_model.cc
@@ -15,16 +15,33 @@
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
+// TODO(akalin): Now that AppMenuModel handles the sync item
+// dynamically, we don't need to refresh the menu on Windows/Linux.
+// Remove that code and make sure it works.
+
AppMenuModel::AppMenuModel(menus::SimpleMenuModel::Delegate* delegate,
Browser* browser)
: menus::SimpleMenuModel(delegate),
- browser_(browser) {
+ browser_(browser),
+ // For now, we assume that sync cannot be enabled/disabled after
+ // launch.
+ sync_item_enabled_(ProfileSyncService::IsSyncEnabled()),
+ sync_item_index_(-1) {
Build();
}
AppMenuModel::~AppMenuModel() {
}
+bool AppMenuModel::IsLabelDynamicAt(int index) const {
+ return IsSyncItem(index) || SimpleMenuModel::IsLabelDynamicAt(index);
+}
+
+string16 AppMenuModel::GetLabelAt(int index) const {
+ return IsSyncItem(index) ?
+ GetSyncMenuLabel() : SimpleMenuModel::GetLabelAt(index);
+}
+
void AppMenuModel::Build() {
AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW);
@@ -56,10 +73,11 @@ void AppMenuModel::Build() {
AddItemWithStringId(IDC_MANAGE_EXTENSIONS, IDS_SHOW_EXTENSIONS);
AddSeparator();
- if (ProfileSyncService::IsSyncEnabled()) {
- string16 label = sync_ui_util::GetSyncMenuLabel(
- browser_->profile()->GetOriginalProfile()->GetProfileSyncService());
- AddItem(IDC_SYNC_BOOKMARKS, label);
+ if (sync_item_enabled_) {
+ AddItem(IDC_SYNC_BOOKMARKS, GetSyncMenuLabel());
+ // TODO(akalin): Make it possible to get the index in a less
+ // hackish way.
+ sync_item_index_ = GetItemCount() - 1;
AddSeparator();
}
#if defined(OS_MACOSX)
@@ -109,3 +127,14 @@ void AppMenuModel::BuildProfileSubMenu() {
IDC_NEW_PROFILE,
IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY);
}
+
+string16 AppMenuModel::GetSyncMenuLabel() const {
+ DCHECK(sync_item_enabled_);
+ return sync_ui_util::GetSyncMenuLabel(
+ browser_->profile()->GetOriginalProfile()->GetProfileSyncService());
+}
+
+bool AppMenuModel::IsSyncItem(int index) const {
+ return sync_item_enabled_ && (index == sync_item_index_);
+}
+