2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-14 21:12:27 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_
|
2013-05-14 21:12:27 +08:00
|
|
|
|
2014-03-15 16:36:29 +08:00
|
|
|
#include <map>
|
2013-07-01 21:56:46 +08:00
|
|
|
#include <string>
|
2013-05-14 21:12:27 +08:00
|
|
|
|
2023-05-11 16:07:39 -04:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2020-02-04 12:19:40 -08:00
|
|
|
#include "shell/browser/ui/electron_menu_model.h"
|
2014-03-15 16:36:29 +08:00
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
|
|
|
|
2013-05-14 21:12:27 +08:00
|
|
|
namespace accelerator_util {
|
|
|
|
|
2018-04-17 21:44:10 -04:00
|
|
|
typedef struct {
|
2022-08-17 11:35:53 -07:00
|
|
|
size_t position;
|
2023-05-11 16:07:39 -04:00
|
|
|
raw_ptr<electron::ElectronMenuModel> model;
|
2018-04-17 21:44:10 -04:00
|
|
|
} MenuItem;
|
2014-03-15 16:36:29 +08:00
|
|
|
typedef std::map<ui::Accelerator, MenuItem> AcceleratorTable;
|
|
|
|
|
2013-05-14 21:12:27 +08:00
|
|
|
// Parse a string as an accelerator.
|
2021-05-31 18:46:25 -07:00
|
|
|
bool StringToAccelerator(const std::string& shortcut,
|
2013-05-14 21:12:27 +08:00
|
|
|
ui::Accelerator* accelerator);
|
|
|
|
|
2021-05-31 18:42:38 -07:00
|
|
|
// Generate a table that contains menu model's accelerators and command ids.
|
2016-07-06 16:04:18 -07:00
|
|
|
void GenerateAcceleratorTable(AcceleratorTable* table,
|
2020-02-04 12:19:40 -08:00
|
|
|
electron::ElectronMenuModel* model);
|
2014-03-15 16:36:29 +08:00
|
|
|
|
|
|
|
// Trigger command from the accelerators table.
|
|
|
|
bool TriggerAcceleratorTableCommand(AcceleratorTable* table,
|
|
|
|
const ui::Accelerator& accelerator);
|
|
|
|
|
2013-05-14 21:12:27 +08:00
|
|
|
} // namespace accelerator_util
|
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_
|