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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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)editProfile:(id)sender { | 86 - (IBAction)editProfile:(id)sender { |
| 87 model_->EditProfile([sender tag]); | 87 model_->EditProfile(model_->GetActiveProfileIndex()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 - (IBAction)newProfile:(id)sender { | 90 - (IBAction)newProfile:(id)sender { |
| 91 model_->AddNewProfile(); | 91 model_->AddNewProfile(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Private ///////////////////////////////////////////////////////////////////// | 94 // Private ///////////////////////////////////////////////////////////////////// |
| 95 | 95 |
| 96 - (NSMenu*)menu { | 96 - (NSMenu*)menu { |
| 97 return [mainMenuItem_ submenu]; | 97 return [mainMenuItem_ submenu]; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 120 | 120 |
| 121 [self rebuildMenu]; | 121 [self rebuildMenu]; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Notifies the controller that the active browser has changed and that the | 124 // Notifies the controller that the active browser has changed and that the |
| 125 // menu item and menu need to be updated to reflect that. | 125 // menu item and menu need to be updated to reflect that. |
| 126 - (void)activeBrowserChangedTo:(Browser*)browser { | 126 - (void)activeBrowserChangedTo:(Browser*)browser { |
| 127 // Tell the model that the browser has changed. | 127 // Tell the model that the browser has changed. |
| 128 model_->set_browser(browser); | 128 model_->set_browser(browser); |
| 129 | 129 |
| 130 // Then find the profile to mark as active. | 130 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 | 131 |
| 141 // Update the state for the menu items. | 132 // Update the state for the menu items. |
| 142 for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) { | 133 for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) { |
| 143 size_t tag = model_->GetItemAt(i).model_index; | 134 size_t tag = model_->GetItemAt(i).model_index; |
| 144 [[[self menu] itemWithTag:tag] setState:index == tag ? NSOnState | 135 BOOL is_active = (active_profile_index == tag) ? YES : NO; |
|
Robert Sesek
2011/10/19 15:07:40
Why pull this out into a separate variable? The or
| |
| 145 : NSOffState]; | 136 [[[self menu] itemWithTag:tag] setState:is_active ? NSOnState : NSOffState]; |
| 146 } | 137 } |
| 147 } | 138 } |
| 148 | 139 |
| 149 - (void)rebuildMenu { | 140 - (void)rebuildMenu { |
| 150 NSMenu* menu = [self menu]; | 141 NSMenu* menu = [self menu]; |
| 151 | 142 |
| 152 for (NSMenuItem* item = [menu itemAtIndex:0]; | 143 for (NSMenuItem* item = [menu itemAtIndex:0]; |
| 153 ![item isSeparatorItem]; | 144 ![item isSeparatorItem]; |
| 154 item = [menu itemAtIndex:0]) { | 145 item = [menu itemAtIndex:0]) { |
| 155 [menu removeItemAtIndex:0]; | 146 [menu removeItemAtIndex:0]; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 171 } | 162 } |
| 172 | 163 |
| 173 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { | 164 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { |
| 174 scoped_nsobject<NSMenuItem> item( | 165 scoped_nsobject<NSMenuItem> item( |
| 175 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); | 166 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); |
| 176 [item setTarget:self]; | 167 [item setTarget:self]; |
| 177 return [item.release() autorelease]; | 168 return [item.release() autorelease]; |
| 178 } | 169 } |
| 179 | 170 |
| 180 @end | 171 @end |
| OLD | NEW |