Skip to content

Build your personal knowledge base with Trilium Notes

launchbar WIP

zadam2694bcff673f
diff --git a/src/public/app/doc_notes/launchbar_note_shortcut.html b/src/public/app/doc_notes/launchbar_note_shortcut.html
new file mode 100644
index 0000000000..055bca59e9
--- /dev/null
+++ b/src/public/app/doc_notes/launchbar_note_shortcut.html
@@ -0,0 +1,3 @@
+<p>Please define the target note in the promoted attributes.</p>
+
+<p>Launchbar displays the title / icon from the shortcut which does not necessarily mirrors those of the target note.</p>
diff --git a/src/public/app/doc_notes/launchbar_script_shortcut.html b/src/public/app/doc_notes/launchbar_script_shortcut.html
new file mode 100644
index 0000000000..2bad3c1ea0
--- /dev/null
+++ b/src/public/app/doc_notes/launchbar_script_shortcut.html
@@ -0,0 +1,3 @@
+<p>Please define the target script note in the promoted attributes. This script will be executed immediately upon clicking the launchbar icon.</p>
+
+<p>Launchbar displays the title / icon from the shortcut which does not necessarily mirrors those of the target script note.</p>
diff --git a/src/public/app/doc_notes/launchbar_spacer.html b/src/public/app/doc_notes/launchbar_spacer.html
new file mode 100644
index 0000000000..3390763ca6
--- /dev/null
+++ b/src/public/app/doc_notes/launchbar_spacer.html
@@ -0,0 +1,6 @@
+<p>Spacer allows you to visually group shortcuts. You can configure it in the promoted attributes:</p>
+
+<ul>
+ <li><code>baseSize</code> - defines size in pixels (if there's enough space)</li>
+ <li><code>growthFactor</code> - set to 0 if you want the spacer to be of constant <code>baseSize</code>, with positive value it will grow.</li>
+</ul>
diff --git a/src/public/app/doc_notes/launchbar_widget_shortcut.html b/src/public/app/doc_notes/launchbar_widget_shortcut.html
new file mode 100644
index 0000000000..19b4c47031
--- /dev/null
+++ b/src/public/app/doc_notes/launchbar_widget_shortcut.html
@@ -0,0 +1 @@
+<p>Please define the target widget note in the promoted attributes. The widget will be used to render the launchbar icon.</p>
diff --git a/src/public/app/menus/shortcut_context_menu.js b/src/public/app/menus/shortcut_context_menu.js
index 6750e57379..74b05f0729 100644
--- a/src/public/app/menus/shortcut_context_menu.js
+++ b/src/public/app/menus/shortcut_context_menu.js
@@ -1,8 +1,6 @@
import treeService from '../services/tree.js';
import froca from "../services/froca.js";
-import noteCreateService from "../services/note_create.js";
import contextMenu from "./context_menu.js";
-import appContext from "../services/app_context.js";
export default class ShortcutContextMenu {
/**
@@ -36,6 +34,7 @@ export default class ShortcutContextMenu {
return [
(isVisibleRoot || isAvailableRoot) ? { title: 'Add note shortcut', command: 'addNoteShortcut', uiIcon: "bx bx-plus" } : null,
+ (isVisibleRoot || isAvailableRoot) ? { title: 'Add script shortcut', command: 'addScriptShortcut', uiIcon: "bx bx-plus" } : null,
(isVisibleRoot || isAvailableRoot) ? { title: 'Add widget shortcut', command: 'addWidgetShortcut', uiIcon: "bx bx-plus" } : null,
(isVisibleRoot || isAvailableRoot) ? { title: 'Add spacer', command: 'addSpacerShortcut', uiIcon: "bx bx-plus" } : null,
(isVisibleRoot || isAvailableRoot) ? { title: "----" } : null,
diff --git a/src/public/app/services/clipboard.js b/src/public/app/services/clipboard.js
index 235fe8381a..3ee16b68a8 100644
--- a/src/public/app/services/clipboard.js
+++ b/src/public/app/services/clipboard.js
@@ -54,10 +54,10 @@ async function pasteInto(parentBranchId) {
await branchService.cloneNoteToBranch(clipboardNote.noteId, parentBranchId);
}
- // copy will keep clipboardBranchIds and clipboardMode so it's possible to paste into multiple places
+ // copy will keep clipboardBranchIds and clipboardMode, so it's possible to paste into multiple places
}
else {
- toastService.throwError("Unrecognized clipboard mode=" + mode);
+ toastService.throwError("Unrecognized clipboard mode=" + clipboardMode);
}
}
diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js
index 3da0c0eab6..7a263cd879 100644
--- a/src/public/app/widgets/note_tree.js
+++ b/src/public/app/widgets/note_tree.js
@@ -1521,6 +1521,10 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
this.createShortcutNote(node, 'note');
}
+ addScriptShortcutCommand({node}) {
+ this.createShortcutNote(node, 'script');
+ }
+
addWidgetShortcutCommand({node}) {
this.createShortcutNote(node, 'widget');
}
diff --git a/src/services/branches.js b/src/services/branches.js
index c18ee8b32f..f35db98dfc 100644
--- a/src/services/branches.js
+++ b/src/services/branches.js
@@ -1,5 +1,5 @@
-const treeService = require("./tree.js");
-const sql = require("./sql.js");
+const treeService = require("./tree");
+const sql = require("./sql");
function moveBranchToNote(sourceBranch, targetParentNoteId) {
if (sourceBranch.parentNoteId === targetParentNoteId) {
diff --git a/src/services/special_notes.js b/src/services/special_notes.js
index 93ef52e8ec..d24772184f 100644
--- a/src/services/special_notes.js
+++ b/src/services/special_notes.js
@@ -394,6 +394,17 @@ function createShortcut(parentNoteId, type) {
}).note;
note.addLabel('relation:targetNote', 'promoted');
+ note.addLabel('docName', 'launchbar_note_shortcut');
+ } else if (type === 'script') {
+ note = noteService.createNewNote({
+ title: "Script shortcut",
+ type: 'shortcut',
+ content: '',
+ parentNoteId: parentNoteId
+ }).note;
+
+ note.addLabel('relation:script', 'promoted');
+ note.addLabel('docName', 'launchbar_script_shortcut');
} else if (type === 'widget') {
note = noteService.createNewNote({
title: "Widget shortcut",
@@ -403,6 +414,7 @@ function createShortcut(parentNoteId, type) {
}).note;
note.addLabel('relation:widget', 'promoted');
+ note.addLabel('docName', 'launchbar_widget_shortcut');
} else if (type === 'spacer') {
note = noteService.createNewNote({
title: "Spacer",
@@ -417,6 +429,7 @@ function createShortcut(parentNoteId, type) {
note.addLabel('baseSize', '40');
note.addLabel('label:growthFactor', 'promoted,number');
note.addLabel('growthFactor', '0');
+ note.addLabel('docName', 'launchbar_spacer');
} else {
throw new Error(`Unrecognized shortcut type ${type}`);
}
diff --git a/src/services/tree.js b/src/services/tree.js
index 218777183e..b231c60380 100644
--- a/src/services/tree.js
+++ b/src/services/tree.js
@@ -58,6 +58,16 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) {
};
}
+ const parentNoteIsShortcut = becca.getNote(parentNoteId).type === 'shortcut';
+ const childNoteIsShortcut = becca.getNote(childNoteId).type === 'shortcut';
+
+ if (parentNoteIsShortcut !== childNoteIsShortcut) {
+ return {
+ success: false,
+ message: 'Moving/cloning is not possible between shortcuts / normal notes.'
+ };
+ }
+
return { success: true };
}