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_resources.h" | |
7 #include "grit/ui_strings.h" | 8 #include "grit/ui_strings.h" |
8 #include "ui/app_list/app_list_view_delegate.h" | 9 #include "ui/app_list/app_list_view_delegate.h" |
9 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
10 #include "ui/base/models/menu_separator_types.h" | 11 #include "ui/base/models/menu_separator_types.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(AppListViewDelegate* delegate, |
17 const AppListModel::Users& users) | |
16 : menu_model_(this), | 18 : menu_model_(this), |
17 delegate_(delegate) { | 19 delegate_(delegate), |
20 users_(users) { | |
18 InitMenu(); | 21 InitMenu(); |
19 } | 22 } |
20 | 23 |
21 AppListMenu::~AppListMenu() {} | 24 AppListMenu::~AppListMenu() {} |
22 | 25 |
23 void AppListMenu::InitMenu() { | 26 void AppListMenu::InitMenu() { |
24 menu_model_.AddItem(CURRENT_USER, base::string16()); | 27 // User selector menu section. We don't show the user selector if there is |
25 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 28 // only 1 user. |
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 | |
34 : users_[i].email, | |
35 0); | |
36 #else | |
37 menu_model_.AddItem(SELECT_PROFILE + i, users_[i].name, 0); | |
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(); | |
tapted
2013/09/13 23:12:17
ugh - I guess mac complains that it's unused when
| |
43 menu_model_.SetIcon(i, gfx::Image(*rb.GetImageSkiaNamed( | |
tapted
2013/09/13 23:12:17
..SetIcon(i, .. --> ..SetIcon(menu_index, ..
calamity
2013/09/16 19:45:26
Done.
| |
44 IDR_APP_LIST_CURRENT_USER_INDICATOR))); | |
45 } | |
46 #endif | |
47 } | |
48 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
49 } | |
26 | 50 |
27 menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16( | 51 menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16( |
28 IDS_APP_LIST_OPEN_SETTINGS)); | 52 IDS_APP_LIST_OPEN_SETTINGS)); |
29 | 53 |
30 menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16( | 54 menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16( |
31 IDS_APP_LIST_HELP)); | 55 IDS_APP_LIST_HELP)); |
32 | 56 |
33 menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16( | 57 menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16( |
34 IDS_APP_LIST_OPEN_FEEDBACK)); | 58 IDS_APP_LIST_OPEN_FEEDBACK)); |
35 } | 59 } |
36 | 60 |
37 bool AppListMenu::IsCommandIdChecked(int command_id) const { | 61 bool AppListMenu::IsCommandIdChecked(int command_id) const { |
62 #if defined(OS_MACOSX) | |
63 return users_[command_id - SELECT_PROFILE].active; | |
tapted
2013/09/13 23:12:17
maybe
DCHECK_LT(static_cast<unsigned>(command_id)
calamity
2013/09/16 19:45:26
Done.
| |
64 #else | |
38 return false; | 65 return false; |
66 #endif | |
39 } | 67 } |
40 | 68 |
41 bool AppListMenu::IsCommandIdEnabled(int command_id) const { | 69 bool AppListMenu::IsCommandIdEnabled(int command_id) const { |
42 return true; | 70 return true; |
43 } | 71 } |
44 | 72 |
45 bool AppListMenu::GetAcceleratorForCommandId(int command_id, | 73 bool AppListMenu::GetAcceleratorForCommandId(int command_id, |
46 ui::Accelerator* accelerator) { | 74 ui::Accelerator* accelerator) { |
47 return false; | 75 return false; |
48 } | 76 } |
49 | 77 |
50 void AppListMenu::ExecuteCommand(int command_id, int event_flags) { | 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 } | |
51 switch (command_id) { | 84 switch (command_id) { |
52 case CURRENT_USER: | 85 case CURRENT_USER: |
53 break; // Do nothing. | 86 break; // Do nothing. |
54 case SHOW_SETTINGS: | 87 case SHOW_SETTINGS: |
55 delegate_->OpenSettings(); | 88 delegate_->OpenSettings(); |
56 break; | 89 break; |
57 case SHOW_HELP: | 90 case SHOW_HELP: |
58 delegate_->OpenHelp(); | 91 delegate_->OpenHelp(); |
59 break; | 92 break; |
60 case SHOW_FEEDBACK: | 93 case SHOW_FEEDBACK: |
61 delegate_->OpenFeedback(); | 94 delegate_->OpenFeedback(); |
62 break; | 95 break; |
63 default: | 96 default: |
64 NOTREACHED(); | 97 NOTREACHED(); |
65 } | 98 } |
66 } | 99 } |
67 | 100 |
68 } // namespace app_list | 101 } // namespace app_list |
OLD | NEW |