electron/atom/browser/ui/atom_menu_model.cc

66 lines
1.7 KiB
C++
Raw Normal View History

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 {
bool AtomMenuModel::Delegate::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) const {
return GetAcceleratorForCommandIdWithParams(command_id, false, accelerator);
}
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();
}
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;
}
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
}
AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) {
return static_cast<AtomMenuModel*>(
2016-07-07 21:28:01 +00:00
ui::SimpleMenuModel::GetSubmenuModelAt(index));
}
2015-08-10 04:39:05 +00:00
} // namespace atom