Skip to content

Build your personal knowledge base with Trilium Notes

client/launchbar: add a context menu command to set the current layout

Adorian Doran5fe77d7de2ec
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index c96ab30dba..bde95ab9ff 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2264,7 +2264,9 @@
"search_now": "Search now"
},
"spacer": {
- "configure_launchbar": "Configure Launchbar"
+ "configure_launchbar": "Configure Launchbar",
+ "launcher_orientation": "Launcher bar orientation",
+ "will_reload_frontend": "(will reload frontend)"
},
"sql_result": {
"not_executed": "The query has not been executed yet.",
diff --git a/apps/client/src/widgets/launch_bar/SpacerWidget.tsx b/apps/client/src/widgets/launch_bar/SpacerWidget.tsx
index 437b980af6..c0bfbdb51c 100644
--- a/apps/client/src/widgets/launch_bar/SpacerWidget.tsx
+++ b/apps/client/src/widgets/launch_bar/SpacerWidget.tsx
@@ -1,8 +1,10 @@
import appContext, { CommandNames } from "../../components/app_context";
import FNote from "../../entities/fnote";
import { showLauncherContextMenu } from "../../menus/launcher_button_context_menu";
+import type { MenuItem } from "../../menus/context_menu";
import { t } from "../../services/i18n";
-import { isMobile } from "../../services/utils";
+import options from "../../services/options";
+import { isMobile, reloadFrontendApp } from "../../services/utils";
interface SpacerWidgetProps {
launcherNote?: FNote;
@@ -20,11 +22,7 @@ export default function SpacerWidget({ launcherNote, baseSize, growthFactor }: S
flexShrink: 1000
}}
onContextMenu={launcherNote ? (e) => showLauncherContextMenu<CommandNames>(launcherNote, e, {
- extraItems: [{
- title: t("spacer.configure_launchbar"),
- command: "showLaunchBarSubtree",
- uiIcon: "bx " + (isMobile() ? "bx-mobile" : "bx-sidebar")
- }],
+ extraItems: buildSpacerContextMenuItems(),
onCommand: (command) => {
if (command) appContext.triggerCommand(command);
}
@@ -32,3 +30,52 @@ export default function SpacerWidget({ launcherNote, baseSize, growthFactor }: S
/>
)
}
+
+function buildSpacerContextMenuItems(): MenuItem<CommandNames>[] {
+ const items: MenuItem<CommandNames>[] = [{
+ title: t("spacer.configure_launchbar"),
+ command: "showLaunchBarSubtree",
+ uiIcon: "bx " + (isMobile() ? "bx-mobile" : "bx-sidebar")
+ }];
+
+ // The layout orientation only applies to the desktop layout; the mobile layout is always horizontal.
+ if (!isMobile()) {
+ const orientation = options.get("layoutOrientation");
+ items.push({
+ title: t("spacer.launcher_orientation"),
+ uiIcon: "bx bx-layout",
+ items: [
+ {
+ // The unchecked item triggers a reload when picked, so hint that after its label.
+ title: orientationItemTitle(t("theme.layout-vertical-title"), orientation === "vertical"),
+ // `bx-empty` reserves the icon slot so unchecked items stay aligned with the checked one.
+ uiIcon: "bx bx-empty",
+ checked: orientation === "vertical",
+ handler: () => setLayoutOrientation("vertical")
+ },
+ {
+ title: orientationItemTitle(t("theme.layout-horizontal-title"), orientation === "horizontal"),
+ uiIcon: "bx bx-empty",
+ checked: orientation === "horizontal",
+ handler: () => setLayoutOrientation("horizontal")
+ }
+ ]
+ });
+ }
+
+ return items;
+}
+
+function orientationItemTitle(title: string, isCurrent: boolean) {
+ return isCurrent ? title : `${title} ${t("spacer.will_reload_frontend")}`;
+}
+
+async function setLayoutOrientation(orientation: "vertical" | "horizontal") {
+ if (options.get("layoutOrientation") === orientation) {
+ return;
+ }
+
+ await options.save("layoutOrientation", orientation);
+ // The layout tree and body classes are computed once at boot, so a reload is required to apply the change.
+ reloadFrontendApp(`layout orientation change: ${orientation}`);
+}