pragma-views2
Version:
124 lines (90 loc) • 2.91 kB
JavaScript
import {Platform} from './platform.js';
export class Shortcuts {
constructor() {
this.platform = new Platform();
this._bindings = new Map([
["?", this.showBindings],
["Escape", this.close],
["ctrl + alt + m", this.toggleMenu],
["ctrl + alt + n", this.newRecord],
["ctrl + alt + p", this.peekRecord],
["ctrl + alt + t", this.toggleAssistant],
["ctrl + alt + g", this.showGrid],
["shift + alt + D", this.focusDetail],
["shift + alt + M", this.focusMaster],
["shift + alt + E", this.focusPragmaMessages],
]);
this.keyupCallback = this.keyup.bind(this);
}
activate() {
window.addEventListener("keyup", this.keyupCallback);
}
close() {
const button = document.querySelector("#btnClose");
if (button)
button.click();
}
deactivate() {
window.removeEventListener("keyup", this.keyupCallback);
this.keyupCallback = null;
}
focusDetail() {
const detail = document.querySelector("div.detail");
if (detail) {
const input = detail.querySelector("input");
if (input)
input.focus();
}
}
focusMaster() {
const master = document.querySelector("div.master");
if (master) {
const visualization = master.querySelector("visualization");
if (visualization) {
visualization.setAttribute("tabindex", "-1");
visualization.focus();
}
}
}
focusPragmaMessages() {
const messages = document.querySelector("pragma-messages");
if (messages) {
messages.focus();
}
}
keyup(event) {
const combo = this.platform.keycombo(event);
if (combo && this._bindings.has(combo)) {
const shortcut = this._bindings.get(combo);
shortcut.apply();
}
}
newRecord() {
const button = document.querySelector("#btnNew");
if (button)
button.click();
}
peekRecord() {
const button = document.querySelector("#btnPeek");
if (button)
button.click();
}
showBindings() {
}
showGrid() {
const button = document.querySelector("#btnShowGrid");
if (button)
button.click();
}
toggleAssistant() {
const assistant = document.querySelector('assistant');
if (assistant)
assistant.classList.toggle('close');
}
toggleMenu() {
const button = document.querySelector('#app-bar-button');
if (button) {
button.click();
}
}
}