OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/app_list/app_list_menu.h" | 5 #include "ui/app_list/app_list_menu.h" |
6 | 6 |
7 #include "grit/ui_strings.h" | 7 #include "grit/ui_strings.h" |
8 #include "ui/app_list/app_list_view_delegate.h" | 8 #include "ui/app_list/app_list_view_delegate.h" |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 #include "ui/base/models/menu_separator_types.h" | 10 #include "ui/base/models/menu_separator_types.h" |
| 11 #include "ui/base/profile_selector/avatar_menu_item_model.h" |
11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
12 | 13 |
13 namespace app_list { | 14 namespace app_list { |
14 | 15 |
15 AppListMenu::AppListMenu(AppListViewDelegate* delegate) | 16 AppListMenu::AppListMenu( |
16 : menu_model_(this), | 17 AppListViewDelegate* delegate, |
17 delegate_(delegate) { | 18 const app_list::AppListModel::ProfileMenuItems& profile_menu_items) |
| 19 : menu_model_(this), |
| 20 profiles_model_(this), |
| 21 delegate_(delegate), |
| 22 profile_menu_items_(profile_menu_items) { |
18 InitMenu(); | 23 InitMenu(); |
19 } | 24 } |
20 | 25 |
21 AppListMenu::~AppListMenu() {} | 26 AppListMenu::~AppListMenu() {} |
22 | 27 |
23 void AppListMenu::InitMenu() { | 28 void AppListMenu::InitMenu() { |
24 menu_model_.AddItem(CURRENT_USER, base::string16()); | 29 // Don't show the profile selector submenu if there is only one profile. |
| 30 if (profile_menu_items_.size() == 1) { |
| 31 menu_model_.AddItem(CURRENT_USER, base::string16()); |
| 32 } else { |
| 33 for (size_t i = 0; i < profile_menu_items_.size(); ++i) { |
| 34 profiles_model_.AddItem(SELECT_PROFILE + i, profile_menu_items_[i]->name); |
| 35 } |
| 36 menu_model_.AddSubMenu(CURRENT_USER, base::string16(), &profiles_model_); |
| 37 } |
25 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 38 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
26 | 39 |
27 menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16( | 40 menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16( |
28 IDS_APP_LIST_OPEN_SETTINGS)); | 41 IDS_APP_LIST_OPEN_SETTINGS)); |
29 | 42 |
30 menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16( | 43 menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16( |
31 IDS_APP_LIST_HELP)); | 44 IDS_APP_LIST_HELP)); |
32 | 45 |
33 menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16( | 46 menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16( |
34 IDS_APP_LIST_OPEN_FEEDBACK)); | 47 IDS_APP_LIST_OPEN_FEEDBACK)); |
35 } | 48 } |
36 | 49 |
37 bool AppListMenu::IsCommandIdChecked(int command_id) const { | 50 bool AppListMenu::IsCommandIdChecked(int command_id) const { |
38 return false; | 51 return false; |
39 } | 52 } |
40 | 53 |
41 bool AppListMenu::IsCommandIdEnabled(int command_id) const { | 54 bool AppListMenu::IsCommandIdEnabled(int command_id) const { |
42 return true; | 55 return true; |
43 } | 56 } |
44 | 57 |
45 bool AppListMenu::GetAcceleratorForCommandId(int command_id, | 58 bool AppListMenu::GetAcceleratorForCommandId(int command_id, |
46 ui::Accelerator* accelerator) { | 59 ui::Accelerator* accelerator) { |
47 return false; | 60 return false; |
48 } | 61 } |
49 | 62 |
50 void AppListMenu::ExecuteCommand(int command_id, int event_flags) { | 63 void AppListMenu::ExecuteCommand(int command_id, int event_flags) { |
| 64 if (command_id >= SELECT_PROFILE) { |
| 65 delegate_->ShowForProfileByPath( |
| 66 profile_menu_items_[command_id - SELECT_PROFILE]->profile_path); |
| 67 return; |
| 68 } |
51 switch (command_id) { | 69 switch (command_id) { |
52 case CURRENT_USER: | 70 case CURRENT_USER: |
53 break; // Do nothing. | 71 break; // Do nothing. |
54 case SHOW_SETTINGS: | 72 case SHOW_SETTINGS: |
55 delegate_->OpenSettings(); | 73 delegate_->OpenSettings(); |
56 break; | 74 break; |
57 case SHOW_HELP: | 75 case SHOW_HELP: |
58 delegate_->OpenHelp(); | 76 delegate_->OpenHelp(); |
59 break; | 77 break; |
60 case SHOW_FEEDBACK: | 78 case SHOW_FEEDBACK: |
61 delegate_->OpenFeedback(); | 79 delegate_->OpenFeedback(); |
62 break; | 80 break; |
63 default: | 81 default: |
64 NOTREACHED(); | 82 NOTREACHED(); |
65 } | 83 } |
66 } | 84 } |
67 | 85 |
68 } // namespace app_list | 86 } // namespace app_list |
OLD | NEW |