atom_menu_model.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2015 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/ui/atom_menu_model.h"
  5. #include "base/stl_util.h"
  6. namespace atom {
  7. bool AtomMenuModel::Delegate::GetAcceleratorForCommandId(int command_id,
  8. ui::Accelerator* accelerator) const {
  9. return GetAcceleratorForCommandIdWithParams(
  10. command_id, false, accelerator);
  11. }
  12. AtomMenuModel::AtomMenuModel(Delegate* delegate)
  13. : ui::SimpleMenuModel(delegate), delegate_(delegate) {}
  14. AtomMenuModel::~AtomMenuModel() {}
  15. void AtomMenuModel::SetRole(int index, const base::string16& role) {
  16. int command_id = GetCommandIdAt(index);
  17. roles_[command_id] = role;
  18. }
  19. base::string16 AtomMenuModel::GetRoleAt(int index) {
  20. int command_id = GetCommandIdAt(index);
  21. if (base::ContainsKey(roles_, command_id))
  22. return roles_[command_id];
  23. else
  24. return base::string16();
  25. }
  26. bool AtomMenuModel::GetAcceleratorAtWithParams(
  27. int index,
  28. bool use_default_accelerator,
  29. ui::Accelerator* accelerator) const {
  30. if (delegate_) {
  31. return delegate_->GetAcceleratorForCommandIdWithParams(
  32. GetCommandIdAt(index), use_default_accelerator, accelerator);
  33. }
  34. return false;
  35. }
  36. void AtomMenuModel::MenuWillClose() {
  37. ui::SimpleMenuModel::MenuWillClose();
  38. for (Observer& observer : observers_) {
  39. observer.OnMenuWillClose();
  40. }
  41. }
  42. void AtomMenuModel::MenuWillShow() {
  43. ui::SimpleMenuModel::MenuWillShow();
  44. for (Observer& observer : observers_) {
  45. observer.OnMenuWillShow();
  46. }
  47. }
  48. AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) {
  49. return static_cast<AtomMenuModel*>(
  50. ui::SimpleMenuModel::GetSubmenuModelAt(index));
  51. }
  52. } // namespace atom