2015-08-10 04:39:05 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/ui/atom_menu_model.h"
|
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
#include "base/stl_util.h"
|
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
AtomMenuModel::AtomMenuModel(Delegate* delegate)
|
|
|
|
: ui::SimpleMenuModel(delegate),
|
|
|
|
delegate_(delegate) {
|
|
|
|
}
|
|
|
|
|
|
|
|
AtomMenuModel::~AtomMenuModel() {
|
|
|
|
}
|
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
void AtomMenuModel::SetRole(int index, const base::string16& role) {
|
2016-06-21 22:25:14 +00:00
|
|
|
int command_id = GetCommandIdAt(index);
|
|
|
|
roles_[command_id] = role;
|
2015-09-01 11:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
base::string16 AtomMenuModel::GetRoleAt(int index) {
|
2016-06-21 22:25:14 +00:00
|
|
|
int command_id = GetCommandIdAt(index);
|
|
|
|
if (ContainsKey(roles_, command_id))
|
|
|
|
return roles_[command_id];
|
2015-09-01 11:48:11 +00:00
|
|
|
else
|
|
|
|
return base::string16();
|
|
|
|
}
|
|
|
|
|
2016-07-02 02:47:40 +00:00
|
|
|
bool AtomMenuModel::GetAcceleratorAtWithParams(
|
|
|
|
int index,
|
|
|
|
bool use_default_accelerator,
|
|
|
|
ui::Accelerator* accelerator) const {
|
|
|
|
if (delegate_) {
|
|
|
|
return delegate_->GetAcceleratorForCommandIdWithParams(
|
|
|
|
GetCommandIdAt(index), use_default_accelerator, accelerator);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
void AtomMenuModel::MenuClosed() {
|
|
|
|
ui::SimpleMenuModel::MenuClosed();
|
|
|
|
FOR_EACH_OBSERVER(Observer, observers_, MenuClosed());
|
|
|
|
}
|
|
|
|
|
2016-07-06 23:04:18 +00:00
|
|
|
AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) {
|
|
|
|
return static_cast<AtomMenuModel*>(
|
|
|
|
ui::SimpleMenuModel::GetSubmenuModelAt(index));
|
|
|
|
}
|
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
} // namespace atom
|