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.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/ui/electron_menu_model.h"
|
2015-08-10 04:39:05 +00:00
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
#include "base/stl_util.h"
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-08-10 04:39:05 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronMenuModel::Delegate::GetAcceleratorForCommandId(
|
2018-09-19 11:10:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronMenuModel::ElectronMenuModel(Delegate* delegate)
|
2018-04-18 01:55:30 +00:00
|
|
|
: ui::SimpleMenuModel(delegate), delegate_(delegate) {}
|
2015-08-10 04:39:05 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronMenuModel::~ElectronMenuModel() = default;
|
2015-08-10 04:39:05 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronMenuModel::SetToolTip(int index, const base::string16& toolTip) {
|
2019-07-11 08:56:22 +00:00
|
|
|
int command_id = GetCommandIdAt(index);
|
|
|
|
toolTips_[command_id] = toolTip;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
base::string16 ElectronMenuModel::GetToolTipAt(int index) {
|
2019-08-28 14:39:21 +00:00
|
|
|
const int command_id = GetCommandIdAt(index);
|
|
|
|
const auto iter = toolTips_.find(command_id);
|
|
|
|
return iter == std::end(toolTips_) ? base::string16() : iter->second;
|
2019-07-11 08:56:22 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronMenuModel::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
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
base::string16 ElectronMenuModel::GetRoleAt(int index) {
|
2019-08-28 14:39:21 +00:00
|
|
|
const int command_id = GetCommandIdAt(index);
|
|
|
|
const auto iter = roles_.find(command_id);
|
|
|
|
return iter == std::end(roles_) ? base::string16() : iter->second;
|
2015-09-01 11:48:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronMenuModel::SetSublabel(int index, const base::string16& sublabel) {
|
2019-10-04 06:58:54 +00:00
|
|
|
int command_id = GetCommandIdAt(index);
|
|
|
|
sublabels_[command_id] = sublabel;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
base::string16 ElectronMenuModel::GetSublabelAt(int index) const {
|
2019-10-04 06:58:54 +00:00
|
|
|
int command_id = GetCommandIdAt(index);
|
|
|
|
const auto iter = sublabels_.find(command_id);
|
|
|
|
return iter == std::end(sublabels_) ? base::string16() : iter->second;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronMenuModel::GetAcceleratorAtWithParams(
|
2016-07-02 02:47:40 +00:00
|
|
|
int index,
|
|
|
|
bool use_default_accelerator,
|
|
|
|
ui::Accelerator* accelerator) const {
|
|
|
|
if (delegate_) {
|
|
|
|
return delegate_->GetAcceleratorForCommandIdWithParams(
|
|
|
|
GetCommandIdAt(index), use_default_accelerator, accelerator);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronMenuModel::ShouldRegisterAcceleratorAt(int index) const {
|
2018-11-26 18:43:55 +00:00
|
|
|
if (delegate_) {
|
|
|
|
return delegate_->ShouldRegisterAcceleratorForCommandId(
|
|
|
|
GetCommandIdAt(index));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronMenuModel::WorksWhenHiddenAt(int index) const {
|
2019-02-28 17:00:54 +00:00
|
|
|
if (delegate_) {
|
|
|
|
return delegate_->ShouldCommandIdWorkWhenHidden(GetCommandIdAt(index));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronMenuModel::MenuWillClose() {
|
2017-01-23 08:53:53 +00:00
|
|
|
ui::SimpleMenuModel::MenuWillClose();
|
2018-01-27 14:35:58 +00:00
|
|
|
for (Observer& observer : observers_) {
|
|
|
|
observer.OnMenuWillClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronMenuModel::MenuWillShow() {
|
2018-01-27 14:35:58 +00:00
|
|
|
ui::SimpleMenuModel::MenuWillShow();
|
|
|
|
for (Observer& observer : observers_) {
|
|
|
|
observer.OnMenuWillShow();
|
|
|
|
}
|
2015-08-10 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronMenuModel* ElectronMenuModel::GetSubmenuModelAt(int index) {
|
|
|
|
return static_cast<ElectronMenuModel*>(
|
2016-07-07 21:28:01 +00:00
|
|
|
ui::SimpleMenuModel::GetSubmenuModelAt(index));
|
2016-07-06 23:04:18 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|