Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sys_string_conversions.h" | 7 #include "base/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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 withObject:nil | 76 withObject:nil |
| 77 afterDelay:0]; | 77 afterDelay:0]; |
| 78 } | 78 } |
| 79 return self; | 79 return self; |
| 80 } | 80 } |
| 81 | 81 |
| 82 - (IBAction)switchToProfile:(id)sender { | 82 - (IBAction)switchToProfile:(id)sender { |
| 83 model_->SwitchToProfile([sender tag]); | 83 model_->SwitchToProfile([sender tag]); |
| 84 } | 84 } |
| 85 | 85 |
| 86 - (IBAction)editCurrentProfile:(id)sender { | |
|
Robert Sesek
2011/10/11 14:23:13
I don't think you need a new selector. You can onl
jeremy
2011/10/19 13:15:24
Done.
| |
| 87 model_->EditProfile(model_->GetActiveProfileIndex()); | |
| 88 } | |
| 89 | |
| 86 - (IBAction)editProfile:(id)sender { | 90 - (IBAction)editProfile:(id)sender { |
| 87 model_->EditProfile([sender tag]); | 91 model_->EditProfile([sender tag]); |
| 88 } | 92 } |
| 89 | 93 |
| 90 - (IBAction)newProfile:(id)sender { | 94 - (IBAction)newProfile:(id)sender { |
| 91 model_->AddNewProfile(); | 95 model_->AddNewProfile(); |
| 92 } | 96 } |
| 93 | 97 |
| 94 // Private ///////////////////////////////////////////////////////////////////// | 98 // Private ///////////////////////////////////////////////////////////////////// |
| 95 | 99 |
| 96 - (NSMenu*)menu { | 100 - (NSMenu*)menu { |
| 97 return [mainMenuItem_ submenu]; | 101 return [mainMenuItem_ submenu]; |
| 98 } | 102 } |
| 99 | 103 |
| 100 - (void)initializeMenu { | 104 - (void)initializeMenu { |
| 101 observer_.reset(new ProfileMenuControllerInternal::Observer(self)); | 105 observer_.reset(new ProfileMenuControllerInternal::Observer(self)); |
| 102 model_.reset(new AvatarMenuModel( | 106 model_.reset(new AvatarMenuModel( |
| 103 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 107 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
| 104 observer_.get(), | 108 observer_.get(), |
| 105 NULL)); | 109 NULL)); |
| 106 | 110 |
| 107 [[self menu] addItem:[NSMenuItem separatorItem]]; | 111 [[self menu] addItem:[NSMenuItem separatorItem]]; |
| 108 | 112 |
| 109 NSMenuItem* item = | 113 NSMenuItem* item = |
| 110 [self createItemWithTitle:l10n_util::GetNSStringWithFixup( | 114 [self createItemWithTitle:l10n_util::GetNSStringWithFixup( |
| 111 IDS_PROFILES_CUSTOMIZE_PROFILE) | 115 IDS_PROFILES_CUSTOMIZE_PROFILE) |
| 112 action:@selector(editProfile:)]; | 116 action:@selector(editCurrentProfile:)]; |
| 113 [[self menu] addItem:item]; | 117 [[self menu] addItem:item]; |
| 114 | 118 |
| 115 [[self menu] addItem:[NSMenuItem separatorItem]]; | 119 [[self menu] addItem:[NSMenuItem separatorItem]]; |
| 116 item = [self createItemWithTitle:l10n_util::GetNSStringWithFixup( | 120 item = [self createItemWithTitle:l10n_util::GetNSStringWithFixup( |
| 117 IDS_PROFILES_CREATE_NEW_PROFILE_OPTION) | 121 IDS_PROFILES_CREATE_NEW_PROFILE_OPTION) |
| 118 action:@selector(newProfile:)]; | 122 action:@selector(newProfile:)]; |
| 119 [[self menu] addItem:item]; | 123 [[self menu] addItem:item]; |
| 120 | 124 |
| 121 [self rebuildMenu]; | 125 [self rebuildMenu]; |
| 122 } | 126 } |
| 123 | 127 |
| 124 // Notifies the controller that the active browser has changed and that the | 128 // Notifies the controller that the active browser has changed and that the |
| 125 // menu item and menu need to be updated to reflect that. | 129 // menu item and menu need to be updated to reflect that. |
| 126 - (void)activeBrowserChangedTo:(Browser*)browser { | 130 - (void)activeBrowserChangedTo:(Browser*)browser { |
| 127 // Tell the model that the browser has changed. | 131 // Tell the model that the browser has changed. |
| 128 model_->set_browser(browser); | 132 model_->set_browser(browser); |
| 129 | 133 |
| 130 // Then find the profile to mark as active. | 134 size_t active_profile_index = model_->GetActiveProfileIndex(); |
| 131 Profile* profile = NULL; | |
| 132 if (!browser) | |
| 133 profile = ProfileManager::GetLastUsedProfile(); | |
| 134 else | |
| 135 profile = browser->profile(); | |
| 136 | |
| 137 ProfileInfoInterface& info = | |
| 138 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 139 size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); | |
| 140 | 135 |
| 141 // Update the state for the menu items. | 136 // Update the state for the menu items. |
| 142 for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) { | 137 for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) { |
| 143 size_t tag = model_->GetItemAt(i).model_index; | 138 size_t tag = model_->GetItemAt(i).model_index; |
| 144 [[[self menu] itemWithTag:tag] setState:index == tag ? NSOnState | 139 bool is_active = active_profile_index == tag; |
|
Robert Sesek
2011/10/11 14:23:13
Use ObjC BOOL
jeremy
2011/10/19 13:15:24
Done.
| |
| 145 : NSOffState]; | 140 [[[self menu] itemWithTag:tag] setState:is_active ? NSOnState : NSOffState]; |
| 146 } | 141 } |
| 147 } | 142 } |
| 148 | 143 |
| 149 - (void)rebuildMenu { | 144 - (void)rebuildMenu { |
| 150 NSMenu* menu = [self menu]; | 145 NSMenu* menu = [self menu]; |
| 151 | 146 |
| 152 for (NSMenuItem* item = [menu itemAtIndex:0]; | 147 for (NSMenuItem* item = [menu itemAtIndex:0]; |
| 153 ![item isSeparatorItem]; | 148 ![item isSeparatorItem]; |
| 154 item = [menu itemAtIndex:0]) { | 149 item = [menu itemAtIndex:0]) { |
| 155 [menu removeItemAtIndex:0]; | 150 [menu removeItemAtIndex:0]; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 169 } | 164 } |
| 170 | 165 |
| 171 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { | 166 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { |
| 172 scoped_nsobject<NSMenuItem> item( | 167 scoped_nsobject<NSMenuItem> item( |
| 173 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); | 168 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); |
| 174 [item setTarget:self]; | 169 [item setTarget:self]; |
| 175 return [item.release() autorelease]; | 170 return [item.release() autorelease]; |
| 176 } | 171 } |
| 177 | 172 |
| 178 @end | 173 @end |
| OLD | NEW |