Simplify parameter format for hotkeys.register_hotkey.

master
voussoir 2020-09-03 11:47:40 -07:00
parent bff4a12fcb
commit a15f14ad06
2 changed files with 20 additions and 9 deletions

View File

@ -13,7 +13,7 @@ hotkeys.hotkey_human =
function hotkey_human(key, ctrlKey, shiftKey, altKey) 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.
mods = []; var 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"); }
@ -23,10 +23,21 @@ function hotkey_human(key, ctrlKey, shiftKey, altKey)
} }
hotkeys.register_hotkey = hotkeys.register_hotkey =
function register_hotkey(key, ctrlKey, shiftKey, altKey, action, description) function register_hotkey(hotkey, action, description)
{ {
identifier = hotkeys.hotkey_identifier(key, ctrlKey, shiftKey, altKey); if (! Array.isArray(hotkey))
human = hotkeys.hotkey_human(key, ctrlKey, shiftKey, altKey); {
hotkey = hotkey.split(/\s+/g);
}
var key = hotkey.pop();
modifiers = hotkey.map(word => word.toLocaleLowerCase());
var ctrlKey = modifiers.includes("control") || modifiers.includes("ctrl");
var shiftKey = modifiers.includes("shift");
var altKey = modifiers.includes("alt");
var identifier = hotkeys.hotkey_identifier(key, ctrlKey, shiftKey, altKey);
var human = hotkeys.hotkey_human(key, ctrlKey, shiftKey, altKey);
hotkeys.HOTKEYS[identifier] = {"action": action, "human": human, "description": description} hotkeys.HOTKEYS[identifier] = {"action": action, "human": human, "description": description}
} }
@ -72,4 +83,4 @@ function hotkeys_listener(event)
window.addEventListener("keydown", hotkeys.hotkeys_listener); window.addEventListener("keydown", hotkeys.hotkeys_listener);
hotkeys.register_hotkey("/", 0, 0, 0, hotkeys.show_all_hotkeys, "Show hotkeys."); hotkeys.register_hotkey("/", hotkeys.show_all_hotkeys, "Show hotkeys.");

View File

@ -324,10 +324,10 @@ photo_clipboard.on_pageload =
function on_pageload() function on_pageload()
{ {
window.addEventListener("storage", photo_clipboard.on_storage_event, false); window.addEventListener("storage", photo_clipboard.on_storage_event, false);
hotkeys.register_hotkey("a", 1, 0, 0, photo_clipboard.select_all_photos, "Select all photos."); hotkeys.register_hotkey("ctrl a", photo_clipboard.select_all_photos, "Select all photos.");
hotkeys.register_hotkey("d", 1, 0, 0, photo_clipboard.unselect_all_photos, "Deselect all photos."); hotkeys.register_hotkey("ctrl d", photo_clipboard.unselect_all_photos, "Deselect all photos.");
hotkeys.register_hotkey("c", 0, 0, 0, photo_clipboard.clipboard_tray_collapse_toggle, "Toggle clipboard tray."); hotkeys.register_hotkey("c", photo_clipboard.clipboard_tray_collapse_toggle, "Toggle clipboard tray.");
hotkeys.register_hotkey("c", 0, 1, 0, photo_clipboard.open_full_clipboard_tab, "Open full clipboard page."); hotkeys.register_hotkey("shift c", photo_clipboard.open_full_clipboard_tab, "Open full clipboard page.");
photo_clipboard.ingest_toolbox_items(); photo_clipboard.ingest_toolbox_items();
photo_clipboard.load_clipboard(); photo_clipboard.load_clipboard();
photo_clipboard.update_pagestate(); photo_clipboard.update_pagestate();