2025-03-19 15:14:17 +01:00
|
|
|
import appContext, { type EventData } from "./app_context.js";
|
2022-12-01 13:07:23 +01:00
|
|
|
import noteCreateService from "../services/note_create.js";
|
|
|
|
import treeService from "../services/tree.js";
|
|
|
|
import hoistedNoteService from "../services/hoisted_note.js";
|
|
|
|
import Component from "./component.js";
|
2020-03-17 12:28:02 +01:00
|
|
|
|
|
|
|
/**
|
2023-05-05 23:41:11 +02:00
|
|
|
* This class contains command executors which logically belong to the NoteTree widget, but for better user experience,
|
2020-03-17 12:28:02 +01:00
|
|
|
* the keyboard shortcuts must be active on the whole screen and not just on the widget itself, so the executors
|
|
|
|
* must be at the root of the component tree.
|
|
|
|
*/
|
|
|
|
export default class MainTreeExecutors extends Component {
|
|
|
|
get tree() {
|
2022-12-11 13:54:12 +01:00
|
|
|
return appContext.noteTreeWidget;
|
2020-03-17 12:28:02 +01:00
|
|
|
}
|
|
|
|
|
2025-03-19 15:14:17 +01:00
|
|
|
async cloneNotesToCommand({ selectedOrActiveNoteIds }: EventData<"cloneNotesTo">) {
|
2024-12-23 14:14:38 +02:00
|
|
|
if (!this.tree) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.triggerCommand("cloneNoteIdsTo", { noteIds: selectedOrActiveNoteIds });
|
2020-03-17 12:28:02 +01:00
|
|
|
}
|
|
|
|
|
2025-03-19 15:14:17 +01:00
|
|
|
async moveNotesToCommand({ selectedOrActiveBranchIds }: EventData<"moveNotesTo">) {
|
2024-12-23 14:14:38 +02:00
|
|
|
if (!this.tree) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.triggerCommand("moveBranchIdsTo", { branchIds: selectedOrActiveBranchIds });
|
2020-03-17 12:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async createNoteIntoCommand() {
|
2021-05-22 12:35:41 +02:00
|
|
|
const activeNoteContext = appContext.tabManager.getActiveContext();
|
2020-03-17 12:28:02 +01:00
|
|
|
|
2024-12-23 21:47:36 +02:00
|
|
|
if (!activeNoteContext || !activeNoteContext.notePath || !activeNoteContext.note) {
|
2020-03-17 12:48:09 +01:00
|
|
|
return;
|
2020-03-17 12:28:02 +01:00
|
|
|
}
|
2020-03-17 12:48:09 +01:00
|
|
|
|
2021-05-22 12:26:45 +02:00
|
|
|
await noteCreateService.createNote(activeNoteContext.notePath, {
|
|
|
|
isProtected: activeNoteContext.note.isProtected,
|
2020-03-17 12:48:09 +01:00
|
|
|
saveSelection: false
|
|
|
|
});
|
2020-03-17 12:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async createNoteAfterCommand() {
|
2024-12-23 14:14:38 +02:00
|
|
|
if (!this.tree) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-17 12:28:02 +01:00
|
|
|
const node = this.tree.getActiveNode();
|
2021-07-21 20:19:17 +02:00
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-03 22:48:06 +01:00
|
|
|
const parentNotePath = treeService.getNotePath(node.getParent());
|
2023-05-05 23:17:23 +02:00
|
|
|
const isProtected = treeService.getParentProtectedStatus(node);
|
2020-03-17 12:28:02 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
if (node.data.noteId === "root" || node.data.noteId === hoistedNoteService.getHoistedNoteId()) {
|
2020-03-17 12:28:02 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-03 22:48:06 +01:00
|
|
|
await noteCreateService.createNote(parentNotePath, {
|
2025-01-09 18:07:02 +02:00
|
|
|
target: "after",
|
2020-03-17 12:28:02 +01:00
|
|
|
targetBranchId: node.data.branchId,
|
|
|
|
isProtected: isProtected,
|
2020-05-05 21:42:18 +02:00
|
|
|
saveSelection: false
|
2020-03-17 12:28:02 +01:00
|
|
|
});
|
|
|
|
}
|
2020-06-04 21:44:34 +02:00
|
|
|
}
|