diff --git a/web/docs/current/desktop-parity-continuation.md b/web/docs/current/desktop-parity-continuation.md index f93e089d..245d4574 100644 --- a/web/docs/current/desktop-parity-continuation.md +++ b/web/docs/current/desktop-parity-continuation.md @@ -48,7 +48,11 @@ - **非 Part 工具栏已接入**:`web/src/shell/workbench-toolbars.tsx` + `toolbar.tsx` 渲染 manifest 工具栏并复用 TaskFrame 回调。 BIM 实测 8 组工具栏 / 73 个按钮,0 pageError、0 溢出; - 截图 `BIM-toolbars.png`。命令标签部分仍是原始 ID(缺元数据),后续补。 + 截图 `BIM-toolbars.png`。命令标签已做人类化回退(`BIM_TogglePanels` → Toggle Panels)。 +- **Tools/Help 菜单与偏好对话框**:`shell/utility-menus.tsx` + + `shell/preferences-dialog.tsx`。Preferences 支持单位制、导航风格、主题、网格, + 写入 `localStorage`;截图 `preferences-dialog.png`;0 pageError。 +- 说明:偏好尚未写入原生 `BaseApp/Preferences`;单位/主题还未影响内核与视口。 - 非 Part 菜单命令改为打开 **React TaskFrame 模态**(`web/src/shell/task-frame.tsx`), iframe 复用 `/workbench.html?module=&command=` 的现有任务面板; BIM_TogglePanels 实测弹出 "Bottom panels" 任务并可点按钮,0 pageError; diff --git a/web/docs/current/desktop-parity-evidence/BIM-toolbars.png b/web/docs/current/desktop-parity-evidence/BIM-toolbars.png index e78dbbbc..c4864e71 100644 Binary files a/web/docs/current/desktop-parity-evidence/BIM-toolbars.png and b/web/docs/current/desktop-parity-evidence/BIM-toolbars.png differ diff --git a/web/docs/current/desktop-parity-evidence/preferences-dialog.png b/web/docs/current/desktop-parity-evidence/preferences-dialog.png new file mode 100644 index 00000000..981c1d32 Binary files /dev/null and b/web/docs/current/desktop-parity-evidence/preferences-dialog.png differ diff --git a/web/src/project-shell.tsx b/web/src/project-shell.tsx index 79f42a13..7b455c8c 100644 --- a/web/src/project-shell.tsx +++ b/web/src/project-shell.tsx @@ -85,6 +85,8 @@ import { PartDesignWorkspace } from "./partdesign-workspace-component.js"; import { ParityWorkbenchMenu } from "./shell/workbench-menu.js"; import { TaskFrame } from "./shell/task-frame.js"; import { ParityWorkbenchToolbars } from "./shell/workbench-toolbars.js"; +import { UtilityMenus } from "./shell/utility-menus.js"; +import { PreferencesDialog } from "./shell/preferences-dialog.js"; import { DocumentTree, type DocumentTreeNode } from "./document-tree.js"; import { PARTDESIGN_DOCUMENT_COMMAND, PARTDESIGN_DOCUMENT_SCHEMA, type DesignAction, type DesignPayload, type DesignResult } from "./partdesign-document-facade.js"; @@ -314,6 +316,7 @@ function App() { const [workbenches, setWorkbenches] = useState>(() => initialWorkbench ? { [initialDocumentId]: initialWorkbench } : {}); const workbench = workbenches[active] ?? "Part"; const [parityTask, setParityTask] = useState<{ module: string; command: string } | null>(null); + const [preferencesOpen, setPreferencesOpen] = useState(false); const [selectedSheets, setSelectedSheets] = useState>({}); const [csvPanel, setCsvPanel] = useState<{ id: string; mode: "import" | "export"; selected?: string; done(result: Record): void } | null>(null); const [sheetRanges, setSheetRanges] = useState>({}); @@ -1902,6 +1905,7 @@ function App() { {workbench === "Part" && } + setPreferencesOpen(true)} /> {workbench === "Part" && } {workbench !== "Part" && void executeManifestCommand(command)} />} @@ -3128,6 +3132,7 @@ function App() { {referenceOpen && setReferenceOpen(false)} />} {parityTask && setParityTask(null)} />} + {preferencesOpen && setPreferencesOpen(false)} />} {lineReferenceOpen && setLineReferenceOpen(false)} />}

{status}

; } diff --git a/web/src/shell/command-registry.ts b/web/src/shell/command-registry.ts index 790885bd..56631d65 100644 --- a/web/src/shell/command-registry.ts +++ b/web/src/shell/command-registry.ts @@ -47,8 +47,14 @@ export function workbenchById(manifest: DesktopManifest, id: string): DesktopWor return manifest.workbenches.find(item => item.id === id); } +const humanize = (command: string) => { + const stripped = command.replace(/^[A-Za-z0-9]+_/, "").replace(/_/g, " "); + const spaced = stripped.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim(); + return spaced || command; +}; + export function commandLabel(manifest: DesktopManifest, command: string): string { - return manifest.commandMetadata[command]?.menuText?.trim() || command; + return manifest.commandMetadata[command]?.menuText?.trim() || humanize(command); } export function commandTooltip(manifest: DesktopManifest, command: string): string { diff --git a/web/src/shell/preferences-dialog.tsx b/web/src/shell/preferences-dialog.tsx new file mode 100644 index 00000000..b2cb06b8 --- /dev/null +++ b/web/src/shell/preferences-dialog.tsx @@ -0,0 +1,78 @@ +import React, { useEffect, useState } from "react"; + +export type WebPreferences = { + unitSystem: string; + navigationStyle: string; + theme: string; + showGrid: boolean; +}; + +const KEY = "freecad-web-preferences-v1"; +const DEFAULTS: WebPreferences = { + unitSystem: "Standard (mm, kg, s, °)", + navigationStyle: "CAD", + theme: "FreeCAD Dark", + showGrid: true, +}; + +export const loadWebPreferences = (): WebPreferences => { + try { + return { ...DEFAULTS, ...JSON.parse(localStorage.getItem(KEY) || "{}") }; + } catch { + return DEFAULTS; + } +}; + +export function PreferencesDialog({ onClose }: { onClose: () => void }) { + const [preferences, setPreferences] = useState(loadWebPreferences); + useEffect(() => { localStorage.setItem(KEY, JSON.stringify(preferences)); }, [preferences]); + const update = (key: K, value: WebPreferences[K]) => + setPreferences(previous => ({ ...previous, [key]: value })); + return
+ +
+
Preferences · Web FreeCAD
+
+ + + + +

设置保存到浏览器 localStorage;原生参数(BaseApp/Preferences)接线在 P3 完成。

+
+
+
; +} diff --git a/web/src/shell/utility-menus.tsx b/web/src/shell/utility-menus.tsx new file mode 100644 index 00000000..6c56c1ef --- /dev/null +++ b/web/src/shell/utility-menus.tsx @@ -0,0 +1,31 @@ +import React, { useState } from "react"; + +export function UtilityMenus({ onPreferences }: { onPreferences: () => void }) { + const [open, setOpen] = useState(""); + return
+ + + Help / documentation + Customize / Units calculator: P3 +
} + + + Online Help + } + + ; +}