Notes/src/public/app/menus/link_context_menu.ts

37 lines
1.7 KiB
TypeScript
Raw Normal View History

import { t } from "../services/i18n.js";
2021-09-24 21:40:02 +02:00
import contextMenu from "./context_menu.js";
2022-12-01 13:07:23 +01:00
import appContext from "../components/app_context.js";
import type { ViewScope } from "../services/link.js";
2021-09-24 21:40:02 +02:00
function openContextMenu(notePath: string, e: PointerEvent | JQuery.ContextMenuEvent, viewScope: ViewScope = {}, hoistedNoteId: string | null = null) {
2021-09-24 21:40:02 +02:00
contextMenu.show({
x: e.pageX,
y: e.pageY,
items: [
2025-01-09 18:07:02 +02:00
{ title: t("link_context_menu.open_note_in_new_tab"), command: "openNoteInNewTab", uiIcon: "bx bx-link-external" },
{ title: t("link_context_menu.open_note_in_new_split"), command: "openNoteInNewSplit", uiIcon: "bx bx-dock-right" },
{ title: t("link_context_menu.open_note_in_new_window"), command: "openNoteInNewWindow", uiIcon: "bx bx-window-open" }
2021-09-24 21:40:02 +02:00
],
2025-01-09 18:07:02 +02:00
selectMenuItemHandler: ({ command }) => {
if (!hoistedNoteId) {
hoistedNoteId = appContext.tabManager.getActiveContext().hoistedNoteId;
}
2025-01-09 18:07:02 +02:00
if (command === "openNoteInNewTab") {
2023-04-03 23:47:24 +02:00
appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId, viewScope });
2025-01-09 18:07:02 +02:00
} else if (command === "openNoteInNewSplit") {
2021-09-24 21:40:02 +02:00
const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
2025-01-09 18:07:02 +02:00
const { ntxId } = subContexts[subContexts.length - 1];
2021-09-24 21:40:02 +02:00
2025-01-09 18:07:02 +02:00
appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath, hoistedNoteId, viewScope });
} else if (command === "openNoteInNewWindow") {
appContext.triggerCommand("openInWindow", { notePath, hoistedNoteId, viewScope });
2021-09-24 21:40:02 +02:00
}
}
});
}
export default {
openContextMenu
2025-01-09 18:07:02 +02:00
};