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 {
|
|
|
|
|
2018-09-19 11:10:26 +00:00
|
|
|
bool AtomMenuModel::Delegate::GetAcceleratorForCommandId(
|
|
|
|
int command_id,
|
2018-04-17 23:47:47 +00:00
|
|
|
ui::Accelerator* accelerator) const {
|
2018-09-19 11:10:26 +00:00
|
|
|
return GetAcceleratorForCommandIdWithParams(command_id, false, accelerator);
|
2018-04-17 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
AtomMenuModel::AtomMenuModel(Delegate* delegate)
|
2018-04-18 01:55:30 +00:00
|
|
|
: ui::SimpleMenuModel(delegate), delegate_(delegate) {}
|
2015-08-10 04:39:05 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
AtomMenuModel::~AtomMenuModel() {}
|
2015-08-10 04:39:05 +00:00
|
|
|
|
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);
|
2016-12-12 01:35:29 +00:00
|
|
|
if (base::ContainsKey(roles_, command_id))
|
2016-06-21 22:25:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-26 18:43:55 +00:00
|
|
|
bool AtomMenuModel::ShouldRegisterAcceleratorAt(int index) const {
|
|
|
|
if (delegate_) {
|
|
|
|
return delegate_->ShouldRegisterAcceleratorForCommandId(
|
|
|
|
GetCommandIdAt(index));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-23 08:53:53 +00:00
|
|
|
void AtomMenuModel::MenuWillClose() {
|
|
|
|
ui::SimpleMenuModel::MenuWillClose();
|
2018-01-27 14:35:58 +00:00
|
|
|
for (Observer& observer : observers_) {
|
|
|
|
observer.OnMenuWillClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomMenuModel::MenuWillShow() {
|
|
|
|
ui::SimpleMenuModel::MenuWillShow();
|
|
|
|
for (Observer& observer : observers_) {
|
|
|
|
observer.OnMenuWillShow();
|
|
|
|
}
|
2015-08-10 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 23:04:18 +00:00
|
|
|
AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) {
|
|
|
|
return static_cast<AtomMenuModel*>(
|
2016-07-07 21:28:01 +00:00
|
|
|
ui::SimpleMenuModel::GetSubmenuModelAt(index));
|
2016-07-06 23:04:18 +00:00
|
|
|
}
|
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
} // namespace atom
|