| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ui/app_list/app_list_menu.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "build/build_config.h" | |
| 10 #include "ui/app_list/app_list_view_delegate.h" | |
| 11 #include "ui/app_list/resources/grit/app_list_resources.h" | |
| 12 #include "ui/base/l10n/l10n_util.h" | |
| 13 #include "ui/base/models/menu_separator_types.h" | |
| 14 #include "ui/base/resource/resource_bundle.h" | |
| 15 #include "ui/strings/grit/ui_strings.h" | |
| 16 | |
| 17 namespace app_list { | |
| 18 | |
| 19 AppListMenu::AppListMenu(AppListViewDelegate* delegate) | |
| 20 : menu_model_(this), | |
| 21 delegate_(delegate), | |
| 22 users_(delegate->GetUsers()) { | |
| 23 InitMenu(); | |
| 24 } | |
| 25 | |
| 26 AppListMenu::~AppListMenu() {} | |
| 27 | |
| 28 void AppListMenu::InitMenu() { | |
| 29 // User selector menu section. We don't show the user selector if there is | |
| 30 // only 1 user. | |
| 31 if (users_.size() > 1) { | |
| 32 for (size_t i = 0; i < users_.size(); ++i) { | |
| 33 #if defined(OS_MACOSX) | |
| 34 menu_model_.AddRadioItem(SELECT_PROFILE + i, | |
| 35 users_[i].email.empty() ? users_[i].name | |
| 36 : users_[i].email, | |
| 37 0 /* group_id */); | |
| 38 #elif defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | |
| 39 menu_model_.AddItem(SELECT_PROFILE + i, users_[i].name); | |
| 40 int menu_index = menu_model_.GetIndexOfCommandId(SELECT_PROFILE + i); | |
| 41 menu_model_.SetSublabel(menu_index, users_[i].email); | |
| 42 // Use custom check mark. | |
| 43 if (users_[i].active) { | |
| 44 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 45 menu_model_.SetIcon(menu_index, gfx::Image(*rb.GetImageSkiaNamed( | |
| 46 IDR_APP_LIST_USER_INDICATOR))); | |
| 47 } | |
| 48 #endif | |
| 49 } | |
| 50 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
| 51 } | |
| 52 | |
| 53 menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16( | |
| 54 IDS_APP_LIST_HELP)); | |
| 55 | |
| 56 menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16( | |
| 57 IDS_APP_LIST_OPEN_FEEDBACK)); | |
| 58 } | |
| 59 | |
| 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; | |
| 64 #else | |
| 65 return false; | |
| 66 #endif | |
| 67 } | |
| 68 | |
| 69 bool AppListMenu::IsCommandIdEnabled(int command_id) const { | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 bool AppListMenu::GetAcceleratorForCommandId(int command_id, | |
| 74 ui::Accelerator* accelerator) { | |
| 75 return false; | |
| 76 } | |
| 77 | |
| 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); | |
| 82 return; | |
| 83 } | |
| 84 switch (command_id) { | |
| 85 case SHOW_HELP: | |
| 86 delegate_->OpenHelp(); | |
| 87 break; | |
| 88 case SHOW_FEEDBACK: | |
| 89 delegate_->OpenFeedback(); | |
| 90 break; | |
| 91 default: | |
| 92 NOTREACHED(); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 } // namespace app_list | |
| OLD | NEW |