Add hotkeys.register_help, forward the event to the hotkey's func.
This commit is contained in:
parent
ebe6fcb07d
commit
01a4864762
1 changed files with 20 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
const hotkeys = {};
|
const hotkeys = {};
|
||||||
|
|
||||||
hotkeys.HOTKEYS = {};
|
hotkeys.HOTKEYS = {};
|
||||||
|
hotkeys.HELPS = [];
|
||||||
|
|
||||||
hotkeys.hotkey_identifier =
|
hotkeys.hotkey_identifier =
|
||||||
function hotkey_identifier(key, ctrlKey, shiftKey, altKey)
|
function hotkey_identifier(key, ctrlKey, shiftKey, altKey)
|
||||||
|
@ -14,14 +15,20 @@ function hotkey_human(key, ctrlKey, shiftKey, altKey)
|
||||||
{
|
{
|
||||||
// Return the string that will be displayed to the user to represent this hotkey.
|
// Return the string that will be displayed to the user to represent this hotkey.
|
||||||
let mods = [];
|
let mods = [];
|
||||||
if (ctrlKey) { mods.push("Ctrl"); }
|
if (ctrlKey) { mods.push("CTRL"); }
|
||||||
if (shiftKey) { mods.push("Shift"); }
|
if (shiftKey) { mods.push("SHIFT"); }
|
||||||
if (altKey) { mods.push("Alt"); }
|
if (altKey) { mods.push("ALT"); }
|
||||||
mods = mods.join("+");
|
mods = mods.join("+");
|
||||||
if (mods) { mods = mods + "+"; }
|
if (mods) { mods = mods + "+"; }
|
||||||
return mods + key.toUpperCase();
|
return mods + key.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hotkeys.register_help =
|
||||||
|
function register_help(help)
|
||||||
|
{
|
||||||
|
hotkeys.HELPS.push(help);
|
||||||
|
}
|
||||||
|
|
||||||
hotkeys.register_hotkey =
|
hotkeys.register_hotkey =
|
||||||
function register_hotkey(hotkey, action, description)
|
function register_hotkey(hotkey, action, description)
|
||||||
{
|
{
|
||||||
|
@ -68,6 +75,14 @@ function show_all_hotkeys()
|
||||||
const line = hotkeys.HOTKEYS[identifier]["human"] + " : " + hotkeys.HOTKEYS[identifier]["description"];
|
const line = hotkeys.HOTKEYS[identifier]["human"] + " : " + hotkeys.HOTKEYS[identifier]["description"];
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
}
|
}
|
||||||
|
if (hotkeys.HELPS)
|
||||||
|
{
|
||||||
|
lines.push("");
|
||||||
|
}
|
||||||
|
for (const help of hotkeys.HELPS)
|
||||||
|
{
|
||||||
|
lines.push(help);
|
||||||
|
}
|
||||||
lines = lines.join("\n");
|
lines = lines.join("\n");
|
||||||
alert(lines);
|
alert(lines);
|
||||||
}
|
}
|
||||||
|
@ -75,6 +90,7 @@ function show_all_hotkeys()
|
||||||
hotkeys.hotkeys_listener =
|
hotkeys.hotkeys_listener =
|
||||||
function hotkeys_listener(event)
|
function hotkeys_listener(event)
|
||||||
{
|
{
|
||||||
|
// console.log(event.key);
|
||||||
if (hotkeys.should_prevent_hotkey(event))
|
if (hotkeys.should_prevent_hotkey(event))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -84,7 +100,7 @@ function hotkeys_listener(event)
|
||||||
//console.log(identifier);
|
//console.log(identifier);
|
||||||
if (identifier in hotkeys.HOTKEYS)
|
if (identifier in hotkeys.HOTKEYS)
|
||||||
{
|
{
|
||||||
hotkeys.HOTKEYS[identifier]["action"]();
|
hotkeys.HOTKEYS[identifier]["action"](event);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue