1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/app_list/app_list_menu.h"
7 #include "grit/ui_resources.h"
8 #include "grit/ui_strings.h"
9 #include "ui/app_list/app_list_view_delegate.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/models/menu_separator_types.h"
12 #include "ui/base/resource/resource_bundle.h"
16 AppListMenu::AppListMenu(AppListViewDelegate
* delegate
)
19 users_(delegate
->GetUsers()) {
23 AppListMenu::~AppListMenu() {}
25 void AppListMenu::InitMenu() {
26 // User selector menu section. We don't show the user selector if there is
28 if (users_
.size() > 1) {
29 for (size_t i
= 0; i
< users_
.size(); ++i
) {
30 #if defined(OS_MACOSX)
31 menu_model_
.AddRadioItem(SELECT_PROFILE
+ i
,
32 users_
[i
].email
.empty() ? users_
[i
].name
35 #elif defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
36 menu_model_
.AddItem(SELECT_PROFILE
+ i
, users_
[i
].name
);
37 int menu_index
= menu_model_
.GetIndexOfCommandId(SELECT_PROFILE
+ i
);
38 menu_model_
.SetSublabel(menu_index
, users_
[i
].email
);
39 // Use custom check mark.
40 if (users_
[i
].active
) {
41 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
42 menu_model_
.SetIcon(menu_index
, gfx::Image(*rb
.GetImageSkiaNamed(
43 IDR_APP_LIST_USER_INDICATOR
)));
47 menu_model_
.AddSeparator(ui::NORMAL_SEPARATOR
);
50 menu_model_
.AddItem(SHOW_SETTINGS
, l10n_util::GetStringUTF16(
51 IDS_APP_LIST_OPEN_SETTINGS
));
53 menu_model_
.AddItem(SHOW_HELP
, l10n_util::GetStringUTF16(
56 menu_model_
.AddItem(SHOW_FEEDBACK
, l10n_util::GetStringUTF16(
57 IDS_APP_LIST_OPEN_FEEDBACK
));
60 bool AppListMenu::IsCommandIdChecked(int command_id
) const {
61 #if defined(OS_MACOSX)
62 DCHECK_LT(static_cast<unsigned>(command_id
) - SELECT_PROFILE
, users_
.size());
63 return users_
[command_id
- SELECT_PROFILE
].active
;
69 bool AppListMenu::IsCommandIdEnabled(int command_id
) const {
73 bool AppListMenu::GetAcceleratorForCommandId(int command_id
,
74 ui::Accelerator
* accelerator
) {
78 void AppListMenu::ExecuteCommand(int command_id
, int event_flags
) {
79 if (command_id
>= SELECT_PROFILE
) {
80 delegate_
->ShowForProfileByPath(
81 users_
[command_id
- SELECT_PROFILE
].profile_path
);
86 delegate_
->OpenSettings();
89 delegate_
->OpenHelp();
92 delegate_
->OpenFeedback();
99 } // namespace app_list