| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/profile_menu_controller.h" | 5 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/avatar_menu_model.h" | 9 #include "chrome/browser/profiles/avatar_menu_model.h" |
| 10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } // namespace ProfileMenuControllerInternal | 59 } // namespace ProfileMenuControllerInternal |
| 60 | 60 |
| 61 //////////////////////////////////////////////////////////////////////////////// | 61 //////////////////////////////////////////////////////////////////////////////// |
| 62 | 62 |
| 63 @implementation ProfileMenuController | 63 @implementation ProfileMenuController |
| 64 | 64 |
| 65 - (id)initWithMainMenuItem:(NSMenuItem*)item { | 65 - (id)initWithMainMenuItem:(NSMenuItem*)item { |
| 66 if ((self = [super init])) { | 66 if ((self = [super init])) { |
| 67 mainMenuItem_ = item; | 67 mainMenuItem_ = item; |
| 68 | 68 |
| 69 scoped_nsobject<NSMenu> menu( | 69 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle: |
| 70 [[NSMenu alloc] initWithTitle: | |
| 71 l10n_util::GetNSStringWithFixup(IDS_PROFILES_OPTIONS_GROUP_NAME)]); | 70 l10n_util::GetNSStringWithFixup(IDS_PROFILES_OPTIONS_GROUP_NAME)]); |
| 72 [mainMenuItem_ setSubmenu:menu]; | 71 [mainMenuItem_ setSubmenu:menu]; |
| 73 | 72 |
| 74 // This object will be constructed as part of nib loading, which happens | 73 // This object will be constructed as part of nib loading, which happens |
| 75 // before the message loop starts and g_browser_process is available. | 74 // before the message loop starts and g_browser_process is available. |
| 76 // Schedule this on the loop to do work when the browser is ready. | 75 // Schedule this on the loop to do work when the browser is ready. |
| 77 [self performSelector:@selector(initializeMenu) | 76 [self performSelector:@selector(initializeMenu) |
| 78 withObject:nil | 77 withObject:nil |
| 79 afterDelay:0]; | 78 afterDelay:0]; |
| 80 } | 79 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 103 | 102 |
| 104 - (BOOL)insertItemsIntoMenu:(NSMenu*)menu | 103 - (BOOL)insertItemsIntoMenu:(NSMenu*)menu |
| 105 atOffset:(NSInteger)offset | 104 atOffset:(NSInteger)offset |
| 106 fromDock:(BOOL)dock { | 105 fromDock:(BOOL)dock { |
| 107 if (!model_ || !model_->ShouldShowAvatarMenu()) | 106 if (!model_ || !model_->ShouldShowAvatarMenu()) |
| 108 return NO; | 107 return NO; |
| 109 | 108 |
| 110 if (dock) { | 109 if (dock) { |
| 111 NSString* headerName = | 110 NSString* headerName = |
| 112 l10n_util::GetNSStringWithFixup(IDS_PROFILES_OPTIONS_GROUP_NAME); | 111 l10n_util::GetNSStringWithFixup(IDS_PROFILES_OPTIONS_GROUP_NAME); |
| 113 scoped_nsobject<NSMenuItem> header( | 112 base::scoped_nsobject<NSMenuItem> header( |
| 114 [[NSMenuItem alloc] initWithTitle:headerName | 113 [[NSMenuItem alloc] initWithTitle:headerName |
| 115 action:NULL | 114 action:NULL |
| 116 keyEquivalent:@""]); | 115 keyEquivalent:@""]); |
| 117 [header setEnabled:NO]; | 116 [header setEnabled:NO]; |
| 118 [menu insertItem:header atIndex:offset++]; | 117 [menu insertItem:header atIndex:offset++]; |
| 119 } | 118 } |
| 120 | 119 |
| 121 for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) { | 120 for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) { |
| 122 const AvatarMenuModel::Item& itemData = model_->GetItemAt(i); | 121 const AvatarMenuModel::Item& itemData = model_->GetItemAt(i); |
| 123 NSString* name = base::SysUTF16ToNSString(itemData.name); | 122 NSString* name = base::SysUTF16ToNSString(itemData.name); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 item = [menu itemAtIndex:0]) { | 205 item = [menu itemAtIndex:0]) { |
| 207 [menu removeItemAtIndex:0]; | 206 [menu removeItemAtIndex:0]; |
| 208 } | 207 } |
| 209 | 208 |
| 210 BOOL hasContent = [self insertItemsIntoMenu:menu atOffset:0 fromDock:NO]; | 209 BOOL hasContent = [self insertItemsIntoMenu:menu atOffset:0 fromDock:NO]; |
| 211 | 210 |
| 212 [mainMenuItem_ setHidden:!hasContent]; | 211 [mainMenuItem_ setHidden:!hasContent]; |
| 213 } | 212 } |
| 214 | 213 |
| 215 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { | 214 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { |
| 216 scoped_nsobject<NSMenuItem> item( | 215 base::scoped_nsobject<NSMenuItem> item( |
| 217 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); | 216 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); |
| 218 [item setTarget:self]; | 217 [item setTarget:self]; |
| 219 return [item.release() autorelease]; | 218 return [item.release() autorelease]; |
| 220 } | 219 } |
| 221 | 220 |
| 222 @end | 221 @end |
| OLD | NEW |