Add reset argument menu item (#1566)

This commit is contained in:
toasted-nutbread 2021-03-27 22:56:48 -04:00 committed by GitHub
parent 2098d2faae
commit 8fe0e5fdf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View File

@ -227,6 +227,7 @@ class KeyboardShortcutHotkeyEntry {
this._eventListeners.addEventListener(scopesButton, 'menuOpen', this._onScopesMenuOpen.bind(this));
this._eventListeners.addEventListener(scopesButton, 'menuClose', this._onScopesMenuClose.bind(this));
this._eventListeners.addEventListener(menuButton, 'menuOpen', this._onMenuOpen.bind(this), false);
this._eventListeners.addEventListener(menuButton, 'menuClose', this._onMenuClose.bind(this), false);
this._eventListeners.addEventListener(this._actionSelect, 'change', this._onActionSelectChange.bind(this), false);
this._eventListeners.on(this._inputField, 'change', this._onInputFieldChange.bind(this));
@ -244,6 +245,18 @@ class KeyboardShortcutHotkeyEntry {
// Private
_onMenuOpen(e) {
const {action} = this._data;
const {menu} = e.detail;
const resetArgument = menu.bodyNode.querySelector('.popup-menu-item[data-menu-action="resetArgument"]');
const details = this._parent.getActionDetails(action);
const argumentDetails = typeof details !== 'undefined' ? details.argument : void 0;
resetArgument.hidden = (typeof argumentDetails === 'undefined');
}
_onMenuClose(e) {
switch (e.detail.action) {
case 'delete':
@ -255,6 +268,9 @@ class KeyboardShortcutHotkeyEntry {
case 'resetInput':
this._resetInput();
break;
case 'resetArgument':
this._resetArgument();
break;
}
}
@ -306,9 +322,6 @@ class KeyboardShortcutHotkeyEntry {
newValue = `${DOMDataBinder.convertToNumber(value, node)}`;
break;
}
if (value !== newValue) {
this._setArgumentInputValue(node, newValue);
}
this._setArgument(newValue);
}
@ -369,6 +382,15 @@ class KeyboardShortcutHotkeyEntry {
this._inputField.setInput(key, modifiers);
}
async _resetArgument() {
const {action} = this._data;
const details = this._parent.getActionDetails(action);
const argumentDetails = typeof details !== 'undefined' ? details.argument : void 0;
let argumentDefault = typeof argumentDetails !== 'undefined' ? argumentDetails.default : void 0;
if (typeof argumentDefault !== 'string') { argumentDefault = ''; }
await this._setArgument(argumentDefault);
}
_getDefaultKeyAndModifiers(defaultHotkeys, action) {
for (const {action: action2, key, modifiers} of defaultHotkeys) {
if (action2 !== action) { continue; }
@ -438,6 +460,12 @@ class KeyboardShortcutHotkeyEntry {
async _setArgument(value) {
this._data.argument = value;
const node = this._argumentInput;
if (node !== null && this._getArgumentInputValue(node) !== value) {
this._setArgumentInputValue(node, value);
}
await this._modifyProfileSettings([{
action: 'set',
path: `${this._basePath}.argument`,

View File

@ -3180,6 +3180,7 @@
<template id="hotkey-list-item-menu-template"><div class="popup-menu-container" tabindex="-1" role="dialog"><div class="popup-menu"><div class="popup-menu-body">
<button class="popup-menu-item" data-menu-action="clearInputs">Clear input</button>
<button class="popup-menu-item" data-menu-action="resetInput">Reset input</button>
<button class="popup-menu-item" data-menu-action="resetArgument">Reset argument</button>
<button class="popup-menu-item" data-menu-action="delete">Delete</button>
</div></div></div></template>