Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ui/app_list/app_list_menu.cc

Issue 20656002: Add profile selector menu to app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/avatar_menu_item_model.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)
16 : menu_model_(this), 17 : menu_model_(this),
18 profiles_model_(this),
17 delegate_(delegate) { 19 delegate_(delegate) {
18 InitMenu(); 20 InitMenu();
19 } 21 }
20 22
21 AppListMenu::~AppListMenu() {} 23 AppListMenu::~AppListMenu() {}
22 24
23 void AppListMenu::InitMenu() { 25 void AppListMenu::InitMenu() {
24 menu_model_.AddItem(CURRENT_USER, base::string16()); 26 std::vector<AvatarMenuItemModel> items = delegate_->GetAvatarMenuItems();
27 // Don't show the profile selector submenu if there is only one profile.
28 if (items.size() == 1) {
29 menu_model_.AddItem(CURRENT_USER, base::string16());
30 } else {
31 for (size_t i = 0; i < items.size(); ++i) {
32 profiles_model_.AddItem(SELECT_PROFILE + i, items[i].name);
33 }
34 menu_model_.AddSubMenu(CURRENT_USER, base::string16(), &profiles_model_);
35 }
25 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 36 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
26 37
27 menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16( 38 menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16(
28 IDS_APP_LIST_OPEN_SETTINGS)); 39 IDS_APP_LIST_OPEN_SETTINGS));
29 40
30 menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16( 41 menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16(
31 IDS_APP_LIST_HELP)); 42 IDS_APP_LIST_HELP));
32 43
33 menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16( 44 menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16(
34 IDS_APP_LIST_OPEN_FEEDBACK)); 45 IDS_APP_LIST_OPEN_FEEDBACK));
35 } 46 }
36 47
37 bool AppListMenu::IsCommandIdChecked(int command_id) const { 48 bool AppListMenu::IsCommandIdChecked(int command_id) const {
38 return false; 49 return false;
39 } 50 }
40 51
41 bool AppListMenu::IsCommandIdEnabled(int command_id) const { 52 bool AppListMenu::IsCommandIdEnabled(int command_id) const {
42 return true; 53 return true;
43 } 54 }
44 55
45 bool AppListMenu::GetAcceleratorForCommandId(int command_id, 56 bool AppListMenu::GetAcceleratorForCommandId(int command_id,
46 ui::Accelerator* accelerator) { 57 ui::Accelerator* accelerator) {
47 return false; 58 return false;
48 } 59 }
49 60
50 void AppListMenu::ExecuteCommand(int command_id, int event_flags) { 61 void AppListMenu::ExecuteCommand(int command_id, int event_flags) {
62 if (command_id >= SELECT_PROFILE) {
63 delegate_->ShowForProfileAtIndex(
64 static_cast<size_t>(command_id - SELECT_PROFILE));
65 return;
66 }
51 switch (command_id) { 67 switch (command_id) {
52 case CURRENT_USER: 68 case CURRENT_USER:
53 break; // Do nothing. 69 break; // Do nothing.
54 case SHOW_SETTINGS: 70 case SHOW_SETTINGS:
55 delegate_->OpenSettings(); 71 delegate_->OpenSettings();
56 break; 72 break;
57 case SHOW_HELP: 73 case SHOW_HELP:
58 delegate_->OpenHelp(); 74 delegate_->OpenHelp();
59 break; 75 break;
60 case SHOW_FEEDBACK: 76 case SHOW_FEEDBACK:
61 delegate_->OpenFeedback(); 77 delegate_->OpenFeedback();
62 break; 78 break;
63 default: 79 default:
64 NOTREACHED(); 80 NOTREACHED();
65 } 81 }
66 } 82 }
67 83
68 } // namespace app_list 84 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698