Notes/src/public/app/components/root_command_executor.js

128 lines
3.9 KiB
JavaScript
Raw Normal View History

2022-12-01 13:07:23 +01:00
import Component from "./component.js";
2020-02-17 22:14:39 +01:00
import appContext from "./app_context.js";
import dateNoteService from "../services/date_notes.js";
2020-12-05 23:00:28 +01:00
import treeService from "../services/tree.js";
2022-12-01 13:07:23 +01:00
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";
2020-01-20 22:35:52 +01:00
export default class RootCommandExecutor extends Component {
editReadOnlyNoteCommand() {
const noteContext = appContext.tabManager.getActiveContext();
noteContext.viewScope.readOnlyTemporarilyDisabled = true;
appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext });
}
async showSQLConsoleCommand() {
const sqlConsoleNote = await dateNoteService.createSqlConsole();
const noteContext = await appContext.tabManager.openContextWithNote(sqlConsoleNote.noteId, { activate: true });
2021-05-22 12:26:45 +02:00
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, {
activate: true,
hoistedNoteId
});
2021-05-22 12:26:45 +02:00
appContext.triggerCommand('focusOnSearchDefinition', {ntxId: noteContext.ntxId});
}
2020-12-05 23:00:28 +01:00
async searchInSubtreeCommand({notePath}) {
const noteId = treeService.getNoteIdFromNotePath(notePath);
this.searchNotesCommand({ancestorNoteId: noteId});
2020-12-05 23:00:28 +01:00
}
openNoteExternallyCommand() {
2021-05-22 12:35:41 +02:00
const noteId = appContext.tabManager.getActiveContextNoteId();
const mime = appContext.tabManager.getActiveContextNoteMime()
2022-12-01 13:07:23 +01:00
if (noteId) {
openService.openNoteExternally(noteId, mime);
}
}
2021-05-18 22:14:35 +02:00
enterProtectedSessionCommand() {
protectedSessionService.enterProtectedSession();
}
leaveProtectedSessionCommand() {
protectedSessionService.leaveProtectedSession();
}
hideLeftPaneCommand() {
options.save(`leftPaneVisible`, "false");
}
showLeftPaneCommand() {
options.save(`leftPaneVisible`, "true");
}
toggleLeftPaneCommand() {
options.toggle('leftPaneVisible');
}
2022-08-04 23:00:32 +02:00
2022-12-15 16:38:05 +01:00
async showBackendLogCommand() {
await appContext.tabManager.openContextWithNote('_backendLog', { activate: true });
2022-12-15 16:38:05 +01:00
}
2022-12-01 10:03:04 +01:00
async showLaunchBarSubtreeCommand() {
2022-12-21 16:11:00 +01:00
await this.showAndHoistSubtree('_lbRoot');
2022-11-25 15:29:57 +01:00
}
2022-08-05 16:44:26 +02:00
2022-11-25 15:29:57 +01:00
async showShareSubtreeCommand() {
2022-12-21 16:11:00 +01:00
await this.showAndHoistSubtree('_share');
2022-11-25 15:29:57 +01:00
}
2022-08-05 16:44:26 +02:00
2022-11-25 15:29:57 +01:00
async showHiddenSubtreeCommand() {
2022-12-21 16:11:00 +01:00
await this.showAndHoistSubtree('_hidden');
2022-08-04 23:00:32 +02:00
}
2022-12-05 23:57:29 +01:00
2023-01-23 23:37:58 +01:00
async showOptionsCommand({section}) {
await appContext.tabManager.openContextWithNote(section || '_options', {
activate: true,
hoistedNoteId: '_options'
});
2022-12-15 16:38:05 +01:00
}
async showSQLConsoleHistoryCommand() {
2022-12-21 16:11:00 +01:00
await this.showAndHoistSubtree('_sqlConsole');
2022-12-15 16:38:05 +01:00
}
async showSearchHistoryCommand() {
2022-12-21 16:11:00 +01:00
await this.showAndHoistSubtree('_search');
2022-12-15 16:38:05 +01:00
}
2022-12-30 17:41:45 +01:00
async showUserGuideCommand() {
await this.showAndHoistSubtree('_userGuide');
}
2022-12-15 16:38:05 +01:00
async showAndHoistSubtree(subtreeNoteId) {
await appContext.tabManager.openContextWithNote(subtreeNoteId, {
activate: true,
hoistedNoteId: subtreeNoteId
});
}
async showNoteSourceEvent() {
const notePath = appContext.tabManager.getActiveContextNotePath();
if (notePath) {
await appContext.tabManager.openContextWithNote(notePath, { activate: true, viewMode: 'source' });
}
2022-12-05 23:57:29 +01:00
}
2020-07-04 10:18:01 +02:00
}