Merge pull request #6169 from electron/map-roles-by-command-id

Map roles by command id instead of index
This commit is contained in:
Cheng Zhao 2016-06-22 01:24:20 +00:00 committed by GitHub
commit 4e811fc377
2 changed files with 6 additions and 4 deletions

View file

@ -17,12 +17,14 @@ AtomMenuModel::~AtomMenuModel() {
} }
void AtomMenuModel::SetRole(int index, const base::string16& role) { void AtomMenuModel::SetRole(int index, const base::string16& role) {
roles_[index] = role; int command_id = GetCommandIdAt(index);
roles_[command_id] = role;
} }
base::string16 AtomMenuModel::GetRoleAt(int index) { base::string16 AtomMenuModel::GetRoleAt(int index) {
if (ContainsKey(roles_, index)) int command_id = GetCommandIdAt(index);
return roles_[index]; if (ContainsKey(roles_, command_id))
return roles_[command_id];
else else
return base::string16(); return base::string16();
} }

View file

@ -42,7 +42,7 @@ class AtomMenuModel : public ui::SimpleMenuModel {
private: private:
Delegate* delegate_; // weak ref. Delegate* delegate_; // weak ref.
std::map<int, base::string16> roles_; std::map<int, base::string16> roles_; // command id -> role
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(AtomMenuModel); DISALLOW_COPY_AND_ASSIGN(AtomMenuModel);