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

39 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 { ViewScope } from "../services/link.js";
2021-09-24 21:40:02 +02:00
function openContextMenu(notePath: string, e: PointerEvent, viewScope: ViewScope = {}, hoistedNoteId: string | null = null) {
2021-09-24 21:40:02 +02:00
contextMenu.show({
x: e.pageX,
y: e.pageY,
items: [
{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
],
selectMenuItemHandler: ({command}) => {
if (!hoistedNoteId) {
hoistedNoteId = appContext.tabManager.getActiveContext().hoistedNoteId;
}
2021-09-24 21:40:02 +02:00
if (command === 'openNoteInNewTab') {
2023-04-03 23:47:24 +02:00
appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId, viewScope });
2021-09-24 21:40:02 +02:00
}
else if (command === 'openNoteInNewSplit') {
const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
const {ntxId} = subContexts[subContexts.length - 1];
2023-04-03 23:47:24 +02:00
appContext.triggerCommand("openNewNoteSplit", {ntxId, notePath, hoistedNoteId, viewScope});
2021-09-24 21:40:02 +02:00
}
else if (command === 'openNoteInNewWindow') {
2023-04-03 23:47:24 +02:00
appContext.triggerCommand('openInWindow', {notePath, hoistedNoteId, viewScope});
2021-09-24 21:40:02 +02:00
}
}
});
}
export default {
openContextMenu
}