mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			107 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import Component from "./component.js";
 | |
| import appContext from "./app_context.js";
 | |
| import dateNoteService from "../services/date_notes.js";
 | |
| import treeService from "../services/tree.js";
 | |
| import openService from "../services/open.js";
 | |
| import protectedSessionService from "../services/protected_session.js";
 | |
| import options from "../services/options.js";
 | |
| import froca from "../services/froca.js";
 | |
| 
 | |
| export default class RootCommandExecutor extends Component {
 | |
|     editReadOnlyNoteCommand() {
 | |
|         const noteContext = appContext.tabManager.getActiveContext();
 | |
|         noteContext.readOnlyTemporarilyDisabled = true;
 | |
| 
 | |
|         appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext });
 | |
|     }
 | |
| 
 | |
|     async showSQLConsoleCommand() {
 | |
|         const sqlConsoleNote = await dateNoteService.createSqlConsole();
 | |
| 
 | |
|         const noteContext = await appContext.tabManager.openContextWithNote(sqlConsoleNote.noteId, true);
 | |
| 
 | |
|         appContext.triggerEvent('focusOnDetail', {ntxId: noteContext.ntxId});
 | |
|     }
 | |
| 
 | |
|     async searchNotesCommand({searchString, ancestorNoteId}) {
 | |
|         const searchNote = await dateNoteService.createSearchNote({searchString, ancestorNoteId});
 | |
| 
 | |
|         // force immediate search
 | |
|         await froca.loadSearchNote(searchNote.noteId);
 | |
| 
 | |
|         const activeNoteContext = appContext.tabManager.getActiveContext();
 | |
|         const hoistedNoteId = activeNoteContext?.hoistedNoteId || 'root';
 | |
| 
 | |
|         const noteContext = await appContext.tabManager.openContextWithNote(searchNote.noteId, true, null, hoistedNoteId);
 | |
| 
 | |
|         appContext.triggerCommand('focusOnSearchDefinition', {ntxId: noteContext.ntxId});
 | |
|     }
 | |
| 
 | |
|     async searchInSubtreeCommand({notePath}) {
 | |
|         const noteId = treeService.getNoteIdFromNotePath(notePath);
 | |
| 
 | |
|         this.searchNotesCommand({ancestorNoteId: noteId});
 | |
|     }
 | |
| 
 | |
|     openNoteExternallyCommand() {
 | |
|         const noteId = appContext.tabManager.getActiveContextNoteId();
 | |
|         const mime = appContext.tabManager.getActiveContextNoteMime()
 | |
| 
 | |
|         if (noteId) {
 | |
|             openService.openNoteExternally(noteId, mime);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     enterProtectedSessionCommand() {
 | |
|         protectedSessionService.enterProtectedSession();
 | |
|     }
 | |
| 
 | |
|     leaveProtectedSessionCommand() {
 | |
|         protectedSessionService.leaveProtectedSession();
 | |
|     }
 | |
| 
 | |
|     hideLeftPaneCommand() {
 | |
|         options.save(`leftPaneVisible`, "false");
 | |
|     }
 | |
| 
 | |
|     showLeftPaneCommand() {
 | |
|         options.save(`leftPaneVisible`, "true");
 | |
|     }
 | |
| 
 | |
|     toggleLeftPaneCommand() {
 | |
|         options.toggle('leftPaneVisible');
 | |
|     }
 | |
| 
 | |
|     async showBackendLogCommand() {
 | |
|         await appContext.tabManager.openContextWithNote('_backendLog', true);
 | |
|     }
 | |
| 
 | |
|     async showLaunchBarSubtreeCommand() {
 | |
|         await this.showAndHoistSubtree('_lbRoot');
 | |
|     }
 | |
| 
 | |
|     async showShareSubtreeCommand() {
 | |
|         await this.showAndHoistSubtree('_share');
 | |
|     }
 | |
| 
 | |
|     async showHiddenSubtreeCommand() {
 | |
|         await this.showAndHoistSubtree('_hidden');
 | |
|     }
 | |
| 
 | |
|     async showOptionsCommand() {
 | |
|         await this.showAndHoistSubtree('options');
 | |
|     }
 | |
| 
 | |
|     async showSQLConsoleHistoryCommand() {
 | |
|         await this.showAndHoistSubtree('_sqlConsole');
 | |
|     }
 | |
| 
 | |
|     async showSearchHistoryCommand() {
 | |
|         await this.showAndHoistSubtree('_search');
 | |
|     }
 | |
| 
 | |
|     async showAndHoistSubtree(subtreeNoteId) {
 | |
|         await appContext.tabManager.openContextWithNote(subtreeNoteId, true, null, subtreeNoteId);
 | |
|     }
 | |
| }
 |