feat(geo_map): add back open context menu

pull/1017/head
Elian Doran 2025-01-22 20:02:20 +07:00
parent 2e1ad24584
commit 47b02da021
No known key found for this signature in database
2 changed files with 38 additions and 23 deletions

@ -1,36 +1,44 @@
import { t } from "../services/i18n.js"; import { t } from "../services/i18n.js";
import contextMenu, { type ContextMenuEvent } from "./context_menu.js"; import contextMenu, { type ContextMenuEvent, type MenuItem } from "./context_menu.js";
import appContext from "../components/app_context.js"; import appContext, { type CommandNames } from "../components/app_context.js";
import type { ViewScope } from "../services/link.js"; import type { ViewScope } from "../services/link.js";
function openContextMenu(notePath: string, e: ContextMenuEvent, viewScope: ViewScope = {}, hoistedNoteId: string | null = null) { function openContextMenu(notePath: string, e: ContextMenuEvent, viewScope: ViewScope = {}, hoistedNoteId: string | null = null) {
contextMenu.show({ contextMenu.show({
x: e.pageX, x: e.pageX,
y: e.pageY, y: e.pageY,
items: [ items: getItems(),
{ title: t("link_context_menu.open_note_in_new_tab"), command: "openNoteInNewTab", uiIcon: "bx bx-link-external" }, selectMenuItemHandler: ({ command }) => handleLinkContextMenuItem(command, notePath, viewScope, hoistedNoteId)
{ 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" } }
],
selectMenuItemHandler: ({ command }) => { function getItems(): MenuItem<any>[] {
if (!hoistedNoteId) { return [
hoistedNoteId = appContext.tabManager.getActiveContext().hoistedNoteId; { 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" }
];
}
if (command === "openNoteInNewTab") { function handleLinkContextMenuItem(command: string | undefined, notePath: string, viewScope = {}, hoistedNoteId: string | null = null) {
appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId, viewScope }); if (!hoistedNoteId) {
} else if (command === "openNoteInNewSplit") { hoistedNoteId = appContext.tabManager.getActiveContext().hoistedNoteId;
const subContexts = appContext.tabManager.getActiveContext().getSubContexts(); }
const { ntxId } = subContexts[subContexts.length - 1];
appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath, hoistedNoteId, viewScope }); if (command === "openNoteInNewTab") {
} else if (command === "openNoteInNewWindow") { appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId, viewScope });
appContext.triggerCommand("openInWindow", { notePath, hoistedNoteId, viewScope }); } else if (command === "openNoteInNewSplit") {
} const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
} const { ntxId } = subContexts[subContexts.length - 1];
});
appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath, hoistedNoteId, viewScope });
} else if (command === "openNoteInNewWindow") {
appContext.triggerCommand("openInWindow", { notePath, hoistedNoteId, viewScope });
}
} }
export default { export default {
getItems,
handleLinkContextMenuItem,
openContextMenu openContextMenu
}; };

@ -1,18 +1,25 @@
import appContext from "../../components/app_context.js"; import appContext from "../../components/app_context.js";
import type { ContextMenuEvent } from "../../menus/context_menu.js"; import type { ContextMenuEvent } from "../../menus/context_menu.js";
import contextMenu from "../../menus/context_menu.js"; import contextMenu from "../../menus/context_menu.js";
import linkContextMenu from "../../menus/link_context_menu.js";
export default function openContextMenu(noteId: string, e: ContextMenuEvent) { export default function openContextMenu(noteId: string, e: ContextMenuEvent) {
contextMenu.show({ contextMenu.show({
x: e.pageX, x: e.pageX,
y: e.pageY, y: e.pageY,
items: [ items: [
...linkContextMenu.getItems(),
{ title: "----" },
{ title: "Remove from map", command: "deleteFromMap", uiIcon: "bx bx-trash" } { title: "Remove from map", command: "deleteFromMap", uiIcon: "bx bx-trash" }
], ],
selectMenuItemHandler: ({ command }) => { selectMenuItemHandler: ({ command }) => {
if (command) { if (command === "deleteFromMap") {
appContext.triggerCommand(command, { noteId }); appContext.triggerCommand(command, { noteId });
return;
} }
// Pass the events to the link context menu
linkContextMenu.handleLinkContextMenuItem(command, noteId);
} }
}); });
} }