refactor(client/ts): use command names enum in context menu

This commit is contained in:
Elian Doran 2024-12-22 18:33:57 +02:00
parent f4e2973a0c
commit 19652fbbce
No known key found for this signature in database
5 changed files with 41 additions and 17 deletions

View File

@ -69,19 +69,40 @@ type CommandMappings = {
notePath: string;
hoistedNoteId: string;
viewScope: ViewScope;
}
},
openNoteInNewTab: CommandData;
openNoteInNewSplit: CommandData;
openNoteInNewWindow: CommandData;
openNoteInSplit: CommandData;
openInTab: CommandData;
insertNoteAfter: CommandData;
insertChildNote: CommandData;
convertNoteToAttachment: CommandData;
copyNotePathToClipboard: CommandData;
executeInActiveNoteDetailWidget: CommandData & {
callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void
};
addTextToActiveEditor: CommandData & {
text: string;
};
/** Works only in the electron context menu. */
replaceMisspelling: CommandData;
importMarkdownInline: CommandData;
showPasswordNotSet: CommandData;
showProtectedSessionPasswordDialog: CommandData;
closeProtectedSessionPasswordDialog: CommandData;
resetLauncher: CommandData;
addNoteLauncher: CommandData;
addScriptLauncher: CommandData;
addWidgetLauncher: CommandData;
addSpacerLauncher: CommandData;
moveLauncherToVisible: CommandData;
moveLauncherToAvailable: CommandData;
duplicateSubtree: CommandData;
deleteNotes: CommandData;
copyImageReferenceToClipboard: CommandData;
copyImageToClipboard: CommandData;
}
type EventMappings = {

View File

@ -1,3 +1,4 @@
import { CommandNames } from '../components/app_context.js';
import keyboardActionService from '../services/keyboard_actions.js';
interface ContextMenuOptions {
@ -14,7 +15,7 @@ interface MenuSeparatorItem {
export interface MenuCommandItem {
title: string;
command?: string;
command?: CommandNames;
type?: string;
uiIcon?: string;
templateNoteId?: string;

View File

@ -1,7 +1,7 @@
import utils from "../services/utils.js";
import options from "../services/options.js";
import zoomService from "../components/zoom.js";
import contextMenu from "./context_menu.js";
import contextMenu, { MenuItem } from "./context_menu.js";
import { t } from "../services/i18n.js";
import type { BrowserWindow } from "electron";
@ -18,7 +18,7 @@ function setupContextMenu() {
const isMac = process.platform === "darwin";
const platformModifier = isMac ? 'Meta' : 'Ctrl';
const items = [];
const items: MenuItem[] = [];
if (params.misspelledWord) {
for (const suggestion of params.dictionarySuggestions) {

View File

@ -38,7 +38,7 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener
const canBeDeleted = !note?.noteId.startsWith("_"); // fixed notes can't be deleted
const canBeReset = !canBeDeleted && note?.isLaunchBarConfig();
return [
const items: (MenuItem | null)[] = [
(isVisibleRoot || isAvailableRoot) ? { title: t("launcher_context_menu.add-note-launcher"), command: 'addNoteLauncher', uiIcon: "bx bx-note" } : null,
(isVisibleRoot || isAvailableRoot) ? { title: t("launcher_context_menu.add-script-launcher"), command: 'addScriptLauncher', uiIcon: "bx bx-code-curly" } : null,
(isVisibleRoot || isAvailableRoot) ? { title: t("launcher_context_menu.add-custom-widget"), command: 'addWidgetLauncher', uiIcon: "bx bx-customize" } : null,
@ -55,7 +55,8 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener
{ title: "----" },
{ title: t("launcher_context_menu.reset"), command: "resetLauncher", uiIcon: "bx bx-reset destructive-action-icon", enabled: canBeReset}
].filter(row => row !== null);
];
return items.filter(row => row !== null);
}
async selectMenuItemHandler({command}: MenuCommandItem) {

View File

@ -2,19 +2,20 @@ import server from "./server.js";
import froca from "./froca.js";
import { t } from "./i18n.js";
import { MenuItem } from "../menus/context_menu.js";
import { CommandNames } from "../components/app_context.js";
async function getNoteTypeItems(command?: string) {
async function getNoteTypeItems(command?: CommandNames) {
const items: MenuItem[] = [
{ title: t("note_types.text"), command: command, type: "text", uiIcon: "bx bx-note" },
{ title: t("note_types.code"), command: command, type: "code", uiIcon: "bx bx-code" },
{ title: t("note_types.saved-search"), command: command, type: "search", uiIcon: "bx bx-file-find" },
{ title: t("note_types.relation-map"), command: command, type: "relationMap", uiIcon: "bx bxs-network-chart" },
{ title: t("note_types.note-map"), command: command, type: "noteMap", uiIcon: "bx bxs-network-chart" },
{ title: t("note_types.render-note"), command: command, type: "render", uiIcon: "bx bx-extension" },
{ title: t("note_types.book"), command: command, type: "book", uiIcon: "bx bx-book" },
{ title: t("note_types.mermaid-diagram"), command: command, type: "mermaid", uiIcon: "bx bx-selection" },
{ title: t("note_types.canvas"), command: command, type: "canvas", uiIcon: "bx bx-pen" },
{ title: t("note_types.web-view"), command: command, type: "webView", uiIcon: "bx bx-globe-alt" },
{ title: t("note_types.text"), command, type: "text", uiIcon: "bx bx-note" },
{ title: t("note_types.code"), command, type: "code", uiIcon: "bx bx-code" },
{ title: t("note_types.saved-search"), command, type: "search", uiIcon: "bx bx-file-find" },
{ title: t("note_types.relation-map"), command, type: "relationMap", uiIcon: "bx bxs-network-chart" },
{ title: t("note_types.note-map"), command, type: "noteMap", uiIcon: "bx bxs-network-chart" },
{ title: t("note_types.render-note"), command, type: "render", uiIcon: "bx bx-extension" },
{ title: t("note_types.book"), command, type: "book", uiIcon: "bx bx-book" },
{ title: t("note_types.mermaid-diagram"), command, type: "mermaid", uiIcon: "bx bx-selection" },
{ title: t("note_types.canvas"), command, type: "canvas", uiIcon: "bx bx-pen" },
{ title: t("note_types.web-view"), command, type: "webView", uiIcon: "bx bx-globe-alt" },
{ title: t("note_types.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" }
];