mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +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()) { | ||||
|                 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 () => { | ||||
|             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); | ||||
|  | ||||
|   | ||||
| @@ -93,10 +93,10 @@ $("#note-menu-button").click(async e => { | ||||
|             const parentNoteId = node.data.parentNoteId; | ||||
|             const isProtected = treeUtils.getParentProtectedStatus(node); | ||||
|  | ||||
|             treeService.createNote(node, parentNoteId, 'after', isProtected); | ||||
|             treeService.createNote(node, parentNoteId, 'after', null, isProtected); | ||||
|         } | ||||
|         else if (cmd === "insertChildNote") { | ||||
|             treeService.createNote(node, node.data.noteId, 'into'); | ||||
|             treeService.createNote(node, node.data.noteId, 'into', null); | ||||
|         } | ||||
|         else if (cmd === "delete") { | ||||
|             treeChangesService.deleteNodes([node]); | ||||
|   | ||||
| @@ -551,10 +551,13 @@ async function createNewTopLevelNote() { | ||||
|  | ||||
|     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); | ||||
|  | ||||
|     // 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, | ||||
|         target: target, | ||||
|         target_branchId: node.data.branchId, | ||||
|         isProtected: isProtected | ||||
|         isProtected: isProtected, | ||||
|         type: type | ||||
|     }); | ||||
|  | ||||
|     if (saveSelection) { | ||||
| @@ -695,13 +699,13 @@ utils.bindShortcut('ctrl+o', async () => { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     createNote(node, parentNoteId, 'after', isProtected, true); | ||||
|     createNote(node, parentNoteId, 'after', null, isProtected, true); | ||||
| }); | ||||
|  | ||||
| function createNoteInto() { | ||||
|     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; | ||||
|   | ||||
| @@ -77,17 +77,20 @@ function cut(nodes) { | ||||
|     infoService.showMessage("Note(s) have been cut into clipboard."); | ||||
| } | ||||
|  | ||||
| const noteTypeItems = [ | ||||
|     {title: "Plain text", cmd: "insertNoteAfter", uiIcon: "file"}, | ||||
|     {title: "Terminal", cmd: "insertNoteAfter", uiIcon: "terminal"}, | ||||
|     {title: "Saved search", cmd: "insertNoteAfter", uiIcon: "search-folder"}, | ||||
|     {title: "Relation Map", cmd: "insertNoteAfter", uiIcon: "map"}, | ||||
|     {title: "Render HTML note", cmd: "insertNoteAfter", uiIcon: "play"} | ||||
| function getNoteTypeItems(baseCmd) { | ||||
|     return [ | ||||
|         { title: "Text", cmd: baseCmd + "_text", uiIcon: "file" }, | ||||
|         { title: "Code", cmd: baseCmd + "_code", uiIcon: "terminal" }, | ||||
|         { title: "Saved search", cmd: baseCmd + "_search", uiIcon: "search-folder" }, | ||||
|         { title: "Relation Map", cmd: baseCmd + "_relation-map", uiIcon: "map" }, | ||||
|         { title: "Render HTML note", cmd: baseCmd + "_render", uiIcon: "play" } | ||||
|     ]; | ||||
| } | ||||
|  | ||||
| const contextMenuItems = [ | ||||
|     {title: "Insert note after <kbd>Ctrl+O</kbd>", cmd: "insertNoteAfter", uiIcon: "plus", items: noteTypeItems}, | ||||
|     {title: "Insert child note <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "plus", items: noteTypeItems}, | ||||
| function getTopLevelItems(note) { | ||||
|     return [ | ||||
|         { title: "Insert note after <kbd>Ctrl+O</kbd>", cmd: "insertNoteAfter", uiIcon: "plus", items: note.type !== 'search' ? getNoteTypeItems("insertNoteAfter") : null }, | ||||
|         { title: "Insert child note <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "plus", items: note.type !== 'search' ? getNoteTypeItems("insertChildNote") : null }, | ||||
|         { title: "Delete <kbd>Delete</kbd>", cmd: "delete", uiIcon: "trash" }, | ||||
|         { title: "----" }, | ||||
|         { title: "Hoist note <kbd>Ctrl-H</kbd>", cmd: "hoist", uiIcon: "arrow-up" }, | ||||
| @@ -109,6 +112,7 @@ const contextMenuItems = [ | ||||
|         { title: "Force note sync", cmd: "forceNoteSync", uiIcon: "refresh" }, | ||||
|         { title: "Sort alphabetically <kbd>Alt+S</kbd>", cmd: "sortAlphabetically", uiIcon: "arrows-v" } | ||||
|     ]; | ||||
| } | ||||
|  | ||||
| async function getContextMenuItems(event) { | ||||
|     const node = $.ui.fancytree.getNode(event); | ||||
| @@ -118,7 +122,7 @@ async function getContextMenuItems(event) { | ||||
|     const isNotRoot = note.noteId !== 'root'; | ||||
|     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 | ||||
|     itemsContainer.enableItem("insertNoteAfter", isNotRoot && !isHoisted && parentNote.type !== 'search'); | ||||
| @@ -151,14 +155,17 @@ function selectContextMenuItem(event, cmd) { | ||||
|     // context menu is always triggered on current node | ||||
|     const node = treeService.getCurrentNode(); | ||||
|  | ||||
|     if (cmd === "insertNoteAfter") { | ||||
|     if (cmd.startsWith("insertNoteAfter")) { | ||||
|         const parentNoteId = node.data.parentNoteId; | ||||
|         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") { | ||||
|         treeService.createNote(node, node.data.noteId, 'into'); | ||||
|     else if (cmd.startsWith("insertChildNote")) { | ||||
|         const type = cmd.split("_")[1]; | ||||
|  | ||||
|         treeService.createNote(node, node.data.noteId, 'into', type); | ||||
|     } | ||||
|     else if (cmd === "editBranchPrefix") { | ||||
|         branchPrefixDialog.showDialog(node); | ||||
|   | ||||
| @@ -81,10 +81,6 @@ async function createNewNote(parentNoteId, noteData) { | ||||
|     noteData.type = noteData.type || parentNote.type; | ||||
|     noteData.mime = noteData.mime || parentNote.mime; | ||||
|  | ||||
|     if (noteData.type === 'text' || noteData.type === 'code') { | ||||
|         noteData.content = noteData.content || ""; | ||||
|     } | ||||
|  | ||||
|     const note = await new Note({ | ||||
|         noteId: noteData.noteId, // optionally can force specific noteId | ||||
|         title: noteData.title, | ||||
| @@ -93,6 +89,10 @@ async function createNewNote(parentNoteId, noteData) { | ||||
|         mime: noteData.mime || 'text/html' | ||||
|     }).save(); | ||||
|  | ||||
|     if (note.isStringNote()) { | ||||
|         noteData.content = noteData.content || ""; | ||||
|     } | ||||
|  | ||||
|     note.noteContent = await new NoteContent({ | ||||
|         noteId: note.noteId, | ||||
|         content: noteData.content | ||||
|   | ||||
		Reference in New Issue
	
	Block a user