Skip to content

Build your personal knowledge base with Trilium Notes

feat(tree): set the clipboard actions and Delete side by side in one row

Elian Doranc5b0c12d1ef4
diff --git a/apps/client/src/menus/context_menu.ts b/apps/client/src/menus/context_menu.ts
index 887be4081f..6044bfebb4 100644
--- a/apps/client/src/menus/context_menu.ts
+++ b/apps/client/src/menus/context_menu.ts
@@ -34,6 +34,12 @@ export interface MenuHeader {
kind: "header";
}
+/** A row of items side by side, each drawn as its icon over its title. */
+export interface MenuActionRow<T> {
+ kind: "actions";
+ items: MenuCommandItem<T>[];
+}
+
export interface MenuItemBadge {
title: string;
className?: string;
@@ -82,7 +88,7 @@ export interface MenuCommandItem<T> {
filterable?: boolean;
}
-export type MenuItem<T> = MenuCommandItem<T> | CustomMenuItem | MenuSeparatorItem | MenuHeader;
+export type MenuItem<T> = MenuCommandItem<T> | CustomMenuItem | MenuSeparatorItem | MenuHeader | MenuActionRow<T>;
export type MenuHandler<T> = (item: MenuCommandItem<T>, e: MouseEvent | KeyboardEvent) => void;
export type ContextMenuEvent = PointerEvent | MouseEvent | JQuery.ContextMenuEvent;
diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.ts
index 82733c3bcb..fdb117fa48 100644
--- a/apps/client/src/menus/tree_context_menu.ts
+++ b/apps/client/src/menus/tree_context_menu.ts
@@ -141,6 +141,42 @@ export async function buildTreeContextMenuItems(ctx: TreeContextMenuContext): Pr
: null;
const items: (MenuItem<TreeCommandNames> | null)[] = [
+ {
+ kind: "actions",
+ items: [
+ {
+ title: t("tree-context-menu.cut"),
+ command: "cutNotesToClipboard",
+ keyboardShortcut: "cutNotesToClipboard",
+ uiIcon: "bx bx-cut",
+ enabled: isNotRoot && !isHoisted && parentNotSearch
+ },
+ { title: t("tree-context-menu.copy-clone"), command: "copyNotesToClipboard", keyboardShortcut: "copyNotesToClipboard", uiIcon: "bx bx-copy", enabled: isNotRoot && !isHoisted },
+ {
+ title: t("tree-context-menu.paste-into"),
+ command: "pasteNotesFromClipboard",
+ keyboardShortcut: "pasteNotesFromClipboard",
+ uiIcon: "bx bx-paste",
+ enabled: !clipboard.isClipboardEmpty() && notSearch && noSelectedNotes
+ },
+ {
+ title: t("tree-context-menu.paste-after"),
+ command: "pasteNotesAfterFromClipboard",
+ uiIcon: "bx bx-paste",
+ enabled: !clipboard.isClipboardEmpty() && isNotRoot && !isHoisted && parentNotSearch && noSelectedNotes
+ },
+ {
+ title: t("tree-context-menu.delete"),
+ command: "deleteNotes",
+ keyboardShortcut: "deleteNotes",
+ uiIcon: "bx bx-trash destructive-action-icon",
+ enabled: isNotRoot && !isHoisted && parentNotSearch && notOptionsOrHelp
+ }
+ ]
+ },
+
+ { kind: "separator" },
+
{ title: t("tree-context-menu.open-in-a-new-tab"), command: "openInTab", shortcut: "Ctrl+Click", uiIcon: "bx bx-link-external", enabled: noSelectedNotes },
{ title: t("tree-context-menu.open-in-a-new-split"), command: "openNoteInSplit", uiIcon: "bx bx-dock-right", enabled: noSelectedNotes },
{ title: t("tree-context-menu.open-in-a-new-window"), command: "openNoteInWindow", uiIcon: "bx bx-window-open", enabled: noSelectedNotes },
@@ -249,31 +285,6 @@ export async function buildTreeContextMenuItems(ctx: TreeContextMenuContext): Pr
{ kind: "separator" },
- {
- title: t("tree-context-menu.cut"),
- command: "cutNotesToClipboard",
- keyboardShortcut: "cutNotesToClipboard",
- uiIcon: "bx bx-cut",
- enabled: isNotRoot && !isHoisted && parentNotSearch
- },
-
- { title: t("tree-context-menu.copy-clone"), command: "copyNotesToClipboard", keyboardShortcut: "copyNotesToClipboard", uiIcon: "bx bx-copy", enabled: isNotRoot && !isHoisted },
-
- {
- title: t("tree-context-menu.paste-into"),
- command: "pasteNotesFromClipboard",
- keyboardShortcut: "pasteNotesFromClipboard",
- uiIcon: "bx bx-paste",
- enabled: !clipboard.isClipboardEmpty() && notSearch && noSelectedNotes
- },
-
- {
- title: t("tree-context-menu.paste-after"),
- command: "pasteNotesAfterFromClipboard",
- uiIcon: "bx bx-paste",
- enabled: !clipboard.isClipboardEmpty() && isNotRoot && !isHoisted && parentNotSearch && noSelectedNotes
- },
-
{
title: t("tree-context-menu.move-to"),
command: "moveNotesTo",
@@ -321,13 +332,6 @@ export async function buildTreeContextMenuItems(ctx: TreeContextMenuContext): Pr
}
}
},
- {
- title: t("tree-context-menu.delete"),
- command: "deleteNotes",
- keyboardShortcut: "deleteNotes",
- uiIcon: "bx bx-trash destructive-action-icon",
- enabled: isNotRoot && !isHoisted && parentNotSearch && notOptionsOrHelp
- },
{ kind: "separator" },
diff --git a/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx b/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx
index 3d435defae..128b0679b1 100644
--- a/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx
+++ b/apps/client/src/widgets/layout/NoteTypeSwitcher.tsx
@@ -137,7 +137,7 @@ const NOT_SWITCHED_TO = new Set<string>([ "text", "search" ]);
*/
export function toSwitcherItems(items: MenuItem<TreeCommandNames>[], noteId: string): MenuItem<unknown>[] {
return items.flatMap((item): MenuItem<unknown>[] => {
- if ("kind" in item) return [ item ];
+ if ("kind" in item) return item.kind === "actions" ? [] : [ item ];
const { command, handler, items: subItems, ...rest } = item;
if (subItems) return [ { ...rest, items: toSwitcherItems(subItems, noteId) } ];
if (handler) return [ { ...rest, handler: (_, e) => handler(item, e) } ];
diff --git a/apps/client/src/widgets/react/Menu.css b/apps/client/src/widgets/react/Menu.css
index 62a104b6cf..59fb135e86 100644
--- a/apps/client/src/widgets/react/Menu.css
+++ b/apps/client/src/widgets/react/Menu.css
@@ -251,3 +251,58 @@ body.desktop .dropdown-item.dropdown-submenu.submenu-open,
color: var(--muted-text-color);
font-size: 0.9em;
}
+
+.tn-menu-actions {
+ display: flex;
+ gap: 5px;
+ padding: 2px 4px;
+}
+
+.tn-menu-action {
+ position: relative;
+ display: flex;
+ flex: 1 1 0;
+ flex-direction: column;
+ align-items: center;
+ gap: 4px;
+ min-width: 0;
+ padding: 8px 4px 6px;
+ border: 0;
+ border-radius: 6px;
+ background: transparent;
+ color: var(--menu-text-color);
+ font-size: 0.85em;
+ line-height: 1.2;
+
+ &:hover:not(:disabled) {
+ color: var(--hover-item-text-color);
+ background-color: var(--hover-item-background-color);
+ }
+
+ &:disabled > * {
+ opacity: var(--menu-item-disabled-opacity);
+ }
+
+ & + &::before {
+ content: "";
+ position: absolute;
+ inset-block: 20%;
+ inset-inline-start: -3px;
+ width: 1px;
+ background: var(--menu-item-delimiter-color);
+ }
+
+ > .tn-icon {
+ color: var(--menu-item-icon-color);
+ font-size: 1.5em;
+ }
+
+ &:not(:disabled) > .destructive-action-icon {
+ color: var(--dropdown-item-icon-destructive-color);
+ }
+}
+
+.tn-menu-action-title {
+ max-width: 100%;
+ text-align: center;
+}
diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsx
index f1641d0a0c..0cb31f457d 100644
--- a/apps/client/src/widgets/react/Menu.tsx
+++ b/apps/client/src/widgets/react/Menu.tsx
@@ -511,6 +511,7 @@ function MenuItemRow<T>({ row, onSelect }: { row: MenuItem<T>, onSelect: MenuPro
if (row.kind === "separator") return <FormDropdownDivider />;
// Its title is text, as it can be a name the user wrote.
if (row.kind === "header") return <FormListHeader text={row.title} />;
+ if (row.kind === "actions") return <MenuActions items={row.items} onSelect={onSelect} />;
return <FormListCustomItem><row.componentFn /></FormListCustomItem>;
}
@@ -546,6 +547,24 @@ function MenuItemRow<T>({ row, onSelect }: { row: MenuItem<T>, onSelect: MenuPro
);
}
+/** A row of items side by side, each its icon over its title. */
+function MenuActions<T>({ items, onSelect }: { items: MenuCommandItem<T>[], onSelect: MenuProps<T>["onSelect"] }) {
+ return (
+ <li className="tn-menu-actions" role="group">
+ {items.map((item, index) => (
+ <button
+ key={index} type="button" role="menuitem" className="tn-menu-action"
+ disabled={item.enabled === false} onClick={(e) => onSelect?.(item, e)}
+ >
+ <span className={`tn-icon ${item.uiIcon ?? "bx bx-empty"}`} aria-hidden="true" />
+ {/* Callers pass HTML, as for a row's title. */}
+ <span className="tn-menu-action-title" dangerouslySetInnerHTML={{ __html: item.title }} />
+ </button>
+ ))}
+ </li>
+ );
+}
+
interface MenuMatch<T> {
item: MenuCommandItem<T>;
/** The title as text. */
@@ -566,7 +585,10 @@ function filterMenuItems<T>(items: MenuItem<T>[], text: string): MenuMatch<T>[]
function collect(level: MenuItem<T>[], path: string[]) {
for (const item of level) {
- if ("kind" in item) continue;
+ if ("kind" in item) {
+ if (item.kind === "actions") collect(item.items, path);
+ continue;
+ }
const title = textOf(item.title);
if (item.items) {
collect(item.items, [ ...path, title ]);