Files
likang 7e01147566
CI / typecheck + test + build (push) Has been cancelled
Initial commit: import VibeMake PCB Studio
2026-11-03 11:20:08 +08:00

151 lines
6.2 KiB
TypeScript

// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 ZiroEDA and contributors.
// Portions derived from KiCad, copyright The KiCad Developers. See NOTICE.md.
/**
* Drawing Sheet Editor toolbar layouts, following the layout that
* `pl_editor` defines in `toolbars_pl_editor.cpp`
* (PL_EDITOR_TOOLBAR_SETTINGS::DefaultToolbarConfig):
*
* - TOP: file group | print | undo/redo | zoom group | inspector +
* preview settings | title-block display-mode pair | origin and
* page choice controls (the combos render next to the buttons);
* - LEFT: grid toggle, then the units radio group;
* - RIGHT: selection tool | line / rect / text / image / append |
* interactive delete tool.
*/
import type { ToolbarDefaults } from '@ziroeda/common/tool/ui/toolbar_configuration.js';
import type { ToolEntry } from '@ziroeda/common/tool/action_toolbar_types.js';
const sep: ToolEntry = 'sep';
/** TOP main toolbar (button portion). */
export const DS_TOP_TOOLBAR: ToolEntry[] = [
{ id: 'new', icon: 'new', title: 'Create new drawing sheet' },
{ id: 'open', icon: 'open', title: 'Open drawing sheet' },
{ id: 'save', icon: 'save', title: 'Save drawing sheet' },
sep,
{ id: 'print', icon: 'print', title: 'Print' },
sep,
{ id: 'undo', icon: 'undo', title: 'Undo last edit' },
{ id: 'redo', icon: 'redo', title: 'Redo last edit' },
sep,
{ id: 'zoomRedraw', icon: 'zoomRedraw', title: 'Refresh' },
{ id: 'zoomIn', icon: 'zoomIn', title: 'Zoom in' },
{ id: 'zoomOut', icon: 'zoomOut', title: 'Zoom out' },
{ id: 'zoomFit', icon: 'zoomFit', title: 'Zoom to fit' },
// ACTIONS::zoomTool: TOGGLE ToolbarState, AF_ACTIVATE, and the tooltip is
// its own (actions.cpp:817-826) - a rubber-band area drag, not the
// selection. Always enabled: nothing needs to be selected.
{
id: 'zoomTool',
icon: 'zoomTool',
title: 'Zoom to an area selection created by a mouse drag',
toggle: true,
},
sep,
{ id: 'inspect', icon: 'inspect', title: 'Show design inspector' },
{
id: 'previewSettings',
icon: 'previewSettings',
title: 'Edit preview data for page size and title block',
},
sep,
{
id: 'layoutNormalMode',
icon: 'layoutNormalMode',
title: 'Text placeholders will be replaced with preview data',
toggle: true,
},
{
id: 'layoutEditMode',
icon: 'layoutEditMode',
title: 'Text placeholders are shown as ${keyword} tokens',
toggle: true,
},
sep,
// `AppendSeparator().AppendControl( originSelector ).AppendControl( pageSelect )`
// (`toolbars_pl_editor.cpp` TOP_MAIN, last block). Both are `aToolbar->Add(
// m_originSelectBox )` / `Add( m_pageSelectBox )` at :132 and :157 — controls
// ON the toolbar, exactly like gerbview's layer selector, with no second bar
// behind them. Ours had them in a `.ze-wks-topbar` wrapper that painted
// --chrome-bg, so the strip read as the menu-bar grey either side of a
// #373737 toolbar.
{ control: 'originSelector' },
{ control: 'pageSelect' },
];
/**
* LEFT options toolbar. `toolbars_pl_editor.cpp:48-59` is two entries and no
* separator between them:
*
* config.AppendAction( ACTIONS::toggleGrid )
* .WithContextMenu( ... ACTIONS::gridProperties ... )
* .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) )
* .AddAction( ACTIONS::millimetersUnits )
* .AddAction( ACTIONS::inchesUnits )
* .AddAction( ACTIONS::milsUnits ) );
*
* so the three units are ONE ACTION_GROUP button showing the active unit with
* a palette behind it - the same shape `pcbToolbars.ts` already uses for the
* identical group - not three buttons in a row.
*
* The grid button's `.WithContextMenu(...)` is deliberately NOT part of this
* inventory, exactly as it is not part of `TOOLBAR_CONFIGURATION` upstream: the
* factory is filed globally by action name so that a toolbar the user
* rearranged - reloaded from JSON, never running the C++ above - still gets the
* same menu. Ours lives in `ui/toolbar_context_menu_registry.ts`, and
* `ui/Toolbar.tsx` looks it up on right-click.
*/
export const DS_LEFT_TOOLBAR: ToolEntry[] = [
{ id: 'toggleGrid', icon: 'toggleGrid', title: 'Show grid', toggle: true },
{
group: 'Units',
cycleOnClick: true,
// NOT toggles. `ACTIONS::millimetersUnits` / `inchesUnits` / `milsUnits`
// declare `.Flags( AF_NONE )` and no `ToolbarState` (`actions.cpp:1113-1131`),
// so `AddGroup`'s `isToggleEntry` is false and the group item is
// wxITEM_NORMAL — it can never paint checked. A live pl_editor shows the
// grid toggle above it lit and this one flat, because `toggleGrid` DOES
// declare `TOOLBAR_STATE::TOGGLE`. The unit still decides which of the
// three icons the button shows; that is `doSelectAction`, not a check.
actions: [
{ id: 'unitsMm', icon: 'unitsMm', title: 'Units in millimetres' },
{ id: 'unitsInches', icon: 'unitsInches', title: 'Units in inches' },
{ id: 'unitsMils', icon: 'unitsMils', title: 'Units in mils' },
],
},
];
/** RIGHT drawing/placement toolbar (radio selection). */
export const DS_RIGHT_TOOLBAR: ToolEntry[] = [
{ id: 'select', icon: 'select', title: 'Select item(s)' },
sep,
{ id: 'dsAddLine', icon: 'dsAddLine', title: 'Draw lines' },
{ id: 'dsAddRect', icon: 'dsAddRect', title: 'Draw rectangles' },
{ id: 'dsAddText', icon: 'dsAddText', title: 'Draw text' },
{ id: 'dsAddBitmap', icon: 'dsAddBitmap', title: 'Place bitmaps' },
{
id: 'appendSheet',
icon: 'appendSheet',
title: 'Append an existing drawing sheet file to the current file',
},
sep,
{ id: 'dsDelete', icon: 'dsDelete', title: 'Delete items' },
];
/**
* `PL_EDITOR_TOOLBAR_SETTINGS::DefaultToolbarConfig`
* (`pagelayout_editor/toolbars_pl_editor.cpp:35-113`), keyed by `TOOLBAR_LOC`.
*
* The three lists above are the toolbars themselves; this is the switch that
* answers "which toolbar is which", and it is what both the frame and
* Preferences > Drawing Sheet Editor > Toolbars ask. `TOP_AUX` is absent
* because upstream's first case is `return std::nullopt` (`:42-43`).
*/
export const DS_DEFAULT_TOOLBARS: ToolbarDefaults = {
LEFT: DS_LEFT_TOOLBAR,
RIGHT: DS_RIGHT_TOOLBAR,
TOP_MAIN: DS_TOP_TOOLBAR,
};