mirror of
https://github.com/zadam/trilium.git
synced 2025-10-28 08:46:43 +01:00
client/menus: refactor
This commit is contained in:
@@ -15,7 +15,7 @@ export interface ContextMenuOptions<T> {
|
||||
}
|
||||
|
||||
interface MenuSeparatorItem {
|
||||
title: "----";
|
||||
kind: "separator";
|
||||
}
|
||||
|
||||
interface MenuHeader {
|
||||
@@ -161,7 +161,7 @@ class ContextMenu {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.title === "----") {
|
||||
if ("kind" in item && item.kind === "separator") {
|
||||
$parent.append($("<div>").addClass("dropdown-divider"));
|
||||
} else if ("kind" in item && item.kind === "header") {
|
||||
$parent.append($("<h6>").addClass("dropdown-header").text(item.title));
|
||||
|
||||
@@ -112,7 +112,7 @@ function setupContextMenu() {
|
||||
// Replace the placeholder with the real search keyword.
|
||||
let searchUrl = searchEngineUrl.replace("{keyword}", encodeURIComponent(params.selectionText));
|
||||
|
||||
items.push({ title: "----" });
|
||||
items.push({ kind: "separator" });
|
||||
|
||||
items.push({
|
||||
title: t("electron_context_menu.search_online", { term: shortenedSelection, searchEngine: searchEngineName }),
|
||||
|
||||
@@ -45,16 +45,16 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener<
|
||||
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-spacer"), command: "addSpacerLauncher", uiIcon: "bx bx-dots-horizontal" } : null,
|
||||
isVisibleRoot || isAvailableRoot ? { title: "----" } : null,
|
||||
isVisibleRoot || isAvailableRoot ? { kind: "separator" } : null,
|
||||
|
||||
isAvailableItem ? { title: t("launcher_context_menu.move-to-visible-launchers"), command: "moveLauncherToVisible", uiIcon: "bx bx-show", enabled: true } : null,
|
||||
isVisibleItem ? { title: t("launcher_context_menu.move-to-available-launchers"), command: "moveLauncherToAvailable", uiIcon: "bx bx-hide", enabled: true } : null,
|
||||
isVisibleItem || isAvailableItem ? { title: "----" } : null,
|
||||
isVisibleItem || isAvailableItem ? { kind: "separator" } : null,
|
||||
|
||||
{ title: `${t("launcher_context_menu.duplicate-launcher")}`, command: "duplicateSubtree", uiIcon: "bx bx-outline", enabled: isItem },
|
||||
{ title: `${t("launcher_context_menu.delete")}`, command: "deleteNotes", uiIcon: "bx bx-trash destructive-action-icon", enabled: canBeDeleted },
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{ title: t("launcher_context_menu.reset"), command: "resetLauncher", uiIcon: "bx bx-reset destructive-action-icon", enabled: canBeReset }
|
||||
];
|
||||
|
||||
@@ -93,7 +93,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
? null
|
||||
: { title: t("tree-context-menu.unhoist-note"), command: "toggleNoteHoisting", keyboardShortcut: "toggleNoteHoisting", uiIcon: "bx bx-door-open" },
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{
|
||||
title: t("tree-context-menu.insert-note-after"),
|
||||
@@ -115,13 +115,13 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
columns: 2
|
||||
},
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{ title: t("tree-context-menu.protect-subtree"), command: "protectSubtree", uiIcon: "bx bx-check-shield", enabled: noSelectedNotes },
|
||||
|
||||
{ title: t("tree-context-menu.unprotect-subtree"), command: "unprotectSubtree", uiIcon: "bx bx-shield", enabled: noSelectedNotes },
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{
|
||||
title: t("tree-context-menu.advanced"),
|
||||
@@ -130,7 +130,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
items: [
|
||||
{ title: t("tree-context-menu.apply-bulk-actions"), command: "openBulkActionsDialog", uiIcon: "bx bx-list-plus", enabled: true },
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{
|
||||
title: t("tree-context-menu.edit-branch-prefix"),
|
||||
@@ -141,7 +141,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
},
|
||||
{ title: t("tree-context-menu.convert-to-attachment"), command: "convertNoteToAttachment", uiIcon: "bx bx-paperclip", enabled: isNotRoot && !isHoisted && notOptionsOrHelp },
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{ title: t("tree-context-menu.expand-subtree"), command: "expandSubtree", keyboardShortcut: "expandSubtree", uiIcon: "bx bx-expand", enabled: noSelectedNotes },
|
||||
{ title: t("tree-context-menu.collapse-subtree"), command: "collapseSubtree", keyboardShortcut: "collapseSubtree", uiIcon: "bx bx-collapse", enabled: noSelectedNotes },
|
||||
@@ -153,14 +153,14 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
enabled: noSelectedNotes && notSearch
|
||||
},
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{ title: t("tree-context-menu.copy-note-path-to-clipboard"), command: "copyNotePathToClipboard", uiIcon: "bx bx-directions", enabled: true },
|
||||
{ title: t("tree-context-menu.recent-changes-in-subtree"), command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes && notOptionsOrHelp }
|
||||
]
|
||||
},
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{
|
||||
title: t("tree-context-menu.cut"),
|
||||
@@ -241,13 +241,13 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
enabled: isNotRoot && !isHoisted && parentNotSearch && notOptionsOrHelp
|
||||
},
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{ title: t("tree-context-menu.import-into-note"), command: "importIntoNote", uiIcon: "bx bx-import", enabled: notSearch && noSelectedNotes && notOptionsOrHelp },
|
||||
|
||||
{ title: t("tree-context-menu.export"), command: "exportNote", uiIcon: "bx bx-export", enabled: notSearch && noSelectedNotes && notOptionsOrHelp },
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{
|
||||
title: t("tree-context-menu.search-in-subtree"),
|
||||
|
||||
@@ -73,7 +73,7 @@ const BETA_BADGE = {
|
||||
title: t("note_types.beta-feature")
|
||||
};
|
||||
|
||||
const SEPARATOR = { title: "----" };
|
||||
const SEPARATOR = { kind: "separator" };
|
||||
|
||||
const creationDateCache = new Map<string, Date>();
|
||||
let rootCreationDate: Date | undefined;
|
||||
@@ -157,7 +157,7 @@ async function getBuiltInTemplates(title: string | null, command: TreeCommandNam
|
||||
const items: MenuItem<TreeCommandNames>[] = [];
|
||||
if (title) {
|
||||
items.push({
|
||||
title: "title",
|
||||
title: title,
|
||||
kind: "header"
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -41,7 +41,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
|
||||
y: event.pageY,
|
||||
items: [
|
||||
...link_context_menu.getItems(),
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("board_view.move-to"),
|
||||
uiIcon: "bx bx-transfer",
|
||||
@@ -52,7 +52,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
|
||||
})),
|
||||
},
|
||||
getArchiveMenuItem(note),
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("board_view.insert-above"),
|
||||
uiIcon: "bx bx-list-plus",
|
||||
@@ -63,7 +63,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
|
||||
uiIcon: "bx bx-empty",
|
||||
handler: () => api.insertRowAtPosition(column, branchId, "after")
|
||||
},
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("board_view.remove-from-board"),
|
||||
uiIcon: "bx bx-task-x",
|
||||
|
||||
@@ -10,14 +10,14 @@ import link from "../../../services/link.js";
|
||||
export default function openContextMenu(noteId: string, e: LeafletMouseEvent, isEditable: boolean) {
|
||||
let items: MenuItem<keyof CommandMappings>[] = [
|
||||
...buildGeoLocationItem(e),
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
...linkContextMenu.getItems(),
|
||||
];
|
||||
|
||||
if (isEditable) {
|
||||
items = [
|
||||
...items,
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{ title: t("geo-map-context.remove-from-map"), command: "deleteFromMap", uiIcon: "bx bx-trash" }
|
||||
];
|
||||
}
|
||||
@@ -46,7 +46,7 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent, isEdita
|
||||
if (isEditable) {
|
||||
items = [
|
||||
...items,
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("geo-map-context.add-note"),
|
||||
handler: () => createNewNote(noteId, e),
|
||||
|
||||
@@ -74,7 +74,7 @@ function showColumnContextMenu(parentComponent: Component, e: MouseEvent, column
|
||||
handler: () => tabulator.clearSort()
|
||||
},
|
||||
{
|
||||
title: "----"
|
||||
kind: "separator"
|
||||
},
|
||||
{
|
||||
title: t("table_view.hide-column", { title }),
|
||||
@@ -86,7 +86,7 @@ function showColumnContextMenu(parentComponent: Component, e: MouseEvent, column
|
||||
uiIcon: "bx bx-columns",
|
||||
items: buildColumnItems(tabulator)
|
||||
},
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("table_view.add-column-to-the-left"),
|
||||
uiIcon: "bx bx-horizontal-left",
|
||||
@@ -105,7 +105,7 @@ function showColumnContextMenu(parentComponent: Component, e: MouseEvent, column
|
||||
direction: "after"
|
||||
})
|
||||
},
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("table_view.edit-column"),
|
||||
uiIcon: "bx bxs-edit-alt",
|
||||
@@ -143,7 +143,7 @@ function showHeaderContextMenu(parentComponent: Component, e: MouseEvent, tabula
|
||||
uiIcon: "bx bx-columns",
|
||||
items: buildColumnItems(tabulator)
|
||||
},
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("table_view.new-column"),
|
||||
uiIcon: "bx bx-empty",
|
||||
@@ -174,7 +174,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
||||
contextMenu.show({
|
||||
items: [
|
||||
...link_context_menu.getItems(),
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("table_view.row-insert-above"),
|
||||
uiIcon: "bx bx-horizontal-left bx-rotate-90",
|
||||
@@ -214,7 +214,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
||||
}
|
||||
})
|
||||
},
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{
|
||||
title: t("table_context_menu.delete_row"),
|
||||
uiIcon: "bx bx-trash",
|
||||
|
||||
@@ -41,7 +41,7 @@ export default function NoteTypeChooserDialogComponent() {
|
||||
let index = -1;
|
||||
|
||||
setNoteTypes((noteTypes ?? []).map((item) => {
|
||||
if (item.title === "----") {
|
||||
if ("kind" in item && item.kind === "separator") {
|
||||
index++;
|
||||
return {
|
||||
title: SEPARATOR_TITLE_REPLACEMENTS[index],
|
||||
@@ -95,7 +95,7 @@ export default function NoteTypeChooserDialogComponent() {
|
||||
<FormGroup name="note-type" label={t("note_type_chooser.modal_body")}>
|
||||
<FormList onSelect={onNoteTypeSelected}>
|
||||
{noteTypes.map((_item) => {
|
||||
if (_item.title === "----") {
|
||||
if ("kind" in _item && _item.kind === "separator") {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export default function MobileDetailMenu() {
|
||||
items: [
|
||||
{ title: t("mobile_detail_menu.insert_child_note"), command: "insertChildNote", uiIcon: "bx bx-plus", enabled: note?.type !== "search" },
|
||||
{ title: t("mobile_detail_menu.delete_this_note"), command: "delete", uiIcon: "bx bx-trash", enabled: note?.noteId !== "root" },
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{ title: "Note revisions", command: "showRevisions", uiIcon: "bx bx-history" }
|
||||
],
|
||||
selectMenuItemHandler: async ({ command }) => {
|
||||
|
||||
@@ -387,7 +387,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
||||
items: [
|
||||
{ title: t("attribute_editor.add_new_label"), command: "addNewLabel", uiIcon: "bx bx-hash" },
|
||||
{ title: t("attribute_editor.add_new_relation"), command: "addNewRelation", uiIcon: "bx bx-transfer" },
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
{ title: t("attribute_editor.add_new_label_definition"), command: "addNewLabelDefinition", uiIcon: "bx bx-empty" },
|
||||
{ title: t("attribute_editor.add_new_relation_definition"), command: "addNewRelationDefinition", uiIcon: "bx bx-empty" }
|
||||
],
|
||||
|
||||
@@ -356,11 +356,11 @@ export default class TabRowWidget extends BasicWidget {
|
||||
{ title: t("tab_row.close_right_tabs"), command: "closeRightTabs", uiIcon: "bx bx-empty", enabled: appContext.tabManager.noteContexts?.at(-1)?.ntxId !== ntxId },
|
||||
{ title: t("tab_row.close_all_tabs"), command: "closeAllTabs", uiIcon: "bx bx-empty" },
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{ title: t("tab_row.reopen_last_tab"), command: "reopenLastTab", uiIcon: "bx bx-undo", enabled: appContext.tabManager.recentlyClosedTabs.length !== 0 },
|
||||
|
||||
{ title: "----" },
|
||||
{ kind: "separator" },
|
||||
|
||||
{ title: t("tab_row.move_tab_to_new_window"), command: "moveTabToNewWindow", uiIcon: "bx bx-window-open" },
|
||||
{ title: t("tab_row.copy_tab_to_new_window"), command: "copyTabToNewWindow", uiIcon: "bx bx-empty" }
|
||||
|
||||
Reference in New Issue
Block a user