Wire manifest workbench menus into project shell

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-11-13 16:15:31 +08:00
parent 70a6c17165
commit 26c8a104cd
8 changed files with 1410 additions and 724 deletions

View File

@@ -82,6 +82,7 @@ import { readImportExportSettings } from "./import-export-preferences.js";
import { RecoveryController } from "./recovery-controller.js";
import { mountQueueRecoveryPanel } from "./queue-recovery-panel.js";
import { PartDesignWorkspace } from "./partdesign-workspace-component.js";
import { ParityWorkbenchMenu } from "./shell/workbench-menu.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";
@@ -1893,6 +1894,8 @@ function App() {
<label><input type="checkbox" checked={developerMode} onChange={event => setDeveloperMode(event.target.checked)} />Developer mode</label>
</div></details>
{workbench === "Part" && <PartWorkbenchMenu disabled={partActionDisabled} activate={activatePartAction} currentTask={workspaceTask} />}
{workbench !== "Part" && <ParityWorkbenchMenu workbench={workbench}
onCommand={command => setStatus(`${command}: selected (desktop menu; execution wiring pending)`)} />}
{workbench !== "Part" && <WorkbenchParityMenu workbench={workbench} />}
</nav>
<PersistentToolbarWorkspace router={router} documentId={nativeName(active || initialDocumentId)} workbench={workbench}>
@@ -1935,7 +1938,7 @@ function App() {
}
setWorkspaceTask(""); setViewCommand(""); setWorkbenches(previous => ({ ...previous, [active]: next }));
void startParameters(router, { LastModule: `${next}Workbench` }, true).catch(error => setStatus(String(error)));
}}><option>Part</option><option>Sketcher</option><option>PartDesign</option><option>Spreadsheet</option><option>Surface</option><option>Assembly</option><option>Draft</option><option>Architecture</option><option disabled={!nativeDocuments.current.has(active)}>TemplatePyMod</option></select></label>
}}><option>Part</option><option>Sketcher</option><option>PartDesign</option><option>Spreadsheet</option><option>Surface</option><option>Assembly</option><option>Draft</option><option>Architecture</option><option>BIM</option><option>CAM</option><option>Cloud</option><option>Fem</option><option>Help</option><option>Import</option><option>Inspection</option><option>JtReader</option><option>Material</option><option>Measure</option><option>Mesh</option><option>MeshPart</option><option>OpenSCAD</option><option>Points</option><option>ReverseEngineering</option><option>Robot</option><option>Sandbox</option><option>Start</option><option>TechDraw</option><option>Test</option><option>Tux</option><option disabled={!nativeDocuments.current.has(active)}>TemplatePyMod</option></select></label>
</ToolbarGroup>
{csvPanel && <SpreadsheetCsvPanel mode={csvPanel.mode} selected={csvPanel.selected}
sheets={Object.values(store.list().find(document => document.id === csvPanel.id)?.objects ?? {}).filter(object => object.type === "Spreadsheet::Sheet").map(object => ({ name: String(object.properties.NativeName), label: String(object.properties.Label) }))}

View File

@@ -0,0 +1,67 @@
import React, { useEffect, useState } from "react";
import { commandLabel, commandTooltip, loadDesktopManifest, workbenchById,
type DesktopManifest, type DesktopMenuItem, type DesktopWorkbench } from "./command-registry.js";
function Items({ items, manifest, onCommand }: {
items: DesktopMenuItem[];
manifest: DesktopManifest;
onCommand: (id: string) => void;
}) {
return <div className="parity-menu-items">
{items.map((item, index) => {
if (item.type === "separator") return <hr key={`sep-${index}`} />;
if (item.type === "submenu") return <details key={`sub-${index}`}>
<summary>{item.label}</summary>
<Items items={item.items ?? []} manifest={manifest} onCommand={onCommand} />
</details>;
if (!item.id) return null;
return <button key={item.id} type="button" title={commandTooltip(manifest, item.id)}
onClick={() => onCommand(item.id!)}>
<span>{commandLabel(manifest, item.id)}</span>
{manifest.commandMetadata[item.id]?.accel ? <kbd>{manifest.commandMetadata[item.id].accel}</kbd> : null}
</button>;
})}
</div>;
}
export function ParityWorkbenchMenu({ workbench, onCommand }: {
workbench: string;
onCommand: (id: string) => void;
}) {
const [manifest, setManifest] = useState<DesktopManifest | null>(null);
const [desktop, setDesktop] = useState<DesktopWorkbench | null>(null);
const [open, setOpen] = useState(false);
useEffect(() => {
if (workbench === "Part") return;
let cancelled = false;
loadDesktopManifest().then(data => {
if (cancelled) return;
setManifest(data);
setDesktop(workbenchById(data, workbench) ?? null);
}).catch(() => { if (!cancelled) setDesktop(null); });
return () => { cancelled = true; };
}, [workbench]);
useEffect(() => setOpen(false), [workbench]);
if (workbench === "Part" || !manifest || !desktop) return null;
return <details className="parity-workbench-menu" open={open}>
<style>{`
.parity-workbench-menu{position:relative;display:inline-block}
.parity-workbench-menu>summary{list-style:none;cursor:pointer;padding:4px 10px;border-radius:3px;color:#dbe6ee}
.parity-workbench-menu>summary::-webkit-details-marker{display:none}
.parity-workbench-menu[open]>summary,.parity-workbench-menu>summary:hover{background:#3d4a52}
.parity-workbench-menu .parity-menu-items{position:absolute;top:100%;left:0;min-width:280px;max-height:72vh;overflow:auto;background:#0f1419;border:1px solid #3f3f3f;box-shadow:0 12px 32px #0009;padding:6px;z-index:40;border-radius:0 0 6px 6px}
.parity-menu-items>button{display:flex;width:100%;justify-content:space-between;gap:16px;background:transparent;border:0;color:#dbe6ee;padding:3px 7px;text-align:left;border-radius:3px;font-size:12.5px;cursor:pointer}
.parity-menu-items>button:hover{background:#29444b}
.parity-menu-items kbd{color:#93a6b3;font-size:11px}
.parity-menu-items summary{cursor:pointer;padding:3px 7px;border-radius:3px;font-size:12.5px}
.parity-menu-items summary:hover{background:#22313b}
.parity-menu-items details .parity-menu-items{padding-left:12px;border-left:1px solid #2a3a45;margin-left:8px}
.parity-menu-items hr{border:0;border-top:1px solid #2a3a45;margin:4px 0}
`}</style>
<summary aria-label={`${workbench} menu`} onClick={event => { event.preventDefault(); setOpen(value => !value); }}>
{workbench}
</summary>
<Items items={desktop.menus.map(menu => ({ type: "submenu" as const, label: menu.label, items: menu.items }))}
manifest={manifest} onCommand={id => { setOpen(false); onCommand(id); }} />
</details>;
}