mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 02:52:27 +08:00
refactor(client/ts): use command names enum in context menu
This commit is contained in:
parent
f4e2973a0c
commit
19652fbbce
@ -69,19 +69,40 @@ type CommandMappings = {
|
|||||||
notePath: string;
|
notePath: string;
|
||||||
hoistedNoteId: string;
|
hoistedNoteId: string;
|
||||||
viewScope: ViewScope;
|
viewScope: ViewScope;
|
||||||
}
|
},
|
||||||
|
openNoteInNewTab: CommandData;
|
||||||
|
openNoteInNewSplit: CommandData;
|
||||||
|
openNoteInNewWindow: CommandData;
|
||||||
|
openNoteInSplit: CommandData;
|
||||||
|
openInTab: CommandData;
|
||||||
|
insertNoteAfter: CommandData;
|
||||||
|
insertChildNote: CommandData;
|
||||||
|
convertNoteToAttachment: CommandData;
|
||||||
|
copyNotePathToClipboard: CommandData;
|
||||||
executeInActiveNoteDetailWidget: CommandData & {
|
executeInActiveNoteDetailWidget: CommandData & {
|
||||||
callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void
|
callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void
|
||||||
};
|
};
|
||||||
addTextToActiveEditor: CommandData & {
|
addTextToActiveEditor: CommandData & {
|
||||||
text: string;
|
text: string;
|
||||||
};
|
};
|
||||||
|
/** Works only in the electron context menu. */
|
||||||
|
replaceMisspelling: CommandData;
|
||||||
|
|
||||||
importMarkdownInline: CommandData;
|
importMarkdownInline: CommandData;
|
||||||
showPasswordNotSet: CommandData;
|
showPasswordNotSet: CommandData;
|
||||||
showProtectedSessionPasswordDialog: CommandData;
|
showProtectedSessionPasswordDialog: CommandData;
|
||||||
closeProtectedSessionPasswordDialog: CommandData;
|
closeProtectedSessionPasswordDialog: CommandData;
|
||||||
resetLauncher: 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 = {
|
type EventMappings = {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { CommandNames } from '../components/app_context.js';
|
||||||
import keyboardActionService from '../services/keyboard_actions.js';
|
import keyboardActionService from '../services/keyboard_actions.js';
|
||||||
|
|
||||||
interface ContextMenuOptions {
|
interface ContextMenuOptions {
|
||||||
@ -14,7 +15,7 @@ interface MenuSeparatorItem {
|
|||||||
|
|
||||||
export interface MenuCommandItem {
|
export interface MenuCommandItem {
|
||||||
title: string;
|
title: string;
|
||||||
command?: string;
|
command?: CommandNames;
|
||||||
type?: string;
|
type?: string;
|
||||||
uiIcon?: string;
|
uiIcon?: string;
|
||||||
templateNoteId?: string;
|
templateNoteId?: string;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import utils from "../services/utils.js";
|
import utils from "../services/utils.js";
|
||||||
import options from "../services/options.js";
|
import options from "../services/options.js";
|
||||||
import zoomService from "../components/zoom.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 { t } from "../services/i18n.js";
|
||||||
import type { BrowserWindow } from "electron";
|
import type { BrowserWindow } from "electron";
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ function setupContextMenu() {
|
|||||||
const isMac = process.platform === "darwin";
|
const isMac = process.platform === "darwin";
|
||||||
const platformModifier = isMac ? 'Meta' : 'Ctrl';
|
const platformModifier = isMac ? 'Meta' : 'Ctrl';
|
||||||
|
|
||||||
const items = [];
|
const items: MenuItem[] = [];
|
||||||
|
|
||||||
if (params.misspelledWord) {
|
if (params.misspelledWord) {
|
||||||
for (const suggestion of params.dictionarySuggestions) {
|
for (const suggestion of params.dictionarySuggestions) {
|
||||||
|
@ -38,7 +38,7 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener
|
|||||||
const canBeDeleted = !note?.noteId.startsWith("_"); // fixed notes can't be deleted
|
const canBeDeleted = !note?.noteId.startsWith("_"); // fixed notes can't be deleted
|
||||||
const canBeReset = !canBeDeleted && note?.isLaunchBarConfig();
|
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-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-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,
|
(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: "----" },
|
||||||
|
|
||||||
{ title: t("launcher_context_menu.reset"), command: "resetLauncher", uiIcon: "bx bx-reset destructive-action-icon", enabled: canBeReset}
|
{ 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) {
|
async selectMenuItemHandler({command}: MenuCommandItem) {
|
||||||
|
@ -2,19 +2,20 @@ import server from "./server.js";
|
|||||||
import froca from "./froca.js";
|
import froca from "./froca.js";
|
||||||
import { t } from "./i18n.js";
|
import { t } from "./i18n.js";
|
||||||
import { MenuItem } from "../menus/context_menu.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[] = [
|
const items: MenuItem[] = [
|
||||||
{ title: t("note_types.text"), command: command, type: "text", uiIcon: "bx bx-note" },
|
{ title: t("note_types.text"), command, type: "text", uiIcon: "bx bx-note" },
|
||||||
{ title: t("note_types.code"), command: command, type: "code", uiIcon: "bx bx-code" },
|
{ title: t("note_types.code"), 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.saved-search"), 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.relation-map"), 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.note-map"), 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.render-note"), command, type: "render", uiIcon: "bx bx-extension" },
|
||||||
{ title: t("note_types.book"), command: command, type: "book", uiIcon: "bx bx-book" },
|
{ title: t("note_types.book"), 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.mermaid-diagram"), command, type: "mermaid", uiIcon: "bx bx-selection" },
|
||||||
{ title: t("note_types.canvas"), command: command, type: "canvas", uiIcon: "bx bx-pen" },
|
{ title: t("note_types.canvas"), 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.web-view"), command, type: "webView", uiIcon: "bx bx-globe-alt" },
|
||||||
{ title: t("note_types.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" }
|
{ title: t("note_types.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user