OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/avatar_menu.h" | 10 #include "chrome/browser/profiles/avatar_menu.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 //////////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////////// |
65 | 65 |
66 @implementation ProfileMenuController | 66 @implementation ProfileMenuController |
67 | 67 |
68 - (id)initWithMainMenuItem:(NSMenuItem*)item { | 68 - (id)initWithMainMenuItem:(NSMenuItem*)item { |
69 if ((self = [super init])) { | 69 if ((self = [super init])) { |
70 mainMenuItem_ = item; | 70 mainMenuItem_ = item; |
71 | 71 |
72 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle: | 72 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle: |
73 l10n_util::GetNSStringWithFixup(switches::IsNewAvatarMenu() ? | 73 l10n_util::GetNSStringWithFixup(IDS_NEW_PROFILES_OPTIONS_GROUP_NAME)]); |
74 IDS_NEW_PROFILES_OPTIONS_GROUP_NAME : | |
75 IDS_PROFILES_OPTIONS_GROUP_NAME)]); | |
76 [mainMenuItem_ setSubmenu:menu]; | 74 [mainMenuItem_ setSubmenu:menu]; |
77 | 75 |
78 // This object will be constructed as part of nib loading, which happens | 76 // This object will be constructed as part of nib loading, which happens |
79 // before the message loop starts and g_browser_process is available. | 77 // before the message loop starts and g_browser_process is available. |
80 // Schedule this on the loop to do work when the browser is ready. | 78 // Schedule this on the loop to do work when the browser is ready. |
81 [self performSelector:@selector(initializeMenu) | 79 [self performSelector:@selector(initializeMenu) |
82 withObject:nil | 80 withObject:nil |
83 afterDelay:0]; | 81 afterDelay:0]; |
84 } | 82 } |
85 return self; | 83 return self; |
(...skipping 19 matching lines...) Expand all Loading... |
105 menu_->AddNewProfile(ProfileMetrics::ADD_NEW_USER_MENU); | 103 menu_->AddNewProfile(ProfileMetrics::ADD_NEW_USER_MENU); |
106 } | 104 } |
107 | 105 |
108 - (BOOL)insertItemsIntoMenu:(NSMenu*)menu | 106 - (BOOL)insertItemsIntoMenu:(NSMenu*)menu |
109 atOffset:(NSInteger)offset | 107 atOffset:(NSInteger)offset |
110 fromDock:(BOOL)dock { | 108 fromDock:(BOOL)dock { |
111 if (!menu_ || !menu_->ShouldShowAvatarMenu()) | 109 if (!menu_ || !menu_->ShouldShowAvatarMenu()) |
112 return NO; | 110 return NO; |
113 | 111 |
114 if (dock) { | 112 if (dock) { |
115 NSString* headerName = l10n_util::GetNSStringWithFixup( | 113 NSString* headerName = |
116 switches::IsNewAvatarMenu() ? IDS_NEW_PROFILES_OPTIONS_GROUP_NAME : | 114 l10n_util::GetNSStringWithFixup(IDS_NEW_PROFILES_OPTIONS_GROUP_NAME); |
117 IDS_PROFILES_OPTIONS_GROUP_NAME); | |
118 base::scoped_nsobject<NSMenuItem> header( | 115 base::scoped_nsobject<NSMenuItem> header( |
119 [[NSMenuItem alloc] initWithTitle:headerName | 116 [[NSMenuItem alloc] initWithTitle:headerName |
120 action:NULL | 117 action:NULL |
121 keyEquivalent:@""]); | 118 keyEquivalent:@""]); |
122 [header setEnabled:NO]; | 119 [header setEnabled:NO]; |
123 [menu insertItem:header atIndex:offset++]; | 120 [menu insertItem:header atIndex:offset++]; |
124 } | 121 } |
125 | 122 |
126 for (size_t i = 0; i < menu_->GetNumberOfItems(); ++i) { | 123 for (size_t i = 0; i < menu_->GetNumberOfItems(); ++i) { |
127 const AvatarMenu::Item& itemData = menu_->GetItemAt(i); | 124 const AvatarMenu::Item& itemData = menu_->GetItemAt(i); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 - (void)initializeMenu { | 183 - (void)initializeMenu { |
187 observer_.reset(new ProfileMenuControllerInternal::Observer(self)); | 184 observer_.reset(new ProfileMenuControllerInternal::Observer(self)); |
188 menu_.reset(new AvatarMenu( | 185 menu_.reset(new AvatarMenu( |
189 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 186 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
190 observer_.get(), | 187 observer_.get(), |
191 NULL)); | 188 NULL)); |
192 menu_->RebuildMenu(); | 189 menu_->RebuildMenu(); |
193 | 190 |
194 [[self menu] addItem:[NSMenuItem separatorItem]]; | 191 [[self menu] addItem:[NSMenuItem separatorItem]]; |
195 | 192 |
196 bool usingNewProfilesUI = switches::IsNewAvatarMenu(); | 193 NSMenuItem* item = [self createItemWithTitle: |
197 NSString* editProfileTitle = l10n_util::GetNSStringWithFixup( | 194 l10n_util::GetNSStringWithFixup(IDS_PROFILES_MANAGE_BUTTON_LABEL) |
198 usingNewProfilesUI ? IDS_PROFILES_MANAGE_BUTTON_LABEL : | |
199 IDS_PROFILES_CUSTOMIZE_PROFILE); | |
200 NSString* newProfileTitle = l10n_util::GetNSStringWithFixup( | |
201 usingNewProfilesUI ? IDS_NEW_PROFILES_CREATE_NEW_PROFILE_OPTION : | |
202 IDS_PROFILES_CREATE_NEW_PROFILE_OPTION); | |
203 | |
204 NSMenuItem* item = [self createItemWithTitle:editProfileTitle | |
205 action:@selector(editProfile:)]; | 195 action:@selector(editProfile:)]; |
206 [[self menu] addItem:item]; | 196 [[self menu] addItem:item]; |
207 | 197 |
208 [[self menu] addItem:[NSMenuItem separatorItem]]; | 198 [[self menu] addItem:[NSMenuItem separatorItem]]; |
209 item = [self createItemWithTitle:newProfileTitle | 199 item = [self createItemWithTitle:l10n_util::GetNSStringWithFixup( |
| 200 IDS_NEW_PROFILES_CREATE_NEW_PROFILE_OPTION) |
210 action:@selector(newProfile:)]; | 201 action:@selector(newProfile:)]; |
211 [[self menu] addItem:item]; | 202 [[self menu] addItem:item]; |
212 | 203 |
213 [self rebuildMenu]; | 204 [self rebuildMenu]; |
214 } | 205 } |
215 | 206 |
216 // Notifies the controller that the active browser has changed and that the | 207 // Notifies the controller that the active browser has changed and that the |
217 // menu item and menu need to be updated to reflect that. | 208 // menu item and menu need to be updated to reflect that. |
218 - (void)activeBrowserChangedTo:(Browser*)browser { | 209 - (void)activeBrowserChangedTo:(Browser*)browser { |
219 // Tell the menu that the browser has changed. | 210 // Tell the menu that the browser has changed. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 250 } |
260 | 251 |
261 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { | 252 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { |
262 base::scoped_nsobject<NSMenuItem> item( | 253 base::scoped_nsobject<NSMenuItem> item( |
263 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); | 254 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); |
264 [item setTarget:self]; | 255 [item setTarget:self]; |
265 return [item.release() autorelease]; | 256 return [item.release() autorelease]; |
266 } | 257 } |
267 | 258 |
268 @end | 259 @end |
OLD | NEW |