-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathroot_command_executor.ts
252 lines (211 loc) · 7.75 KB
/
root_command_executor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import Component from "./component.js";
import appContext, { type CommandData, type CommandListenerData } 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";
import utils from "../services/utils.js";
import LlmChatPanel from "../widgets/llm_chat_panel.js";
import toastService from "../services/toast.js";
export default class RootCommandExecutor extends Component {
private llmChatPanel: any = null;
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 }: CommandListenerData<"searchNotes">) {
const searchNote = await dateNoteService.createSearchNote({ searchString, ancestorNoteId });
if (!searchNote) {
return;
}
// force immediate search
await froca.loadSearchNote(searchNote.noteId);
const noteContext = await appContext.tabManager.openTabWithNoteWithHoisting(searchNote.noteId, {
activate: true
});
appContext.triggerCommand("focusOnSearchDefinition", { ntxId: noteContext.ntxId });
}
async searchInSubtreeCommand({ notePath }: CommandListenerData<"searchInSubtree">) {
const noteId = treeService.getNoteIdFromUrl(notePath);
this.searchNotesCommand({ ancestorNoteId: noteId });
}
openNoteExternallyCommand() {
const noteId = appContext.tabManager.getActiveContextNoteId();
const mime = appContext.tabManager.getActiveContextNoteMime();
if (noteId) {
openService.openNoteExternally(noteId, mime || "");
}
}
openNoteCustomCommand() {
const noteId = appContext.tabManager.getActiveContextNoteId();
const mime = appContext.tabManager.getActiveContextNoteMime();
if (noteId) {
openService.openNoteCustom(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.openTabWithNoteWithHoisting("_backendLog", { activate: true });
}
async showHelpCommand() {
await this.showAndHoistSubtree("_help");
}
async showLaunchBarSubtreeCommand() {
const rootNote = utils.isMobile() ? "_lbMobileRoot" : "_lbRoot";
await this.showAndHoistSubtree(rootNote);
this.showLeftPaneCommand();
}
async showShareSubtreeCommand() {
await this.showAndHoistSubtree("_share");
}
async showHiddenSubtreeCommand() {
await this.showAndHoistSubtree("_hidden");
}
async showOptionsCommand({ section }: CommandListenerData<"showOptions">) {
await appContext.tabManager.openContextWithNote(section || "_options", {
activate: true,
hoistedNoteId: "_options"
});
}
async showSQLConsoleHistoryCommand() {
await this.showAndHoistSubtree("_sqlConsole");
}
async showSearchHistoryCommand() {
await this.showAndHoistSubtree("_search");
}
async showAndHoistSubtree(subtreeNoteId: string) {
await appContext.tabManager.openContextWithNote(subtreeNoteId, {
activate: true,
hoistedNoteId: subtreeNoteId
});
}
async showNoteSourceCommand() {
const notePath = appContext.tabManager.getActiveContextNotePath();
if (notePath) {
await appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
activate: true,
viewScope: {
viewMode: "source"
}
});
}
}
async showAttachmentsCommand() {
const notePath = appContext.tabManager.getActiveContextNotePath();
if (notePath) {
await appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
activate: true,
viewScope: {
viewMode: "attachments"
}
});
}
}
async showAttachmentDetailCommand() {
const notePath = appContext.tabManager.getActiveContextNotePath();
if (notePath) {
await appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
activate: true,
viewScope: {
viewMode: "attachments"
}
});
}
}
toggleTrayCommand() {
if (!utils.isElectron()) return;
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";
for (const window of windows) window[action]();
}
toggleZenModeCommand() {
const $body = $("body");
$body.toggleClass("zen");
const isEnabled = $body.hasClass("zen");
appContext.triggerEvent("zenModeChanged", { isEnabled });
}
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);
}
#goToTab(tabNumber: number) {
const mainNoteContexts = appContext.tabManager.getMainNoteContexts();
const index = tabNumber === Number.POSITIVE_INFINITY ? mainNoteContexts.length - 1 : tabNumber - 1;
const tab = mainNoteContexts[index];
if (tab) {
appContext.tabManager.activateNoteContext(tab.ntxId);
}
}
async showLlmChatCommand() {
console.log("showLlmChatCommand triggered");
toastService.showMessage("Opening LLM Chat...");
try {
// We'll use the Note Map approach - open a known note ID that corresponds to the LLM chat panel
await appContext.tabManager.openTabWithNoteWithHoisting("_globalNoteMap", {
activate: true,
viewScope: {
viewMode: "llmChat" // We'll need to handle this custom view mode elsewhere
}
});
}
catch (e) {
console.error("Error opening LLM Chat:", e);
toastService.showError("Failed to open LLM Chat: " + (e as Error).message);
}
}
}