note can be activated through 'keyboardShortcut' label

This commit is contained in:
zadam 2019-11-24 18:32:18 +01:00
parent 60c3b5cccc
commit cd139bdd76
4 changed files with 25 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import server from "./server.js";
import utils from "./utils.js";
import tree from "./tree.js";
class KeyboardAction {
constructor(params) {
@ -33,6 +34,16 @@ const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => {
}
});
server.get('keyboard-shortcuts-for-notes').then(shortcutForNotes => {
for (const shortcut in shortcutForNotes) {
utils.bindGlobalShortcut(shortcut, async () => {
const treeService = (await import("./tree.js")).default;
treeService.activateNote(shortcutForNotes[shortcut]);
});
}
});
function setGlobalActionHandler(actionName, handler) {
keyboardActionsLoaded.then(() => {
const action = keyboardActionRepo[actionName];

View File

@ -1,11 +1,22 @@
"use strict";
const keyboardActions = require('../../services/keyboard_actions');
const sql = require('../../services/sql');
async function getKeyboardActions() {
return await keyboardActions.getKeyboardActions();
}
async function getShortcutsForNotes() {
return await sql.getMap(`
SELECT value, noteId
FROM attributes
WHERE isDeleted = 0
AND type = 'label'
AND name = 'keyboardShortcut'`);
}
module.exports = {
getKeyboardActions
getKeyboardActions,
getShortcutsForNotes
};

View File

@ -246,6 +246,7 @@ function register(app) {
apiRoute(GET, '/api/similar-notes/:noteId', similarNotesRoute.getSimilarNotes);
apiRoute(GET, '/api/keyboard-actions', keysRoute.getKeyboardActions);
apiRoute(GET, '/api/keyboard-shortcuts-for-notes', keysRoute.getShortcutsForNotes);
app.use('', router);
}

View File

@ -21,6 +21,7 @@ const BUILTIN_ATTRIBUTES = [
{ type: 'label', name: 'readOnly' },
{ type: 'label', name: 'cssClass' },
{ type: 'label', name: 'iconClass' },
{ type: 'label', name: 'keyboardShortcut' },
{ type: 'label', name: 'run', isDangerous: true },
{ type: 'label', name: 'customRequestHandler', isDangerous: true },
{ type: 'label', name: 'customResourceProvider', isDangerous: true },