2022-12-01 13:07:23 +01:00
|
|
|
import Component from "./component.js";
|
2025-01-09 18:36:24 +02:00
|
|
|
import appContext, { type CommandData, type CommandListenerData } from "./app_context.js";
|
2020-05-08 23:39:46 +02:00
|
|
|
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";
|
2023-09-18 04:38:23 -04:00
|
|
|
import utils from "../services/utils.js";
|
2025-03-09 02:19:26 +00:00
|
|
|
import LlmChatPanel from "../widgets/llm_chat_panel.js";
|
|
|
|
import toastService from "../services/toast.js";
|
2025-03-28 20:01:39 +00:00
|
|
|
import noteCreateService from "../services/note_create.js";
|
2020-01-20 22:35:52 +01:00
|
|
|
|
2021-04-24 22:18:25 +02:00
|
|
|
export default class RootCommandExecutor extends Component {
|
2021-06-24 20:27:04 +02:00
|
|
|
editReadOnlyNoteCommand() {
|
|
|
|
const noteContext = appContext.tabManager.getActiveContext();
|
2025-01-04 11:51:16 +02:00
|
|
|
if (noteContext?.viewScope) {
|
|
|
|
noteContext.viewScope.readOnlyTemporarilyDisabled = true;
|
|
|
|
appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext });
|
|
|
|
}
|
2021-06-24 20:27:04 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 23:39:46 +02:00
|
|
|
async showSQLConsoleCommand() {
|
|
|
|
const sqlConsoleNote = await dateNoteService.createSqlConsole();
|
2025-01-04 11:51:16 +02:00
|
|
|
if (!sqlConsoleNote) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-08 23:39:46 +02:00
|
|
|
|
2023-07-14 18:15:31 +02:00
|
|
|
const noteContext = await appContext.tabManager.openTabWithNoteWithHoisting(sqlConsoleNote.noteId, { activate: true });
|
2020-05-08 23:39:46 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
appContext.triggerEvent("focusOnDetail", { ntxId: noteContext.ntxId });
|
2020-02-16 19:54:11 +01:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
async searchNotesCommand({ searchString, ancestorNoteId }: CommandListenerData<"searchNotes">) {
|
|
|
|
const searchNote = await dateNoteService.createSearchNote({ searchString, ancestorNoteId });
|
2025-01-04 11:51:16 +02:00
|
|
|
if (!searchNote) {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-25 23:02:12 +01:00
|
|
|
|
2022-01-10 20:37:33 +01:00
|
|
|
// force immediate search
|
|
|
|
await froca.loadSearchNote(searchNote.noteId);
|
|
|
|
|
2023-07-14 18:15:31 +02:00
|
|
|
const noteContext = await appContext.tabManager.openTabWithNoteWithHoisting(searchNote.noteId, {
|
|
|
|
activate: true
|
2023-02-14 16:06:49 +01:00
|
|
|
});
|
2020-10-25 23:02:12 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
appContext.triggerCommand("focusOnSearchDefinition", { ntxId: noteContext.ntxId });
|
2020-10-25 23:02:12 +01:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
async searchInSubtreeCommand({ notePath }: CommandListenerData<"searchInSubtree">) {
|
2023-05-29 22:37:19 +02:00
|
|
|
const noteId = treeService.getNoteIdFromUrl(notePath);
|
2020-12-05 23:00:28 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.searchNotesCommand({ ancestorNoteId: noteId });
|
2020-12-05 23:00:28 +01:00
|
|
|
}
|
|
|
|
|
2021-04-24 22:18:25 +02:00
|
|
|
openNoteExternallyCommand() {
|
2021-05-22 12:35:41 +02:00
|
|
|
const noteId = appContext.tabManager.getActiveContextNoteId();
|
2023-09-07 06:33:51 +00:00
|
|
|
const mime = appContext.tabManager.getActiveContextNoteMime();
|
2021-04-24 22:18:25 +02:00
|
|
|
if (noteId) {
|
2025-01-04 11:51:16 +02:00
|
|
|
openService.openNoteExternally(noteId, mime || "");
|
2021-04-24 22:18:25 +02:00
|
|
|
}
|
|
|
|
}
|
2023-05-17 23:57:32 +02:00
|
|
|
|
2023-05-16 11:57:28 +00:00
|
|
|
openNoteCustomCommand() {
|
|
|
|
const noteId = appContext.tabManager.getActiveContextNoteId();
|
2023-09-07 06:33:51 +00:00
|
|
|
const mime = appContext.tabManager.getActiveContextNoteMime();
|
2023-05-16 11:57:28 +00:00
|
|
|
if (noteId) {
|
2025-01-04 11:51:16 +02:00
|
|
|
openService.openNoteCustom(noteId, mime || "");
|
2023-05-16 11:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-18 22:14:35 +02:00
|
|
|
|
|
|
|
enterProtectedSessionCommand() {
|
|
|
|
protectedSessionService.enterProtectedSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
leaveProtectedSessionCommand() {
|
|
|
|
protectedSessionService.leaveProtectedSession();
|
|
|
|
}
|
2021-10-12 19:29:42 +02:00
|
|
|
|
|
|
|
hideLeftPaneCommand() {
|
|
|
|
options.save(`leftPaneVisible`, "false");
|
|
|
|
}
|
|
|
|
|
|
|
|
showLeftPaneCommand() {
|
|
|
|
options.save(`leftPaneVisible`, "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleLeftPaneCommand() {
|
2025-01-09 18:07:02 +02:00
|
|
|
options.toggle("leftPaneVisible");
|
2021-10-12 19:29:42 +02:00
|
|
|
}
|
2022-08-04 23:00:32 +02:00
|
|
|
|
2022-12-15 16:38:05 +01:00
|
|
|
async showBackendLogCommand() {
|
2025-01-09 18:07:02 +02:00
|
|
|
await appContext.tabManager.openTabWithNoteWithHoisting("_backendLog", { activate: true });
|
2022-12-15 16:38:05 +01:00
|
|
|
}
|
2025-01-04 11:51:16 +02:00
|
|
|
|
2025-02-02 17:49:26 +02:00
|
|
|
async showHelpCommand() {
|
2025-02-02 17:54:14 +02:00
|
|
|
await this.showAndHoistSubtree("_help");
|
2025-02-02 17:49:26 +02:00
|
|
|
}
|
|
|
|
|
2022-12-01 10:03:04 +01:00
|
|
|
async showLaunchBarSubtreeCommand() {
|
2025-01-04 22:00:39 +02:00
|
|
|
const rootNote = utils.isMobile() ? "_lbMobileRoot" : "_lbRoot";
|
|
|
|
await this.showAndHoistSubtree(rootNote);
|
2024-12-18 23:19:07 +02:00
|
|
|
this.showLeftPaneCommand();
|
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() {
|
2025-01-09 18:07:02 +02: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() {
|
2025-01-09 18:07:02 +02:00
|
|
|
await this.showAndHoistSubtree("_hidden");
|
2022-08-04 23:00:32 +02:00
|
|
|
}
|
2022-12-05 23:57:29 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
async showOptionsCommand({ section }: CommandListenerData<"showOptions">) {
|
|
|
|
await appContext.tabManager.openContextWithNote(section || "_options", {
|
2023-02-14 16:06:49 +01:00
|
|
|
activate: true,
|
2025-01-09 18:07:02 +02:00
|
|
|
hoistedNoteId: "_options"
|
2023-02-14 16:06:49 +01:00
|
|
|
});
|
2022-12-15 16:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async showSQLConsoleHistoryCommand() {
|
2025-01-09 18:07:02 +02:00
|
|
|
await this.showAndHoistSubtree("_sqlConsole");
|
2022-12-15 16:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async showSearchHistoryCommand() {
|
2025-01-09 18:07:02 +02:00
|
|
|
await this.showAndHoistSubtree("_search");
|
2022-12-15 16:38:05 +01:00
|
|
|
}
|
|
|
|
|
2025-01-04 11:51:16 +02:00
|
|
|
async showAndHoistSubtree(subtreeNoteId: string) {
|
2023-02-14 16:06:49 +01:00
|
|
|
await appContext.tabManager.openContextWithNote(subtreeNoteId, {
|
|
|
|
activate: true,
|
|
|
|
hoistedNoteId: subtreeNoteId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-15 14:32:12 +01:00
|
|
|
async showNoteSourceCommand() {
|
2023-02-14 16:06:49 +01:00
|
|
|
const notePath = appContext.tabManager.getActiveContextNotePath();
|
|
|
|
|
|
|
|
if (notePath) {
|
2023-07-14 18:15:31 +02:00
|
|
|
await appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
|
2023-04-03 23:47:24 +02:00
|
|
|
activate: true,
|
|
|
|
viewScope: {
|
2025-01-09 18:07:02 +02:00
|
|
|
viewMode: "source"
|
2023-04-03 23:47:24 +02:00
|
|
|
}
|
|
|
|
});
|
2023-02-14 16:06:49 +01:00
|
|
|
}
|
2022-12-05 23:57:29 +01:00
|
|
|
}
|
2023-03-20 23:11:32 +01:00
|
|
|
|
|
|
|
async showAttachmentsCommand() {
|
|
|
|
const notePath = appContext.tabManager.getActiveContextNotePath();
|
|
|
|
|
|
|
|
if (notePath) {
|
2023-07-14 18:15:31 +02:00
|
|
|
await appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
|
2023-04-03 23:47:24 +02:00
|
|
|
activate: true,
|
|
|
|
viewScope: {
|
2025-01-09 18:07:02 +02:00
|
|
|
viewMode: "attachments"
|
2023-04-03 23:47:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async showAttachmentDetailCommand() {
|
|
|
|
const notePath = appContext.tabManager.getActiveContextNotePath();
|
|
|
|
|
|
|
|
if (notePath) {
|
2023-07-14 18:15:31 +02:00
|
|
|
await appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
|
2023-04-03 23:47:24 +02:00
|
|
|
activate: true,
|
|
|
|
viewScope: {
|
2025-01-09 18:07:02 +02:00
|
|
|
viewMode: "attachments"
|
2023-04-03 23:47:24 +02:00
|
|
|
}
|
|
|
|
});
|
2023-03-20 23:11:32 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-13 09:01:55 +02:00
|
|
|
|
2023-09-18 04:38:23 -04:00
|
|
|
toggleTrayCommand() {
|
|
|
|
if (!utils.isElectron()) return;
|
2025-01-09 18:07:02 +02:00
|
|
|
const { BrowserWindow } = utils.dynamicRequire("@electron/remote");
|
|
|
|
const windows = BrowserWindow.getAllWindows() as Electron.BaseWindow[];
|
|
|
|
const isVisible = windows.every((w) => w.isVisible());
|
|
|
|
const action = isVisible ? "hide" : "show";
|
2023-09-18 04:38:23 -04:00
|
|
|
for (const window of windows) window[action]();
|
|
|
|
}
|
|
|
|
|
2025-02-14 13:55:04 +02:00
|
|
|
toggleZenModeCommand() {
|
2025-02-14 18:18:28 +02:00
|
|
|
const $body = $("body");
|
|
|
|
$body.toggleClass("zen");
|
|
|
|
const isEnabled = $body.hasClass("zen");
|
|
|
|
appContext.triggerEvent("zenModeChanged", { isEnabled });
|
2025-02-14 13:55:04 +02:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
firstTabCommand() {
|
|
|
|
this.#goToTab(1);
|
|
|
|
}
|
|
|
|
secondTabCommand() {
|
|
|
|
this.#goToTab(2);
|
|
|
|
}
|
|
|
|
thirdTabCommand() {
|
|
|
|
this.#goToTab(3);
|
|
|
|
}
|
|
|
|
fourthTabCommand() {
|
|
|
|
this.#goToTab(4);
|
|
|
|
}
|
|
|
|
fifthTabCommand() {
|
|
|
|
this.#goToTab(5);
|
|
|
|
}
|
|
|
|
sixthTabCommand() {
|
|
|
|
this.#goToTab(6);
|
|
|
|
}
|
|
|
|
seventhTabCommand() {
|
|
|
|
this.#goToTab(7);
|
|
|
|
}
|
|
|
|
eigthTabCommand() {
|
|
|
|
this.#goToTab(8);
|
|
|
|
}
|
|
|
|
ninthTabCommand() {
|
|
|
|
this.#goToTab(9);
|
|
|
|
}
|
|
|
|
lastTabCommand() {
|
|
|
|
this.#goToTab(Number.POSITIVE_INFINITY);
|
|
|
|
}
|
2023-09-13 09:01:55 +02:00
|
|
|
|
2025-01-04 11:51:16 +02:00
|
|
|
#goToTab(tabNumber: number) {
|
2023-09-13 09:01:55 +02:00
|
|
|
const mainNoteContexts = appContext.tabManager.getMainNoteContexts();
|
|
|
|
|
|
|
|
const index = tabNumber === Number.POSITIVE_INFINITY ? mainNoteContexts.length - 1 : tabNumber - 1;
|
|
|
|
const tab = mainNoteContexts[index];
|
|
|
|
|
2023-09-13 09:10:56 +02:00
|
|
|
if (tab) {
|
|
|
|
appContext.tabManager.activateNoteContext(tab.ntxId);
|
|
|
|
}
|
2023-09-13 09:01:55 +02:00
|
|
|
}
|
2025-03-09 02:19:26 +00:00
|
|
|
|
2025-03-28 20:01:39 +00:00
|
|
|
async createAiChatCommand() {
|
2025-03-09 02:19:26 +00:00
|
|
|
try {
|
2025-03-28 20:01:39 +00:00
|
|
|
// Create a new AI Chat note
|
|
|
|
const parentNoteId = appContext.tabManager.getActiveContextNotePath();
|
|
|
|
|
|
|
|
if (!parentNoteId) {
|
|
|
|
toastService.showError("No active note to create AI Chat under");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = await noteCreateService.createNote(parentNoteId, {
|
|
|
|
title: "New AI Chat",
|
|
|
|
type: "aiChat",
|
|
|
|
content: JSON.stringify({
|
|
|
|
messages: [],
|
|
|
|
title: "New AI Chat"
|
|
|
|
})
|
2025-03-09 02:19:26 +00:00
|
|
|
});
|
2025-03-28 20:01:39 +00:00
|
|
|
|
|
|
|
if (!result.note) {
|
|
|
|
toastService.showError("Failed to create AI Chat note");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await appContext.tabManager.openTabWithNoteWithHoisting(result.note.noteId, {
|
|
|
|
activate: true
|
|
|
|
});
|
|
|
|
|
|
|
|
toastService.showMessage("Created new AI Chat note");
|
2025-03-09 02:19:26 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2025-03-28 20:01:39 +00:00
|
|
|
console.error("Error creating AI Chat note:", e);
|
|
|
|
toastService.showError("Failed to create AI Chat note: " + (e as Error).message);
|
2025-03-09 02:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-04 10:18:01 +02:00
|
|
|
}
|