clipboard is now owned by note tree

This commit is contained in:
azivner 2017-11-04 19:49:26 -04:00
parent 19c5404d02
commit dfaa59b0a9
2 changed files with 19 additions and 9 deletions

View File

@ -4,23 +4,23 @@ const contextMenu = (function() {
const treeEl = $("#tree");
function pasteAfter(node) {
const subjectNode = getNodeByKey(glob.clipboardNoteId);
const subjectNode = getNodeByKey(noteTree.getClipboardNoteId());
moveAfterNode(subjectNode, node);
glob.clipboardNoteId = null;
noteTree.setClipboardNoteId(null);
}
function pasteInto(node) {
const subjectNode = getNodeByKey(glob.clipboardNoteId);
const subjectNode = getNodeByKey(noteTree.getClipboardNoteId());
moveToNode(subjectNode, node);
glob.clipboardNoteId = null;
noteTree.setClipboardNoteId(null);
}
function cut(node) {
glob.clipboardNoteId = node.key;
noteTree.setClipboardNoteId(node.key);
}
const contextMenuSettings = {
@ -42,8 +42,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", glob.clipboardNoteId !== null);
treeEl.contextmenu("enableEntry", "pasteInto", glob.clipboardNoteId !== null);
treeEl.contextmenu("enableEntry", "pasteAfter", noteTree.getClipboardNoteId() !== null);
treeEl.contextmenu("enableEntry", "pasteInto", noteTree.getClipboardNoteId() !== null);
// Activate node on right-click
node.setActive();

View File

@ -4,14 +4,22 @@ const noteTree = (function() {
const noteDetailEl = $('#note-detail');
const treeEl = $("#tree");
let treeLoadTime = null;
let clipboardNoteId = null;
glob.allNoteIds = [];
glob.clipboardNoteId = null;
function getTreeLoadTime() {
return treeLoadTime;
}
function getClipboardNoteId() {
return clipboardNoteId;
}
function setClipboardNoteId(cbNoteId) {
clipboardNoteId = cbNoteId;
}
function prepareNoteTree(notes) {
for (const note of notes) {
glob.allNoteIds.push(note.note_id);
@ -284,9 +292,11 @@ const noteTree = (function() {
return {
getTreeLoadTime,
getClipboardNoteId,
setClipboardNoteId,
loadTree,
collapseTree,
scrollToCurrentNote,
toggleSearch
toggleSearch,
};
})();