mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	note type context submenu now works end to end
This commit is contained in:
		| @@ -74,7 +74,8 @@ class Note extends Entity { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (this.isStringNote()) { |             if (this.isStringNote()) { | ||||||
|                 this.noteContent.content = this.noteContent.content.toString("UTF-8"); |                 this.noteContent.content = this.noteContent.content === null | ||||||
|  |                     ? "" : this.noteContent.content.toString("UTF-8"); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -122,7 +122,7 @@ if (utils.isElectron()) { | |||||||
|         setTimeout(async () => { |         setTimeout(async () => { | ||||||
|             const parentNode = treeService.getCurrentNode(); |             const parentNode = treeService.getCurrentNode(); | ||||||
|  |  | ||||||
|             const {note} = await treeService.createNote(parentNode, parentNode.data.noteId, 'into', parentNode.data.isProtected); |             const {note} = await treeService.createNote(parentNode, parentNode.data.noteId, 'into', "text", parentNode.data.isProtected); | ||||||
|  |  | ||||||
|             await treeService.activateNote(note.noteId); |             await treeService.activateNote(note.noteId); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -93,10 +93,10 @@ $("#note-menu-button").click(async e => { | |||||||
|             const parentNoteId = node.data.parentNoteId; |             const parentNoteId = node.data.parentNoteId; | ||||||
|             const isProtected = treeUtils.getParentProtectedStatus(node); |             const isProtected = treeUtils.getParentProtectedStatus(node); | ||||||
|  |  | ||||||
|             treeService.createNote(node, parentNoteId, 'after', isProtected); |             treeService.createNote(node, parentNoteId, 'after', null, isProtected); | ||||||
|         } |         } | ||||||
|         else if (cmd === "insertChildNote") { |         else if (cmd === "insertChildNote") { | ||||||
|             treeService.createNote(node, node.data.noteId, 'into'); |             treeService.createNote(node, node.data.noteId, 'into', null); | ||||||
|         } |         } | ||||||
|         else if (cmd === "delete") { |         else if (cmd === "delete") { | ||||||
|             treeChangesService.deleteNodes([node]); |             treeChangesService.deleteNodes([node]); | ||||||
|   | |||||||
| @@ -551,10 +551,13 @@ async function createNewTopLevelNote() { | |||||||
|  |  | ||||||
|     const rootNode = getNodesByNoteId(hoistedNoteId)[0]; |     const rootNode = getNodesByNoteId(hoistedNoteId)[0]; | ||||||
|  |  | ||||||
|     await createNote(rootNode, hoistedNoteId, "into", false); |     await createNote(rootNode, hoistedNoteId, "into", null, false); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function createNote(node, parentNoteId, target, isProtected, saveSelection = false) { | /** | ||||||
|  |  * @param type - type can be falsy - in that case it will be chosen automatically based on parent note | ||||||
|  |  */ | ||||||
|  | async function createNote(node, parentNoteId, target, type, isProtected, saveSelection = false) { | ||||||
|     utils.assertArguments(node, parentNoteId, target); |     utils.assertArguments(node, parentNoteId, target); | ||||||
|  |  | ||||||
|     // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted |     // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted | ||||||
| @@ -586,7 +589,8 @@ async function createNote(node, parentNoteId, target, isProtected, saveSelection | |||||||
|         content: content, |         content: content, | ||||||
|         target: target, |         target: target, | ||||||
|         target_branchId: node.data.branchId, |         target_branchId: node.data.branchId, | ||||||
|         isProtected: isProtected |         isProtected: isProtected, | ||||||
|  |         type: type | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     if (saveSelection) { |     if (saveSelection) { | ||||||
| @@ -695,13 +699,13 @@ utils.bindShortcut('ctrl+o', async () => { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     createNote(node, parentNoteId, 'after', isProtected, true); |     createNote(node, parentNoteId, 'after', null, isProtected, true); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| function createNoteInto() { | function createNoteInto() { | ||||||
|     const node = getCurrentNode(); |     const node = getCurrentNode(); | ||||||
|  |  | ||||||
|     createNote(node, node.data.noteId, 'into', node.data.isProtected, true); |     createNote(node, node.data.noteId, 'into', null, node.data.isProtected, true); | ||||||
| } | } | ||||||
|  |  | ||||||
| window.glob.createNoteInto = createNoteInto; | window.glob.createNoteInto = createNoteInto; | ||||||
|   | |||||||
| @@ -77,38 +77,42 @@ function cut(nodes) { | |||||||
|     infoService.showMessage("Note(s) have been cut into clipboard."); |     infoService.showMessage("Note(s) have been cut into clipboard."); | ||||||
| } | } | ||||||
|  |  | ||||||
| const noteTypeItems = [ | function getNoteTypeItems(baseCmd) { | ||||||
|     {title: "Plain text", cmd: "insertNoteAfter", uiIcon: "file"}, |     return [ | ||||||
|     {title: "Terminal", cmd: "insertNoteAfter", uiIcon: "terminal"}, |         { title: "Text", cmd: baseCmd + "_text", uiIcon: "file" }, | ||||||
|     {title: "Saved search", cmd: "insertNoteAfter", uiIcon: "search-folder"}, |         { title: "Code", cmd: baseCmd + "_code", uiIcon: "terminal" }, | ||||||
|     {title: "Relation Map", cmd: "insertNoteAfter", uiIcon: "map"}, |         { title: "Saved search", cmd: baseCmd + "_search", uiIcon: "search-folder" }, | ||||||
|     {title: "Render HTML note", cmd: "insertNoteAfter", uiIcon: "play"} |         { title: "Relation Map", cmd: baseCmd + "_relation-map", uiIcon: "map" }, | ||||||
| ]; |         { title: "Render HTML note", cmd: baseCmd + "_render", uiIcon: "play" } | ||||||
|  |     ]; | ||||||
|  | } | ||||||
|  |  | ||||||
| const contextMenuItems = [ | function getTopLevelItems(note) { | ||||||
|     {title: "Insert note after <kbd>Ctrl+O</kbd>", cmd: "insertNoteAfter", uiIcon: "plus", items: noteTypeItems}, |     return [ | ||||||
|     {title: "Insert child note <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "plus", items: noteTypeItems}, |         { title: "Insert note after <kbd>Ctrl+O</kbd>", cmd: "insertNoteAfter", uiIcon: "plus", items: note.type !== 'search' ? getNoteTypeItems("insertNoteAfter") : null }, | ||||||
|     {title: "Delete <kbd>Delete</kbd>", cmd: "delete", uiIcon: "trash"}, |         { title: "Insert child note <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "plus", items: note.type !== 'search' ? getNoteTypeItems("insertChildNote") : null }, | ||||||
|     {title: "----"}, |         { title: "Delete <kbd>Delete</kbd>", cmd: "delete", uiIcon: "trash" }, | ||||||
|     {title: "Hoist note <kbd>Ctrl-H</kbd>", cmd: "hoist", uiIcon: "arrow-up"}, |         { title: "----" }, | ||||||
|     {title: "Unhoist note <kbd>Ctrl-H</kbd>", cmd: "unhoist", uiIcon: "arrow-up"}, |         { title: "Hoist note <kbd>Ctrl-H</kbd>", cmd: "hoist", uiIcon: "arrow-up" }, | ||||||
|     {title: "Edit branch prefix <kbd>F2</kbd>", cmd: "editBranchPrefix", uiIcon: "pencil"}, |         { title: "Unhoist note <kbd>Ctrl-H</kbd>", cmd: "unhoist", uiIcon: "arrow-up" }, | ||||||
|     {title: "----"}, |         { title: "Edit branch prefix <kbd>F2</kbd>", cmd: "editBranchPrefix", uiIcon: "pencil" }, | ||||||
|     {title: "Protect subtree", cmd: "protectSubtree", uiIcon: "shield-check"}, |         { title: "----" }, | ||||||
|     {title: "Unprotect subtree", cmd: "unprotectSubtree", uiIcon: "shield-close"}, |         { title: "Protect subtree", cmd: "protectSubtree", uiIcon: "shield-check" }, | ||||||
|     {title: "----"}, |         { title: "Unprotect subtree", cmd: "unprotectSubtree", uiIcon: "shield-close" }, | ||||||
|     {title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "files"}, |         { title: "----" }, | ||||||
|     {title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "scissors"}, |         { title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "files" }, | ||||||
|     {title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "clipboard"}, |         { title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "scissors" }, | ||||||
|     {title: "Paste after", cmd: "pasteAfter", uiIcon: "clipboard"}, |         { title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "clipboard" }, | ||||||
|     {title: "----"}, |         { title: "Paste after", cmd: "pasteAfter", uiIcon: "clipboard" }, | ||||||
|     {title: "Export", cmd: "export", uiIcon: "arrow-up-right"}, |         { title: "----" }, | ||||||
|     {title: "Import into note", cmd: "importIntoNote", uiIcon: "arrow-down-left"}, |         { title: "Export", cmd: "export", uiIcon: "arrow-up-right" }, | ||||||
|     {title: "----"}, |         { title: "Import into note", cmd: "importIntoNote", uiIcon: "arrow-down-left" }, | ||||||
|     {title: "Collapse subtree <kbd>Alt+-</kbd>", cmd: "collapseSubtree", uiIcon: "align-justify"}, |         { title: "----" }, | ||||||
|     {title: "Force note sync", cmd: "forceNoteSync", uiIcon: "refresh"}, |         { title: "Collapse subtree <kbd>Alt+-</kbd>", cmd: "collapseSubtree", uiIcon: "align-justify" }, | ||||||
|     {title: "Sort alphabetically <kbd>Alt+S</kbd>", cmd: "sortAlphabetically", uiIcon: "arrows-v"} |         { title: "Force note sync", cmd: "forceNoteSync", uiIcon: "refresh" }, | ||||||
| ]; |         { title: "Sort alphabetically <kbd>Alt+S</kbd>", cmd: "sortAlphabetically", uiIcon: "arrows-v" } | ||||||
|  |     ]; | ||||||
|  | } | ||||||
|  |  | ||||||
| async function getContextMenuItems(event) { | async function getContextMenuItems(event) { | ||||||
|     const node = $.ui.fancytree.getNode(event); |     const node = $.ui.fancytree.getNode(event); | ||||||
| @@ -118,7 +122,7 @@ async function getContextMenuItems(event) { | |||||||
|     const isNotRoot = note.noteId !== 'root'; |     const isNotRoot = note.noteId !== 'root'; | ||||||
|     const isHoisted = note.noteId === await hoistedNoteService.getHoistedNoteId(); |     const isHoisted = note.noteId === await hoistedNoteService.getHoistedNoteId(); | ||||||
|  |  | ||||||
|     const itemsContainer = new ContextMenuItemsContainer(contextMenuItems); |     const itemsContainer = new ContextMenuItemsContainer(getTopLevelItems(note)); | ||||||
|  |  | ||||||
|     // Modify menu entries depending on node status |     // Modify menu entries depending on node status | ||||||
|     itemsContainer.enableItem("insertNoteAfter", isNotRoot && !isHoisted && parentNote.type !== 'search'); |     itemsContainer.enableItem("insertNoteAfter", isNotRoot && !isHoisted && parentNote.type !== 'search'); | ||||||
| @@ -151,14 +155,17 @@ function selectContextMenuItem(event, cmd) { | |||||||
|     // context menu is always triggered on current node |     // context menu is always triggered on current node | ||||||
|     const node = treeService.getCurrentNode(); |     const node = treeService.getCurrentNode(); | ||||||
|  |  | ||||||
|     if (cmd === "insertNoteAfter") { |     if (cmd.startsWith("insertNoteAfter")) { | ||||||
|         const parentNoteId = node.data.parentNoteId; |         const parentNoteId = node.data.parentNoteId; | ||||||
|         const isProtected = treeUtils.getParentProtectedStatus(node); |         const isProtected = treeUtils.getParentProtectedStatus(node); | ||||||
|  |         const type = cmd.split("_")[1]; | ||||||
|  |  | ||||||
|         treeService.createNote(node, parentNoteId, 'after', isProtected); |         treeService.createNote(node, parentNoteId, 'after', type, isProtected); | ||||||
|     } |     } | ||||||
|     else if (cmd === "insertChildNote") { |     else if (cmd.startsWith("insertChildNote")) { | ||||||
|         treeService.createNote(node, node.data.noteId, 'into'); |         const type = cmd.split("_")[1]; | ||||||
|  |  | ||||||
|  |         treeService.createNote(node, node.data.noteId, 'into', type); | ||||||
|     } |     } | ||||||
|     else if (cmd === "editBranchPrefix") { |     else if (cmd === "editBranchPrefix") { | ||||||
|         branchPrefixDialog.showDialog(node); |         branchPrefixDialog.showDialog(node); | ||||||
|   | |||||||
| @@ -81,10 +81,6 @@ async function createNewNote(parentNoteId, noteData) { | |||||||
|     noteData.type = noteData.type || parentNote.type; |     noteData.type = noteData.type || parentNote.type; | ||||||
|     noteData.mime = noteData.mime || parentNote.mime; |     noteData.mime = noteData.mime || parentNote.mime; | ||||||
|  |  | ||||||
|     if (noteData.type === 'text' || noteData.type === 'code') { |  | ||||||
|         noteData.content = noteData.content || ""; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     const note = await new Note({ |     const note = await new Note({ | ||||||
|         noteId: noteData.noteId, // optionally can force specific noteId |         noteId: noteData.noteId, // optionally can force specific noteId | ||||||
|         title: noteData.title, |         title: noteData.title, | ||||||
| @@ -93,6 +89,10 @@ async function createNewNote(parentNoteId, noteData) { | |||||||
|         mime: noteData.mime || 'text/html' |         mime: noteData.mime || 'text/html' | ||||||
|     }).save(); |     }).save(); | ||||||
|  |  | ||||||
|  |     if (note.isStringNote()) { | ||||||
|  |         noteData.content = noteData.content || ""; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     note.noteContent = await new NoteContent({ |     note.noteContent = await new NoteContent({ | ||||||
|         noteId: note.noteId, |         noteId: note.noteId, | ||||||
|         content: noteData.content |         content: noteData.content | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user