mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-30 17:58:39 +01:00
Add default keyboard shortcuts for save & cancel buttons
This commit is contained in:
parent
ad3321c438
commit
da92471920
@ -12,6 +12,7 @@
|
||||
import {css, LitElement, PropertyValues} from "lit";
|
||||
import '../Et2Image/Et2Image';
|
||||
import shoelace from "../Styles/shoelace";
|
||||
import {egw_registerGlobalShortcut} from "../../egw_action/egw_keymanager";
|
||||
|
||||
type Constructor<T = LitElement> = new (...args : any[]) => T;
|
||||
export const ButtonMixin = <T extends Constructor>(superclass : T) => class extends superclass
|
||||
@ -49,6 +50,12 @@ export const ButtonMixin = <T extends Constructor>(superclass : T) => class exte
|
||||
et2_button_delete: /delete(&|\]|$)/ // red
|
||||
};
|
||||
|
||||
static readonly default_keys : object = {
|
||||
//egw_shortcutIdx : id regex
|
||||
_83_C: /save(&|\]|$)/, // CTRL+S
|
||||
_27_: /cancel(&|\]|$)/, // Esc
|
||||
};
|
||||
|
||||
static get styles()
|
||||
{
|
||||
return [
|
||||
@ -323,6 +330,38 @@ export const ButtonMixin = <T extends Constructor>(superclass : T) => class exte
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* If button ID has a default keyboard shortcut (eg: Save: Ctrl+S), register with egw_keymanager
|
||||
*
|
||||
* @param {string} check_id
|
||||
*/
|
||||
_register_default_keyhandler(check_id : string)
|
||||
{
|
||||
if(!check_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// @ts-ignore
|
||||
for(const keyindex in this.constructor.default_keys)
|
||||
{
|
||||
// @ts-ignore
|
||||
if(check_id.match(this.constructor.default_keys[keyindex]))
|
||||
{
|
||||
let [keycode, modifiers] = keyindex.substring(1).split("_");
|
||||
egw_registerGlobalShortcut(
|
||||
parseInt(keycode),
|
||||
modifiers.includes("S"), modifiers.includes("C"), modifiers.includes("A"),
|
||||
() =>
|
||||
{
|
||||
this.dispatchEvent(new MouseEvent("click"));
|
||||
return true;
|
||||
},
|
||||
this
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a default class for the button based on ID
|
||||
*
|
||||
|
@ -30,6 +30,9 @@ export class Et2Button extends ButtonMixin(Et2InputWidget(SlButton))
|
||||
{
|
||||
super.firstUpdated(_changedProperties);
|
||||
|
||||
// Register default keyboard shortcut, if applicable
|
||||
this._register_default_keyhandler(this.id);
|
||||
|
||||
if(!this.label && this.__image)
|
||||
{
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user