chore(client/ts): port root_command_executor

This commit is contained in:
Elian Doran 2025-01-04 11:51:16 +02:00
parent 634be6bbb4
commit d8358407ce
No known key found for this signature in database
3 changed files with 31 additions and 16 deletions

View File

@ -22,7 +22,7 @@ import { Node } from "../services/tree.js";
import LoadResults from "../services/load_results.js"; import LoadResults from "../services/load_results.js";
import { Attribute } from "../services/attribute_parser.js"; import { Attribute } from "../services/attribute_parser.js";
import NoteTreeWidget from "../widgets/note_tree.js"; import NoteTreeWidget from "../widgets/note_tree.js";
import { GetTextEditorCallback } from "./note_context.js"; import NoteContext, { GetTextEditorCallback } from "./note_context.js";
interface Layout { interface Layout {
getRootWidget: (appContext: AppContext) => RootWidget; getRootWidget: (appContext: AppContext) => RootWidget;
@ -70,8 +70,13 @@ export interface ExecuteCommandData extends CommandData {
export type CommandMappings = { export type CommandMappings = {
"api-log-messages": CommandData; "api-log-messages": CommandData;
focusOnDetail: Required<CommandData>; focusOnDetail: Required<CommandData>;
focusOnSearchDefinition: Required<CommandData>;
searchNotes: CommandData & { searchNotes: CommandData & {
searchString: string | undefined; searchString?: string;
ancestorNoteId?: string | null;
};
showOptions: CommandData & {
section: string;
}; };
showDeleteNotesDialog: CommandData & { showDeleteNotesDialog: CommandData & {
branchIdsToDelete: string[]; branchIdsToDelete: string[];
@ -194,6 +199,9 @@ type EventMappings = {
addNewRelation: CommandData; addNewRelation: CommandData;
sqlQueryResults: CommandData & { sqlQueryResults: CommandData & {
results: SqlExecuteResults; results: SqlExecuteResults;
},
readOnlyTemporarilyDisabled: {
noteContext: NoteContext
} }
} }

View File

@ -28,7 +28,7 @@ class NoteContext extends Component
notePath?: string | null; notePath?: string | null;
private noteId?: string | null; private noteId?: string | null;
private parentNoteId?: string | null; private parentNoteId?: string | null;
private viewScope?: ViewScope; viewScope?: ViewScope;
constructor(ntxId: string | null = null, hoistedNoteId: string = 'root', mainNtxId: string | null = null) { constructor(ntxId: string | null = null, hoistedNoteId: string = 'root', mainNtxId: string | null = null) {
super(); super();

View File

@ -1,5 +1,5 @@
import Component from "./component.js"; import Component from "./component.js";
import appContext from "./app_context.js"; import appContext, { CommandData, CommandListenerData } from "./app_context.js";
import dateNoteService from "../services/date_notes.js"; import dateNoteService from "../services/date_notes.js";
import treeService from "../services/tree.js"; import treeService from "../services/tree.js";
import openService from "../services/open.js"; import openService from "../services/open.js";
@ -11,21 +11,28 @@ import utils from "../services/utils.js";
export default class RootCommandExecutor extends Component { export default class RootCommandExecutor extends Component {
editReadOnlyNoteCommand() { editReadOnlyNoteCommand() {
const noteContext = appContext.tabManager.getActiveContext(); const noteContext = appContext.tabManager.getActiveContext();
noteContext.viewScope.readOnlyTemporarilyDisabled = true; if (noteContext?.viewScope) {
noteContext.viewScope.readOnlyTemporarilyDisabled = true;
appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext }); appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext });
}
} }
async showSQLConsoleCommand() { async showSQLConsoleCommand() {
const sqlConsoleNote = await dateNoteService.createSqlConsole(); const sqlConsoleNote = await dateNoteService.createSqlConsole();
if (!sqlConsoleNote) {
return;
}
const noteContext = await appContext.tabManager.openTabWithNoteWithHoisting(sqlConsoleNote.noteId, { activate: true }); const noteContext = await appContext.tabManager.openTabWithNoteWithHoisting(sqlConsoleNote.noteId, { activate: true });
appContext.triggerEvent('focusOnDetail', {ntxId: noteContext.ntxId}); appContext.triggerEvent('focusOnDetail', {ntxId: noteContext.ntxId});
} }
async searchNotesCommand({searchString, ancestorNoteId}) { async searchNotesCommand({searchString, ancestorNoteId}: CommandListenerData<"searchNotes">) {
const searchNote = await dateNoteService.createSearchNote({searchString, ancestorNoteId}); const searchNote = await dateNoteService.createSearchNote({searchString, ancestorNoteId});
if (!searchNote) {
return;
}
// force immediate search // force immediate search
await froca.loadSearchNote(searchNote.noteId); await froca.loadSearchNote(searchNote.noteId);
@ -37,7 +44,7 @@ export default class RootCommandExecutor extends Component {
appContext.triggerCommand('focusOnSearchDefinition', {ntxId: noteContext.ntxId}); appContext.triggerCommand('focusOnSearchDefinition', {ntxId: noteContext.ntxId});
} }
async searchInSubtreeCommand({notePath}) { async searchInSubtreeCommand({notePath}: CommandListenerData<"searchInSubtree">) {
const noteId = treeService.getNoteIdFromUrl(notePath); const noteId = treeService.getNoteIdFromUrl(notePath);
this.searchNotesCommand({ancestorNoteId: noteId}); this.searchNotesCommand({ancestorNoteId: noteId});
@ -47,7 +54,7 @@ export default class RootCommandExecutor extends Component {
const noteId = appContext.tabManager.getActiveContextNoteId(); const noteId = appContext.tabManager.getActiveContextNoteId();
const mime = appContext.tabManager.getActiveContextNoteMime(); const mime = appContext.tabManager.getActiveContextNoteMime();
if (noteId) { if (noteId) {
openService.openNoteExternally(noteId, mime); openService.openNoteExternally(noteId, mime || "");
} }
} }
@ -55,7 +62,7 @@ export default class RootCommandExecutor extends Component {
const noteId = appContext.tabManager.getActiveContextNoteId(); const noteId = appContext.tabManager.getActiveContextNoteId();
const mime = appContext.tabManager.getActiveContextNoteMime(); const mime = appContext.tabManager.getActiveContextNoteMime();
if (noteId) { if (noteId) {
openService.openNoteCustom(noteId, mime); openService.openNoteCustom(noteId, mime || "");
} }
} }
@ -82,7 +89,7 @@ export default class RootCommandExecutor extends Component {
async showBackendLogCommand() { async showBackendLogCommand() {
await appContext.tabManager.openTabWithNoteWithHoisting('_backendLog', { activate: true }); await appContext.tabManager.openTabWithNoteWithHoisting('_backendLog', { activate: true });
} }
async showLaunchBarSubtreeCommand() { async showLaunchBarSubtreeCommand() {
await this.showAndHoistSubtree('_lbRoot'); await this.showAndHoistSubtree('_lbRoot');
this.showLeftPaneCommand(); this.showLeftPaneCommand();
@ -96,7 +103,7 @@ export default class RootCommandExecutor extends Component {
await this.showAndHoistSubtree('_hidden'); await this.showAndHoistSubtree('_hidden');
} }
async showOptionsCommand({section}) { async showOptionsCommand({section}: CommandListenerData<"showOptions">) {
await appContext.tabManager.openContextWithNote(section || '_options', { await appContext.tabManager.openContextWithNote(section || '_options', {
activate: true, activate: true,
hoistedNoteId: '_options' hoistedNoteId: '_options'
@ -111,7 +118,7 @@ export default class RootCommandExecutor extends Component {
await this.showAndHoistSubtree('_search'); await this.showAndHoistSubtree('_search');
} }
async showAndHoistSubtree(subtreeNoteId) { async showAndHoistSubtree(subtreeNoteId: string) {
await appContext.tabManager.openContextWithNote(subtreeNoteId, { await appContext.tabManager.openContextWithNote(subtreeNoteId, {
activate: true, activate: true,
hoistedNoteId: subtreeNoteId hoistedNoteId: subtreeNoteId
@ -160,7 +167,7 @@ export default class RootCommandExecutor extends Component {
toggleTrayCommand() { toggleTrayCommand() {
if (!utils.isElectron()) return; if (!utils.isElectron()) return;
const {BrowserWindow} = utils.dynamicRequire('@electron/remote'); const {BrowserWindow} = utils.dynamicRequire('@electron/remote');
const windows = BrowserWindow.getAllWindows(); const windows = (BrowserWindow.getAllWindows()) as Electron.BaseWindow[];
const isVisible = windows.every(w => w.isVisible()); const isVisible = windows.every(w => w.isVisible());
const action = isVisible ? "hide" : "show" const action = isVisible ? "hide" : "show"
for (const window of windows) window[action](); for (const window of windows) window[action]();
@ -177,7 +184,7 @@ export default class RootCommandExecutor extends Component {
ninthTabCommand() { this.#goToTab(9); } ninthTabCommand() { this.#goToTab(9); }
lastTabCommand() { this.#goToTab(Number.POSITIVE_INFINITY); } lastTabCommand() { this.#goToTab(Number.POSITIVE_INFINITY); }
#goToTab(tabNumber) { #goToTab(tabNumber: number) {
const mainNoteContexts = appContext.tabManager.getMainNoteContexts(); const mainNoteContexts = appContext.tabManager.getMainNoteContexts();
const index = tabNumber === Number.POSITIVE_INFINITY ? mainNoteContexts.length - 1 : tabNumber - 1; const index = tabNumber === Number.POSITIVE_INFINITY ? mainNoteContexts.length - 1 : tabNumber - 1;