mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
saving options keyboard shortcuts
This commit is contained in:
parent
08a518479b
commit
5fac2c7633
@ -1,5 +1,5 @@
|
|||||||
import server from "../../services/server.js";
|
import server from "../../services/server.js";
|
||||||
import optionsService from "../../services/options.js";
|
import utils from "../../services/utils.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<h4>Keyboard shortcuts</h4>
|
<h4>Keyboard shortcuts</h4>
|
||||||
@ -19,9 +19,9 @@ const TPL = `
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="display: flex; justify-content: space-between">
|
<div style="display: flex; justify-content: space-between">
|
||||||
<button class="btn btn-primary">Reload app to apply changes</button>
|
<button class="btn btn-primary" id="options-keyboard-shortcuts-reload-app">Reload app to apply changes</button>
|
||||||
|
|
||||||
<button class="btn">Set all shortcuts to the default</button>
|
<button class="btn" id="options-keyboard-shortcuts-set-all-to-default">Set all shortcuts to the default</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -29,6 +29,8 @@ export default class KeyboardShortcutsOptions {
|
|||||||
constructor() {
|
constructor() {
|
||||||
$("#options-keyboard-shortcuts").html(TPL);
|
$("#options-keyboard-shortcuts").html(TPL);
|
||||||
|
|
||||||
|
$("#options-keyboard-shortcuts-reload-app").on("click", () => utils.reloadApp());
|
||||||
|
|
||||||
const $table = $("#keyboard-shortcut-table tbody");
|
const $table = $("#keyboard-shortcut-table tbody");
|
||||||
|
|
||||||
server.get('keyboard-actions').then(actions => {
|
server.get('keyboard-actions').then(actions => {
|
||||||
@ -36,7 +38,11 @@ export default class KeyboardShortcutsOptions {
|
|||||||
const $tr = $("<tr>")
|
const $tr = $("<tr>")
|
||||||
.append($("<td>").text(action.actionName))
|
.append($("<td>").text(action.actionName))
|
||||||
.append($("<td>").append(
|
.append($("<td>").append(
|
||||||
$(`<input type="text" class="form-control">`).val(action.effectiveShortcuts.join(", ")))
|
$(`<input type="text" class="form-control">`)
|
||||||
|
.val(action.effectiveShortcuts.join(", "))
|
||||||
|
.attr('data-keyboard-action-name', action.actionName)
|
||||||
|
.attr('data-default-keyboard-shortcuts', action.defaultShortcuts.join(", "))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.append($("<td>").text(action.defaultShortcuts.join(", ")))
|
.append($("<td>").text(action.defaultShortcuts.join(", ")))
|
||||||
.append($("<td>").text(action.description));
|
.append($("<td>").text(action.description));
|
||||||
@ -44,18 +50,37 @@ export default class KeyboardShortcutsOptions {
|
|||||||
$table.append($tr);
|
$table.append($tr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
async save() {
|
$table.on('change', 'input.form-control', e => {
|
||||||
const enabledMimeTypes = [];
|
const $input = $(e.target);
|
||||||
|
const actionName = $input.attr('data-keyboard-action-name');
|
||||||
|
const shortcuts = $input.val()
|
||||||
|
.replace('+,', "+Comma")
|
||||||
|
.split(",")
|
||||||
|
.map(shortcut => shortcut.replace("+Comma", "+,"));
|
||||||
|
|
||||||
this.$mimeTypes.find("input:checked").each(
|
const opts = {};
|
||||||
(i, el) => enabledMimeTypes.push($(el).attr("data-mime-type")));
|
opts['keyboardShortcuts' + actionName] = JSON.stringify(shortcuts);
|
||||||
|
|
||||||
const opts = { codeNotesMimeTypes: JSON.stringify(enabledMimeTypes) };
|
server.put('options', opts);
|
||||||
|
});
|
||||||
|
|
||||||
await server.put('options', opts);
|
$("#options-keyboard-shortcuts-set-all-to-default").on('click', async () => {
|
||||||
|
const confirmDialog = await import('../confirm.js');
|
||||||
|
|
||||||
await optionsService.reloadOptions();
|
if (!await confirmDialog.confirm("Do you really want to reset all keyboard shortcuts to the default?")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$table.find('input.form-control').each(function() {
|
||||||
|
const defaultShortcuts = $(this).attr('data-default-keyboard-shortcuts');
|
||||||
|
|
||||||
|
if ($(this).val() !== defaultShortcuts) {
|
||||||
|
$(this)
|
||||||
|
.val(defaultShortcuts)
|
||||||
|
.trigger('change');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -153,7 +153,11 @@ function registerEntrypoints() {
|
|||||||
caseSelectedColor: 'var(--main-border-color)'
|
caseSelectedColor: 'var(--main-border-color)'
|
||||||
});
|
});
|
||||||
|
|
||||||
setActionHandler("FindInText", () => findInPage.openFindWindow());
|
setActionHandler("FindInText", () => {
|
||||||
|
if (!glob.activeDialog || !glob.activeDialog.is(":visible")) {
|
||||||
|
findInPage.openFindWindow();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
|
@ -137,7 +137,10 @@ function bindGlobalShortcut(keyboardShortcut, handler) {
|
|||||||
|
|
||||||
function bindElShortcut($el, keyboardShortcut, handler) {
|
function bindElShortcut($el, keyboardShortcut, handler) {
|
||||||
if (isDesktop()) {
|
if (isDesktop()) {
|
||||||
keyboardShortcut = keyboardShortcut.replace("mod", isMac() ? "meta" : "ctrl");
|
keyboardShortcut = keyboardShortcut
|
||||||
|
.toLowerCase()
|
||||||
|
.replace("ctrl+alt", "alt+ctrl")
|
||||||
|
.replace("meta+alt", "alt+meta"); // alt needs to be first
|
||||||
|
|
||||||
$el.bind('keydown', keyboardShortcut, e => {
|
$el.bind('keydown', keyboardShortcut, e => {
|
||||||
handler(e);
|
handler(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user