Add Tools/Help menus and preferences dialog

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-11-13 17:00:08 +08:00
parent 4efeadbee3
commit cbd2690993
7 changed files with 126 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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<WebPreferences>(loadWebPreferences);
useEffect(() => { localStorage.setItem(KEY, JSON.stringify(preferences)); }, [preferences]);
const update = <K extends keyof WebPreferences>(key: K, value: WebPreferences[K]) =>
setPreferences(previous => ({ ...previous, [key]: value }));
return <div className="web-preferences" role="dialog" aria-label="Preferences">
<style>{`
.web-preferences{position:fixed;inset:0;background:#000b;z-index:85;display:flex;align-items:center;justify-content:center;padding:20px}
.web-preferences>section{width:min(720px,94vw);max-height:86vh;overflow:auto;background:#17212b;border:1px solid #3f3f3f;border-radius:8px;color:#dbe6ee;font:13px/1.6 system-ui,"Noto Sans SC",sans-serif}
.web-preferences header{display:flex;align-items:center;padding:10px 14px;background:#1b242c;border-bottom:1px solid #3f3f3f}
.web-preferences header strong{font-size:14px}
.web-preferences header button{margin-left:auto;background:#2b2b2b;color:#dbe6ee;border:1px solid #555;border-radius:4px;padding:3px 10px;cursor:pointer}
.web-preferences .body{padding:14px}
.web-preferences label{display:grid;grid-template-columns:200px 1fr;gap:10px;align-items:center;margin:8px 0}
.web-preferences select,.web-preferences input[type=checkbox]{justify-self:start}
.web-preferences select{background:#0b1014;color:#dbe6ee;border:1px solid #3f3f3f;border-radius:4px;padding:4px 8px;min-width:260px}
.web-preferences .note{color:#93a6b3;font-size:12px;margin-top:12px}
`}</style>
<section>
<header><strong>Preferences · Web FreeCAD</strong><button type="button" aria-label="Close preferences" onClick={onClose}>关闭</button></header>
<div className="body">
<label>Unit system
<select aria-label="Unit system" value={preferences.unitSystem}
onChange={event => update("unitSystem", event.target.value)}>
<option>Standard (mm, kg, s, °)</option>
<option>MKS (m, kg, s, °)</option>
<option>Imperial decimal (in, lb)</option>
<option>Building US (ft-in, lb)</option>
<option>Building cm (cm, kg)</option>
</select>
</label>
<label>Navigation style
<select aria-label="Navigation style" value={preferences.navigationStyle}
onChange={event => update("navigationStyle", event.target.value)}>
<option>CAD</option><option>Blender</option><option>OpenInventor</option>
<option>Revit</option><option>Touchpad</option>
</select>
</label>
<label>Theme
<select aria-label="Theme" value={preferences.theme}
onChange={event => update("theme", event.target.value)}>
<option>FreeCAD Dark</option><option>FreeCAD Light</option><option>FreeCAD Classic</option>
</select>
</label>
<label>Show grid
<input type="checkbox" aria-label="Show grid" checked={preferences.showGrid}
onChange={event => update("showGrid", event.target.checked)} />
</label>
<p className="note">设置保存到浏览器 localStorage;原生参数(BaseApp/Preferences)接线在 P3 完成。</p>
</div>
</section>
</div>;
}

View File

@@ -0,0 +1,31 @@
import React, { useState } from "react";
export function UtilityMenus({ onPreferences }: { onPreferences: () => void }) {
const [open, setOpen] = useState("");
return <div className="utility-menus">
<style>{`
.utility-menus{display:inline-flex;align-items:stretch;gap:2px;position:relative}
.utility-menus>button{background:transparent;border:0;color:#dbe6ee;padding:5px 10px;cursor:pointer;border-radius:3px;font:13px system-ui,"Noto Sans SC",sans-serif}
.utility-menus>button:hover,.utility-menus>button[aria-expanded=true]{background:#3d4a52}
.utility-menus .dropdown{position:absolute;top:100%;left:0;min-width:220px;background:#0f1419;border:1px solid #3f3f3f;box-shadow:0 12px 32px #0009;padding:5px;z-index:45;border-radius:0 0 6px 6px}
.utility-menus .dropdown button,.utility-menus .dropdown a{display:block;width:100%;text-align:left;background:transparent;border:0;color:#dbe6ee;padding:4px 8px;border-radius:3px;font-size:12.5px;cursor:pointer;text-decoration:none}
.utility-menus .dropdown button:hover,.utility-menus .dropdown a:hover{background:#29444b}
.utility-menus .dropdown span{display:block;padding:3px 8px;color:#6f8390;font-size:11px}
`}</style>
<button type="button" aria-expanded={open === "Tools"}
onClick={() => setOpen(previous => previous === "Tools" ? "" : "Tools")}>Tools
{open === "Tools" && <div className="dropdown" role="menu" aria-label="Tools">
<button type="button" onClick={() => { setOpen(""); onPreferences(); }}>Preferences…</button>
<a href="/help.html" target="_blank" rel="noopener">Help / documentation</a>
<span>Customize / Units calculator: P3</span>
</div>}
</button>
<button type="button" aria-expanded={open === "Help"}
onClick={() => setOpen(previous => previous === "Help" ? "" : "Help")}>Help
{open === "Help" && <div className="dropdown" role="menu" aria-label="Help">
<button type="button" onClick={() => { setOpen(""); window.alert("FreeCAD 1.2 Web · desktop parity shell"); }}>About FreeCAD</button>
<a href="/help.html" target="_blank" rel="noopener">Online Help</a>
</div>}
</button>
</div>;
}