Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/browser/app_menu_model.cc

Issue 523147: Made MenuController handle dynamic labels. (Closed)
Patch Set: Addressed pinkerton's comments. Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/app_menu_model.h ('k') | chrome/browser/cocoa/menu_controller.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "chrome/browser/app_menu_model.h" 5 #include "chrome/browser/app_menu_model.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/defaults.h" 11 #include "chrome/browser/defaults.h"
12 #include "chrome/browser/sync/profile_sync_service.h" 12 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/sync/sync_ui_util.h" 13 #include "chrome/browser/sync/sync_ui_util.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "grit/chromium_strings.h" 15 #include "grit/chromium_strings.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 17
18 // TODO(akalin): Now that AppMenuModel handles the sync item
19 // dynamically, we don't need to refresh the menu on Windows/Linux.
20 // Remove that code and make sure it works.
21
18 AppMenuModel::AppMenuModel(menus::SimpleMenuModel::Delegate* delegate, 22 AppMenuModel::AppMenuModel(menus::SimpleMenuModel::Delegate* delegate,
19 Browser* browser) 23 Browser* browser)
20 : menus::SimpleMenuModel(delegate), 24 : menus::SimpleMenuModel(delegate),
21 browser_(browser) { 25 browser_(browser),
26 // For now, we assume that sync cannot be enabled/disabled after
27 // launch.
28 sync_item_enabled_(ProfileSyncService::IsSyncEnabled()),
29 sync_item_index_(-1) {
22 Build(); 30 Build();
23 } 31 }
24 32
25 AppMenuModel::~AppMenuModel() { 33 AppMenuModel::~AppMenuModel() {
26 } 34 }
27 35
36 bool AppMenuModel::IsLabelDynamicAt(int index) const {
37 return IsSyncItem(index) || SimpleMenuModel::IsLabelDynamicAt(index);
38 }
39
40 string16 AppMenuModel::GetLabelAt(int index) const {
41 return IsSyncItem(index) ?
42 GetSyncMenuLabel() : SimpleMenuModel::GetLabelAt(index);
43 }
44
28 void AppMenuModel::Build() { 45 void AppMenuModel::Build() {
29 AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); 46 AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
30 AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); 47 AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW);
31 AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW); 48 AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW);
32 // Enumerate profiles asynchronously and then create the parent menu item. 49 // Enumerate profiles asynchronously and then create the parent menu item.
33 // We will create the child menu items for this once the asynchronous call is 50 // We will create the child menu items for this once the asynchronous call is
34 // done. See OnGetProfilesDone(). 51 // done. See OnGetProfilesDone().
35 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 52 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
36 if (command_line.HasSwitch(switches::kEnableUserDataDirProfiles)) { 53 if (command_line.HasSwitch(switches::kEnableUserDataDirProfiles)) {
37 // Triggers profile list refresh in case it's changed. 54 // Triggers profile list refresh in case it's changed.
(...skipping 11 matching lines...) Expand all
49 AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); 66 AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN);
50 AddSeparator(); 67 AddSeparator();
51 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); 68 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY);
52 AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER); 69 AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER);
53 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); 70 AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS);
54 71
55 // Create the manage extensions menu item. 72 // Create the manage extensions menu item.
56 AddItemWithStringId(IDC_MANAGE_EXTENSIONS, IDS_SHOW_EXTENSIONS); 73 AddItemWithStringId(IDC_MANAGE_EXTENSIONS, IDS_SHOW_EXTENSIONS);
57 74
58 AddSeparator(); 75 AddSeparator();
59 if (ProfileSyncService::IsSyncEnabled()) { 76 if (sync_item_enabled_) {
60 string16 label = sync_ui_util::GetSyncMenuLabel( 77 AddItem(IDC_SYNC_BOOKMARKS, GetSyncMenuLabel());
61 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); 78 // TODO(akalin): Make it possible to get the index in a less
62 AddItem(IDC_SYNC_BOOKMARKS, label); 79 // hackish way.
80 sync_item_index_ = GetItemCount() - 1;
63 AddSeparator(); 81 AddSeparator();
64 } 82 }
65 #if defined(OS_MACOSX) 83 #if defined(OS_MACOSX)
66 AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES_MAC); 84 AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES_MAC);
67 #else 85 #else
68 AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); 86 AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS);
69 #endif 87 #endif
70 if (browser_defaults::kShowAboutMenuItem) { 88 if (browser_defaults::kShowAboutMenuItem) {
71 AddItem(IDC_ABOUT, 89 AddItem(IDC_ABOUT,
72 l10n_util::GetStringFUTF16( 90 l10n_util::GetStringFUTF16(
(...skipping 29 matching lines...) Expand all
102 profiles_menu_contents_->AddItemWithStringId(IDC_SELECT_PROFILE, 120 profiles_menu_contents_->AddItemWithStringId(IDC_SELECT_PROFILE,
103 IDS_SELECT_PROFILE); 121 IDS_SELECT_PROFILE);
104 } 122 }
105 123
106 // Always show a link to select a new profile. 124 // Always show a link to select a new profile.
107 profiles_menu_contents_->AddSeparator(); 125 profiles_menu_contents_->AddSeparator();
108 profiles_menu_contents_->AddItemWithStringId( 126 profiles_menu_contents_->AddItemWithStringId(
109 IDC_NEW_PROFILE, 127 IDC_NEW_PROFILE,
110 IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY); 128 IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY);
111 } 129 }
130
131 string16 AppMenuModel::GetSyncMenuLabel() const {
132 DCHECK(sync_item_enabled_);
133 return sync_ui_util::GetSyncMenuLabel(
134 browser_->profile()->GetOriginalProfile()->GetProfileSyncService());
135 }
136
137 bool AppMenuModel::IsSyncItem(int index) const {
138 return sync_item_enabled_ && (index == sync_item_index_);
139 }
140
OLDNEW
« no previous file with comments | « chrome/browser/app_menu_model.h ('k') | chrome/browser/cocoa/menu_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698