| 
									
										
										
										
											2020-03-17 12:28:02 +01:00
										 |  |  | import appContext from "./app_context.js"; | 
					
						
							|  |  |  | import noteCreateService from "./note_create.js"; | 
					
						
							|  |  |  | import treeService from "./tree.js"; | 
					
						
							|  |  |  | import hoistedNoteService from "./hoisted_note.js"; | 
					
						
							|  |  |  | import Component from "../widgets/component.js"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * This class contains command executors which logically belong to the NoteTree widget, but for better user experience | 
					
						
							|  |  |  |  * the keyboard shortcuts must be active on the whole screen and not just on the widget itself, so the executors | 
					
						
							|  |  |  |  * must be at the root of the component tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export default class MainTreeExecutors extends Component { | 
					
						
							|  |  |  |     get tree() { | 
					
						
							|  |  |  |         return appContext.mainTreeWidget; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async cloneNotesToCommand() { | 
					
						
							|  |  |  |         const selectedOrActiveNoteIds = this.tree.getSelectedOrActiveNodes().map(node => node.data.noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.triggerCommand('cloneNoteIdsTo', {noteIds: selectedOrActiveNoteIds}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async moveNotesToCommand() { | 
					
						
							|  |  |  |         const selectedOrActiveBranchIds = this.tree.getSelectedOrActiveNodes().map(node => node.data.branchId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.triggerCommand('moveBranchIdsTo', {branchIds: selectedOrActiveBranchIds}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async createNoteIntoCommand() { | 
					
						
							| 
									
										
										
										
											2020-03-17 12:48:09 +01:00
										 |  |  |         const activeNote = appContext.tabManager.getActiveTabNote(); | 
					
						
							| 
									
										
										
										
											2020-03-17 12:28:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 12:48:09 +01:00
										 |  |  |         if (!activeNote) { | 
					
						
							|  |  |  |             return; | 
					
						
							| 
									
										
										
										
											2020-03-17 12:28:02 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-03-17 12:48:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 21:44:34 +02:00
										 |  |  |         await noteCreateService.createNote(activeNote.noteId, { | 
					
						
							| 
									
										
										
										
											2020-03-17 12:48:09 +01:00
										 |  |  |             isProtected: activeNote.isProtected, | 
					
						
							|  |  |  |             saveSelection: false | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-03-17 12:28:02 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async createNoteAfterCommand() { | 
					
						
							|  |  |  |         const node = this.tree.getActiveNode(); | 
					
						
							|  |  |  |         const parentNoteId = node.data.parentNoteId; | 
					
						
							|  |  |  |         const isProtected = await treeService.getParentProtectedStatus(node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (node.data.noteId === 'root' || node.data.noteId === hoistedNoteService.getHoistedNoteId()) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-05 21:42:18 +02:00
										 |  |  |         await noteCreateService.createNote(parentNoteId, { | 
					
						
							| 
									
										
										
										
											2020-03-17 12:28:02 +01:00
										 |  |  |             target: 'after', | 
					
						
							|  |  |  |             targetBranchId: node.data.branchId, | 
					
						
							|  |  |  |             isProtected: isProtected, | 
					
						
							| 
									
										
										
										
											2020-05-05 21:42:18 +02:00
										 |  |  |             saveSelection: false | 
					
						
							| 
									
										
										
										
											2020-03-17 12:28:02 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-04 21:44:34 +02:00
										 |  |  | } |