accelerator_util.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_
  5. #define ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_
  6. #include <map>
  7. #include <string>
  8. #include "base/memory/raw_ptr.h"
  9. #include "shell/browser/ui/electron_menu_model.h"
  10. #include "ui/base/accelerators/accelerator.h"
  11. namespace accelerator_util {
  12. typedef struct {
  13. size_t position;
  14. raw_ptr<electron::ElectronMenuModel> model;
  15. } MenuItem;
  16. typedef std::map<ui::Accelerator, MenuItem> AcceleratorTable;
  17. // Parse a string as an accelerator.
  18. bool StringToAccelerator(const std::string& shortcut,
  19. ui::Accelerator* accelerator);
  20. // Generate a table that contains menu model's accelerators and command ids.
  21. void GenerateAcceleratorTable(AcceleratorTable* table,
  22. electron::ElectronMenuModel* model);
  23. // Trigger command from the accelerators table.
  24. bool TriggerAcceleratorTableCommand(AcceleratorTable* table,
  25. const ui::Accelerator& accelerator);
  26. } // namespace accelerator_util
  27. #endif // ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_