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 [[[self menu] itemWithTag:tag] |
145 : NSOffState]; | 136 setState:active_profile_index == tag ? NSOnState |
| 137 : NSOffState]; |
146 } | 138 } |
147 } | 139 } |
148 | 140 |
149 - (void)rebuildMenu { | 141 - (void)rebuildMenu { |
150 NSMenu* menu = [self menu]; | 142 NSMenu* menu = [self menu]; |
151 | 143 |
152 for (NSMenuItem* item = [menu itemAtIndex:0]; | 144 for (NSMenuItem* item = [menu itemAtIndex:0]; |
153 ![item isSeparatorItem]; | 145 ![item isSeparatorItem]; |
154 item = [menu itemAtIndex:0]) { | 146 item = [menu itemAtIndex:0]) { |
155 [menu removeItemAtIndex:0]; | 147 [menu removeItemAtIndex:0]; |
(...skipping 15 matching lines...) Expand all Loading... |
171 } | 163 } |
172 | 164 |
173 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { | 165 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { |
174 scoped_nsobject<NSMenuItem> item( | 166 scoped_nsobject<NSMenuItem> item( |
175 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); | 167 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); |
176 [item setTarget:self]; | 168 [item setTarget:self]; |
177 return [item.release() autorelease]; | 169 return [item.release() autorelease]; |
178 } | 170 } |
179 | 171 |
180 @end | 172 @end |
OLD | NEW |