Commit 637495cd authored by jeremy@chromium.org's avatar jeremy@chromium.org

[Mac/multiprofile] "Customize User..." should edit the currently active profile

The NSMenu tag for the "Customize User..." menu item was always 0 before this patch.  Add a new selector to ProfileMenuController and use that for the menu item.

Also, move the code for determining the index of the active profile into the AvatarMenuModel.

BUG=99621
TEST=See bug


Review URL: http://codereview.chromium.org/8230011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107089 0039d316-1c4b-4281-b951-d872f2087c98
parent 8b2eb4bd
......@@ -103,6 +103,20 @@ size_t AvatarMenuModel::GetNumberOfItems() {
return items_.size();
}
size_t AvatarMenuModel::GetActiveProfileIndex() {
Profile* active_profile = NULL;
if (!browser_)
active_profile = ProfileManager::GetLastUsedProfile();
else
active_profile = browser_->profile();
size_t index =
profile_info_->GetIndexOfProfileWithPath(active_profile->GetPath());
DCHECK_LT(index, items_.size());
return index;
}
const AvatarMenuModel::Item& AvatarMenuModel::GetItemAt(size_t index) {
DCHECK_LT(index, items_.size());
return *items_[index];
......
......@@ -69,6 +69,9 @@ class AvatarMenuModel : public content::NotificationObserver {
// Gets the number of profiles.
size_t GetNumberOfItems();
// Returns the index of the active profile.
size_t GetActiveProfileIndex();
// Gets the an Item at a specified index.
const Item& GetItemAt(size_t index);
......
......@@ -72,6 +72,21 @@ TEST_F(AvatarMenuModelTest, InitialCreation) {
EXPECT_EQ(name2, item2.name);
}
TEST_F(AvatarMenuModelTest, ActiveItem) {
string16 name1(ASCIIToUTF16("Test 1"));
string16 name2(ASCIIToUTF16("Test 2"));
manager()->CreateTestingProfile("p1", name1, 0);
manager()->CreateTestingProfile("p2", name2, 0);
MockObserver observer;
AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser());
ASSERT_EQ(2U, model.GetNumberOfItems());
// TODO(jeremy): Expand test to verify active profile index other than 0
// crbug.com/100871
ASSERT_EQ(0U, model.GetActiveProfileIndex());
}
TEST_F(AvatarMenuModelTest, ModifyingNameResortsCorrectly) {
string16 name1(ASCIIToUTF16("Alpha"));
string16 name2(ASCIIToUTF16("Beta"));
......
......@@ -84,7 +84,7 @@ class Observer : public BrowserList::Observer,
}
- (IBAction)editProfile:(id)sender {
model_->EditProfile([sender tag]);
model_->EditProfile(model_->GetActiveProfileIndex());
}
- (IBAction)newProfile:(id)sender {
......@@ -127,22 +127,14 @@ class Observer : public BrowserList::Observer,
// Tell the model that the browser has changed.
model_->set_browser(browser);
// Then find the profile to mark as active.
Profile* profile = NULL;
if (!browser)
profile = ProfileManager::GetLastUsedProfile();
else
profile = browser->profile();
ProfileInfoInterface& info =
g_browser_process->profile_manager()->GetProfileInfoCache();
size_t index = info.GetIndexOfProfileWithPath(profile->GetPath());
size_t active_profile_index = model_->GetActiveProfileIndex();
// Update the state for the menu items.
for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) {
size_t tag = model_->GetItemAt(i).model_index;
[[[self menu] itemWithTag:tag] setState:index == tag ? NSOnState
: NSOffState];
[[[self menu] itemWithTag:tag]
setState:active_profile_index == tag ? NSOnState
: NSOffState];
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment