6#include "TTauri/GUI/KeyboardKey.hpp"
7#include "TTauri/Foundation/string_tag.hpp"
8#include "TTauri/Foundation/URL.hpp"
9#include "TTauri/Foundation/os_detect.hpp"
10#include <unordered_map>
18 return tt::hash_mix(rhs.first, rhs.second);
45 ttlet i =
std::find(system.cbegin(), system.cend(), cmd);
46 if (i == system.cend()) {
47 system.push_back(cmd);
52 void add_ignored_command(
string_ltag cmd)
noexcept {
54 if (i == ignored.
cend()) {
62 if (i == user.
cend()) {
68 void update_cache()
noexcept {
69 cache.
reserve(ssize(system) + ssize(user));
71 for (ttlet cmd: system) {
73 if (i == cache.
cend()) {
78 for (ttlet cmd: ignored) {
80 if (i != cache.
cend()) {
85 for (ttlet cmd: user) {
87 if (i == cache.
cend()) {
103 bindings[key].add_system_command(command);
107 bindings[key].add_ignored_command(command);
111 bindings[key].add_user_command(command);
119 ttlet i = bindings.
find(key);
120 if (i != bindings.
cend()) {
121 return i->second.get_commands();
123 return empty_commands;
143 if constexpr (OperatingSystem::current == OperatingSystem::Windows) {
150 void loadUserBindings(
URL url) {
Definition KeyboardBindings.hpp:26
void loadSystemBindings()
Load system bindings.
Definition KeyboardBindings.hpp:142
void loadBindings(URL url, bool system_binding)
Load bindings from a JSON file.
std::vector< string_ltag > const & translate(KeyboardKey key) const noexcept
translate a key press in the empty-context to a command.
Definition KeyboardBindings.hpp:116
void clear() noexcept
Clear all bindings.
Definition KeyboardBindings.hpp:132
void saveUserBindings(URL url)
Save user bindings This will save all bindings that are different from the system bindings.
A key in combination with modifiers.
Definition KeyboardKey.hpp:23