From a577485e4297624f0c283ea642b6710eef146552 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 23 Sep 2020 22:45:51 +0200 Subject: [PATCH] allow duplicating multiple notes at once, closes #1259 --- src/public/app/services/tree_context_menu.js | 4 ++-- src/public/app/widgets/note_tree.js | 15 +++++++++++++-- src/services/notes.js | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.js index 0c37e5158..b37ef28ba 100644 --- a/src/public/app/services/tree_context_menu.js +++ b/src/public/app/services/tree_context_menu.js @@ -95,8 +95,8 @@ class TreeContextMenu { enabled: !clipboard.isClipboardEmpty() && notSearch && noSelectedNotes }, { title: 'Paste after', command: "pasteNotesAfterFromClipboard", uiIcon: "paste", enabled: !clipboard.isClipboardEmpty() && isNotRoot && !isHoisted && parentNotSearch && noSelectedNotes }, - { title: "Duplicate note here", command: "duplicateNote", uiIcon: "empty", - enabled: noSelectedNotes && parentNotSearch && isNotRoot && !isHoisted && (!note.isProtected || protectedSessionHolder.isProtectedSessionAvailable()) }, + { title: "Duplicate note(s) here", command: "duplicateNote", uiIcon: "empty", + enabled: parentNotSearch && isNotRoot && !isHoisted }, { title: "----" }, { title: "Export", command: "exportNote", uiIcon: "empty", enabled: notSearch && noSelectedNotes }, diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 013deb525..7a7f445cc 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -15,6 +15,7 @@ import clipboard from "../services/clipboard.js"; import protectedSessionService from "../services/protected_session.js"; import syncService from "../services/sync.js"; import options from "../services/options.js"; +import protectedSessionHolder from "../services/protected_session_holder.js"; const TPL = `
@@ -1362,8 +1363,18 @@ export default class NoteTreeWidget extends TabAwareWidget { } duplicateNoteCommand({node}) { - const branch = treeCache.getBranch(node.data.branchId); + const nodesToDuplicate = this.getSelectedOrActiveNodes(node); - noteCreateService.duplicateNote(node.data.noteId, branch.parentNoteId); + for (const nodeToDuplicate of nodesToDuplicate) { + const note = treeCache.getNoteFromCache(nodeToDuplicate.data.noteId); + + if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) { + continue; + } + + const branch = treeCache.getBranch(nodeToDuplicate.data.branchId); + + noteCreateService.duplicateNote(nodeToDuplicate.data.noteId, branch.parentNoteId); + } } } diff --git a/src/services/notes.js b/src/services/notes.js index 7da60e784..fc6be0eb7 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -727,7 +727,7 @@ function duplicateNote(noteId, parentNoteId) { } // might be null if orig note is not in the target parentNoteId - const origBranch = (origNote.getBranches()).find(branch => branch.parentNoteId === parentNoteId); + const origBranch = origNote.getBranches().find(branch => branch.parentNoteId === parentNoteId); const newNote = new Note(origNote); newNote.noteId = undefined; // force creation of new note