mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
chore(client/ts): port root_command_executor
This commit is contained in:
parent
634be6bbb4
commit
d8358407ce
@ -22,7 +22,7 @@ import { Node } from "../services/tree.js";
|
||||
import LoadResults from "../services/load_results.js";
|
||||
import { Attribute } from "../services/attribute_parser.js";
|
||||
import NoteTreeWidget from "../widgets/note_tree.js";
|
||||
import { GetTextEditorCallback } from "./note_context.js";
|
||||
import NoteContext, { GetTextEditorCallback } from "./note_context.js";
|
||||
|
||||
interface Layout {
|
||||
getRootWidget: (appContext: AppContext) => RootWidget;
|
||||
@ -70,8 +70,13 @@ export interface ExecuteCommandData extends CommandData {
|
||||
export type CommandMappings = {
|
||||
"api-log-messages": CommandData;
|
||||
focusOnDetail: Required<CommandData>;
|
||||
focusOnSearchDefinition: Required<CommandData>;
|
||||
searchNotes: CommandData & {
|
||||
searchString: string | undefined;
|
||||
searchString?: string;
|
||||
ancestorNoteId?: string | null;
|
||||
};
|
||||
showOptions: CommandData & {
|
||||
section: string;
|
||||
};
|
||||
showDeleteNotesDialog: CommandData & {
|
||||
branchIdsToDelete: string[];
|
||||
@ -194,6 +199,9 @@ type EventMappings = {
|
||||
addNewRelation: CommandData;
|
||||
sqlQueryResults: CommandData & {
|
||||
results: SqlExecuteResults;
|
||||
},
|
||||
readOnlyTemporarilyDisabled: {
|
||||
noteContext: NoteContext
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class NoteContext extends Component
|
||||
notePath?: string | null;
|
||||
private noteId?: string | null;
|
||||
private parentNoteId?: string | null;
|
||||
private viewScope?: ViewScope;
|
||||
viewScope?: ViewScope;
|
||||
|
||||
constructor(ntxId: string | null = null, hoistedNoteId: string = 'root', mainNtxId: string | null = null) {
|
||||
super();
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 treeService from "../services/tree.js";
|
||||
import openService from "../services/open.js";
|
||||
@ -11,21 +11,28 @@ import utils from "../services/utils.js";
|
||||
export default class RootCommandExecutor extends Component {
|
||||
editReadOnlyNoteCommand() {
|
||||
const noteContext = appContext.tabManager.getActiveContext();
|
||||
if (noteContext?.viewScope) {
|
||||
noteContext.viewScope.readOnlyTemporarilyDisabled = true;
|
||||
|
||||
appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext });
|
||||
}
|
||||
}
|
||||
|
||||
async showSQLConsoleCommand() {
|
||||
const sqlConsoleNote = await dateNoteService.createSqlConsole();
|
||||
if (!sqlConsoleNote) {
|
||||
return;
|
||||
}
|
||||
|
||||
const noteContext = await appContext.tabManager.openTabWithNoteWithHoisting(sqlConsoleNote.noteId, { activate: true });
|
||||
|
||||
appContext.triggerEvent('focusOnDetail', {ntxId: noteContext.ntxId});
|
||||
}
|
||||
|
||||
async searchNotesCommand({searchString, ancestorNoteId}) {
|
||||
async searchNotesCommand({searchString, ancestorNoteId}: CommandListenerData<"searchNotes">) {
|
||||
const searchNote = await dateNoteService.createSearchNote({searchString, ancestorNoteId});
|
||||
if (!searchNote) {
|
||||
return;
|
||||
}
|
||||
|
||||
// force immediate search
|
||||
await froca.loadSearchNote(searchNote.noteId);
|
||||
@ -37,7 +44,7 @@ export default class RootCommandExecutor extends Component {
|
||||
appContext.triggerCommand('focusOnSearchDefinition', {ntxId: noteContext.ntxId});
|
||||
}
|
||||
|
||||
async searchInSubtreeCommand({notePath}) {
|
||||
async searchInSubtreeCommand({notePath}: CommandListenerData<"searchInSubtree">) {
|
||||
const noteId = treeService.getNoteIdFromUrl(notePath);
|
||||
|
||||
this.searchNotesCommand({ancestorNoteId: noteId});
|
||||
@ -47,7 +54,7 @@ export default class RootCommandExecutor extends Component {
|
||||
const noteId = appContext.tabManager.getActiveContextNoteId();
|
||||
const mime = appContext.tabManager.getActiveContextNoteMime();
|
||||
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 mime = appContext.tabManager.getActiveContextNoteMime();
|
||||
if (noteId) {
|
||||
openService.openNoteCustom(noteId, mime);
|
||||
openService.openNoteCustom(noteId, mime || "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +103,7 @@ export default class RootCommandExecutor extends Component {
|
||||
await this.showAndHoistSubtree('_hidden');
|
||||
}
|
||||
|
||||
async showOptionsCommand({section}) {
|
||||
async showOptionsCommand({section}: CommandListenerData<"showOptions">) {
|
||||
await appContext.tabManager.openContextWithNote(section || '_options', {
|
||||
activate: true,
|
||||
hoistedNoteId: '_options'
|
||||
@ -111,7 +118,7 @@ export default class RootCommandExecutor extends Component {
|
||||
await this.showAndHoistSubtree('_search');
|
||||
}
|
||||
|
||||
async showAndHoistSubtree(subtreeNoteId) {
|
||||
async showAndHoistSubtree(subtreeNoteId: string) {
|
||||
await appContext.tabManager.openContextWithNote(subtreeNoteId, {
|
||||
activate: true,
|
||||
hoistedNoteId: subtreeNoteId
|
||||
@ -160,7 +167,7 @@ export default class RootCommandExecutor extends Component {
|
||||
toggleTrayCommand() {
|
||||
if (!utils.isElectron()) return;
|
||||
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 action = isVisible ? "hide" : "show"
|
||||
for (const window of windows) window[action]();
|
||||
@ -177,7 +184,7 @@ export default class RootCommandExecutor extends Component {
|
||||
ninthTabCommand() { this.#goToTab(9); }
|
||||
lastTabCommand() { this.#goToTab(Number.POSITIVE_INFINITY); }
|
||||
|
||||
#goToTab(tabNumber) {
|
||||
#goToTab(tabNumber: number) {
|
||||
const mainNoteContexts = appContext.tabManager.getMainNoteContexts();
|
||||
|
||||
const index = tabNumber === Number.POSITIVE_INFINITY ? mainNoteContexts.length - 1 : tabNumber - 1;
|
Loading…
x
Reference in New Issue
Block a user