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