2024-11-25 17:41:00 +08:00
|
|
|
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";
|
2025-01-09 18:36:24 +02:00
|
|
|
import type { ViewScope } from "../services/link.js";
|
2021-09-24 21:40:02 +02:00
|
|
|
|
2025-01-11 01:46:00 +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 }) => {
|
2022-12-18 22:05:06 +01:00
|
|
|
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
|
|
|
};
|