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,
17 const AppListModel::Users& users)
24 AppListMenu::~AppListMenu() {}
26 void AppListMenu::InitMenu() {
27 // User selector menu section. We don't show the user selector if there is
29 if (users_.size() > 1) {
30 for (size_t i = 0; i < users_.size(); ++i) {
31 #if defined(OS_MACOSX)
32 menu_model_.AddRadioItem(SELECT_PROFILE + i,
33 users_[i].email.empty() ? users_[i].name
37 menu_model_.AddItem(SELECT_PROFILE + i, users_[i].name);
38 int menu_index = menu_model_.GetIndexOfCommandId(SELECT_PROFILE + i);
39 menu_model_.SetSublabel(menu_index, users_[i].email);
40 // Use custom check mark.
41 if (users_[i].active) {
42 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
43 menu_model_.SetIcon(menu_index, gfx::Image(*rb.GetImageSkiaNamed(
44 IDR_APP_LIST_USER_INDICATOR)));
48 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
51 menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16(
52 IDS_APP_LIST_OPEN_SETTINGS));
54 menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16(
57 menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16(
58 IDS_APP_LIST_OPEN_FEEDBACK));
61 bool AppListMenu::IsCommandIdChecked(int command_id) const {
62 #if defined(OS_MACOSX)
63 DCHECK_LT(static_cast<unsigned>(command_id) - SELECT_PROFILE, users_.size());
64 return users_[command_id - SELECT_PROFILE].active;
70 bool AppListMenu::IsCommandIdEnabled(int command_id) const {
74 bool AppListMenu::GetAcceleratorForCommandId(int command_id,
75 ui::Accelerator* accelerator) {
79 void AppListMenu::ExecuteCommand(int command_id, int event_flags) {
80 if (command_id >= SELECT_PROFILE) {
81 delegate_->ShowForProfileByPath(
82 users_[command_id - SELECT_PROFILE].profile_path);
87 delegate_->OpenSettings();
90 delegate_->OpenHelp();
93 delegate_->OpenFeedback();
100 } // namespace app_list