mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 10:55:55 +01:00
cloning in context menu (copy & paste) and a lot of related refactoring and fixes
This commit is contained in:
@@ -3,24 +3,51 @@
|
||||
const contextMenu = (function() {
|
||||
const treeEl = $("#tree");
|
||||
|
||||
let clipboardId = null;
|
||||
let clipboardMode = null;
|
||||
|
||||
function pasteAfter(node) {
|
||||
const subjectNode = treeUtils.getNodeByNoteTreeId(noteTree.getClipboardNoteTreeId());
|
||||
if (clipboardMode === 'cut') {
|
||||
const subjectNode = treeUtils.getNodeByNoteTreeId(clipboardId);
|
||||
|
||||
treeChanges.moveAfterNode(subjectNode, node);
|
||||
treeChanges.moveAfterNode(subjectNode, node);
|
||||
}
|
||||
else if (clipboardMode === 'copy') {
|
||||
treeChanges.cloneNoteAfter(clipboardId, node.data.note_tree_id);
|
||||
}
|
||||
else {
|
||||
throw new Error("Unrecognized clipboard mode=" + mode);
|
||||
}
|
||||
|
||||
noteTree.setClipboardNoteTreeId(null);
|
||||
clipboardId = null;
|
||||
clipboardMode = null;
|
||||
}
|
||||
|
||||
function pasteInto(node) {
|
||||
const subjectNode = treeUtils.getNodeByNoteTreeId(noteTree.getClipboardNoteTreeId());
|
||||
if (clipboardMode === 'cut') {
|
||||
const subjectNode = treeUtils.getNodeByNoteTreeId(clipboardId);
|
||||
|
||||
treeChanges.moveToNode(subjectNode, node);
|
||||
treeChanges.moveToNode(subjectNode, node);
|
||||
}
|
||||
else if (clipboardMode === 'copy') {
|
||||
treeChanges.cloneNoteTo(clipboardId, node.data.note_id);
|
||||
}
|
||||
else {
|
||||
throw new Error("Unrecognized clipboard mode=" + mode);
|
||||
}
|
||||
|
||||
noteTree.setClipboardNoteTreeId(null);
|
||||
clipboardId = null;
|
||||
clipboardMode = null;
|
||||
}
|
||||
|
||||
function copy(node) {
|
||||
clipboardId = node.data.note_id;
|
||||
clipboardMode = 'copy';
|
||||
}
|
||||
|
||||
function cut(node) {
|
||||
noteTree.setClipboardNoteTreeId(node.note_tree_id);
|
||||
clipboardId = node.data.note_tree_id;
|
||||
clipboardMode = 'cut';
|
||||
}
|
||||
|
||||
const contextMenuSettings = {
|
||||
@@ -42,8 +69,8 @@ const contextMenu = (function() {
|
||||
beforeOpen: (event, ui) => {
|
||||
const node = $.ui.fancytree.getNode(ui.target);
|
||||
// Modify menu entries depending on node status
|
||||
treeEl.contextmenu("enableEntry", "pasteAfter", noteTree.getClipboardNoteTreeId() !== null);
|
||||
treeEl.contextmenu("enableEntry", "pasteInto", noteTree.getClipboardNoteTreeId() !== null);
|
||||
treeEl.contextmenu("enableEntry", "pasteAfter", clipboardId !== null);
|
||||
treeEl.contextmenu("enableEntry", "pasteInto", clipboardId !== null);
|
||||
|
||||
// Activate node on right-click
|
||||
node.setActive();
|
||||
@@ -56,13 +83,13 @@ const contextMenu = (function() {
|
||||
const node = $.ui.fancytree.getNode(ui.target);
|
||||
|
||||
if (ui.cmd === "insertNoteHere") {
|
||||
const parentNoteTreeId = treeUtils.getParentNoteTreeId(node);
|
||||
const parentNoteId = node.data.note_pid;
|
||||
const isProtected = treeUtils.getParentProtectedStatus(node);
|
||||
|
||||
noteEditor.createNote(node, parentNoteTreeId, 'after', isProtected);
|
||||
noteTree.createNote(node, parentNoteId, 'after', isProtected);
|
||||
}
|
||||
else if (ui.cmd === "insertChildNote") {
|
||||
noteEditor.createNote(node, node.data.note_id, 'into');
|
||||
noteTree.createNote(node, node.data.note_id, 'into');
|
||||
}
|
||||
else if (ui.cmd === "protectSubTree") {
|
||||
protected_session.protectSubTree(node.data.note_id, true);
|
||||
@@ -70,6 +97,9 @@ const contextMenu = (function() {
|
||||
else if (ui.cmd === "unprotectSubTree") {
|
||||
protected_session.protectSubTree(node.data.note_id, false);
|
||||
}
|
||||
else if (ui.cmd === "copy") {
|
||||
copy(node);
|
||||
}
|
||||
else if (ui.cmd === "cut") {
|
||||
cut(node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user