refactor(toolbar): pass registry to all button factories
Toolbar component now receives registry from ButtonGroupManager options and passes it to all 16 toolbar button factory functions. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
|
export const createAiChatButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
|
|
||||||
export const createAiChatButton = (): ButtonConfig => {
|
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
|
|
||||||
registry.on('aiChat:opened', () => {
|
registry.on('aiChat:opened', () => {
|
||||||
registry.toolbar?.setBtnActive('aiChat', true);
|
registry.toolbar?.setBtnActive('aiChat', true);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createFullscreenButton = (): ButtonConfig => {
|
export const createFullscreenButton = (_registry?: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'fullscreen',
|
id: 'fullscreen',
|
||||||
groupId: 'group-2',
|
groupId: 'group-2',
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createHomeButton = (): ButtonConfig => {
|
export const createHomeButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'home',
|
id: 'home',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
@@ -12,7 +12,6 @@ export const createHomeButton = (): ButtonConfig => {
|
|||||||
keepActive: false,
|
keepActive: false,
|
||||||
onClick: (button) => {
|
onClick: (button) => {
|
||||||
console.log('首页按钮被点击:', button.id);
|
console.log('首页按钮被点击:', button.id);
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
registry.engine3d?.CameraGoHome();
|
registry.engine3d?.CameraGoHome();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
|
export const createInfoButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
|
|
||||||
export const createInfoButton = (): ButtonConfig => {
|
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'info',
|
id: 'info',
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
|
export const createMapButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
|
|
||||||
export const createMapButton = (): ButtonConfig => {
|
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'map',
|
id: 'map',
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createMeasureButton = (): ButtonConfig => {
|
export const createMeasureButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'measure',
|
id: 'measure',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
@@ -11,7 +11,6 @@ export const createMeasureButton = (): ButtonConfig => {
|
|||||||
icon: getIcon('测量'),
|
icon: getIcon('测量'),
|
||||||
keepActive: true,
|
keepActive: true,
|
||||||
onClick: (button) => {
|
onClick: (button) => {
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
if (button.isActive) {
|
if (button.isActive) {
|
||||||
registry.measure?.show();
|
registry.measure?.show();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createPropertyButton = (): ButtonConfig => {
|
export const createPropertyButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'property',
|
id: 'property',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
@@ -12,7 +12,6 @@ export const createPropertyButton = (): ButtonConfig => {
|
|||||||
icon: getIcon('文档'),
|
icon: getIcon('文档'),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
console.log('构件详情按钮被点击');
|
console.log('构件详情按钮被点击');
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
registry.componentDetail?.show();
|
registry.componentDetail?.show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../../index.type';
|
import type { ButtonConfig } from '../../../../index.type';
|
||||||
import { getIcon } from '../../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createSectionAxisButton = (): ButtonConfig => {
|
export const createSectionAxisButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'section-axis',
|
id: 'section-axis',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
@@ -14,7 +14,6 @@ export const createSectionAxisButton = (): ButtonConfig => {
|
|||||||
label: 'toolbar.sectionAxis',
|
label: 'toolbar.sectionAxis',
|
||||||
icon: getIcon('轴向剖切'),
|
icon: getIcon('轴向剖切'),
|
||||||
onClick: (button) => {
|
onClick: (button) => {
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
if (button.isActive) {
|
if (button.isActive) {
|
||||||
registry.sectionAxis?.show();
|
registry.sectionAxis?.show();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../../index.type';
|
import type { ButtonConfig } from '../../../../index.type';
|
||||||
import { getIcon } from '../../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createSectionBoxButton = (): ButtonConfig => {
|
export const createSectionBoxButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'section-box',
|
id: 'section-box',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
@@ -15,7 +15,6 @@ export const createSectionBoxButton = (): ButtonConfig => {
|
|||||||
icon: getIcon('剖切盒'),
|
icon: getIcon('剖切盒'),
|
||||||
onClick: (button) => {
|
onClick: (button) => {
|
||||||
console.log('剖切盒被点击:', button.id, '激活状态:', button.isActive);
|
console.log('剖切盒被点击:', button.id, '激活状态:', button.isActive);
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
if (button.isActive) {
|
if (button.isActive) {
|
||||||
registry.sectionBox?.show();
|
registry.sectionBox?.show();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../../index.type';
|
import type { ButtonConfig } from '../../../../index.type';
|
||||||
import { getIcon } from '../../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../../utils/icon-manager';
|
||||||
|
import type { ManagerRegistry } from '../../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createSectionMenuButton = (): ButtonConfig => {
|
export const createSectionMenuButton = (_registry?: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'section',
|
id: 'section',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../../index.type';
|
import type { ButtonConfig } from '../../../../index.type';
|
||||||
import { getIcon } from '../../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createSectionPlaneButton = (): ButtonConfig => {
|
export const createSectionPlaneButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'section-plane',
|
id: 'section-plane',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
@@ -15,7 +15,6 @@ export const createSectionPlaneButton = (): ButtonConfig => {
|
|||||||
icon: getIcon('拾曲面剖切'),
|
icon: getIcon('拾曲面剖切'),
|
||||||
onClick: (button) => {
|
onClick: (button) => {
|
||||||
console.log('拾取面剖切被点击:', button.id, '激活状态:', button.isActive);
|
console.log('拾取面剖切被点击:', button.id, '激活状态:', button.isActive);
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
if (button.isActive) {
|
if (button.isActive) {
|
||||||
registry.sectionPlane?.show();
|
registry.sectionPlane?.show();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createSettingButton = (): ButtonConfig => {
|
export const createSettingButton = (_registry?: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'setting',
|
id: 'setting',
|
||||||
groupId: 'group-2',
|
groupId: 'group-2',
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../../index.type';
|
import type { ButtonConfig } from '../../../../index.type';
|
||||||
import { getIcon } from '../../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../../utils/icon-manager';
|
||||||
|
import type { ManagerRegistry } from '../../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createWalkBirdButton = (): ButtonConfig => {
|
export const createWalkBirdButton = (_registry?: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'walk-bird',
|
id: 'walk-bird',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../../index.type';
|
import type { ButtonConfig } from '../../../../index.type';
|
||||||
import { getIcon } from '../../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createWalkMenuButton = (): ButtonConfig => {
|
export const createWalkMenuButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'walk',
|
id: 'walk',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
@@ -12,7 +12,6 @@ export const createWalkMenuButton = (): ButtonConfig => {
|
|||||||
icon: getIcon('漫游'),
|
icon: getIcon('漫游'),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
console.log('漫游按钮被点击');
|
console.log('漫游按钮被点击');
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
registry.walkControl?.show();
|
registry.walkControl?.show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../../index.type';
|
import type { ButtonConfig } from '../../../../index.type';
|
||||||
import { getIcon } from '../../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../../utils/icon-manager';
|
||||||
|
import type { ManagerRegistry } from '../../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createWalkPersonButton = (): ButtonConfig => {
|
export const createWalkPersonButton = (_registry?: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'walk-person',
|
id: 'walk-person',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { ButtonConfig } from '../../../index.type';
|
import type { ButtonConfig } from '../../../index.type';
|
||||||
import { getIcon } from '../../../../../utils/icon-manager';
|
import { getIcon } from '../../../../../utils/icon-manager';
|
||||||
import { ManagerRegistry } from '../../../../../core/manager-registry';
|
import type { ManagerRegistry } from '../../../../../core/manager-registry';
|
||||||
|
|
||||||
export const createZoomBoxButton = (): ButtonConfig => {
|
export const createZoomBoxButton = (registry: ManagerRegistry): ButtonConfig => {
|
||||||
return {
|
return {
|
||||||
id: 'zoom-box',
|
id: 'zoom-box',
|
||||||
groupId: 'group-1',
|
groupId: 'group-1',
|
||||||
@@ -11,7 +11,6 @@ export const createZoomBoxButton = (): ButtonConfig => {
|
|||||||
label: 'toolbar.zoomBox',
|
label: 'toolbar.zoomBox',
|
||||||
icon: getIcon('框选放大'),
|
icon: getIcon('框选放大'),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
const registry = ManagerRegistry.getInstance();
|
|
||||||
registry.engine3d?.activateZoomBox();
|
registry.engine3d?.activateZoomBox();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import { BimButtonGroup } from '../index';
|
import { BimButtonGroup } from '../index';
|
||||||
|
import type { ManagerRegistry } from '../../../core/manager-registry';
|
||||||
|
|
||||||
export class Toolbar extends BimButtonGroup {
|
export class Toolbar extends BimButtonGroup {
|
||||||
public async init(): Promise<void> {
|
public async init(): Promise<void> {
|
||||||
await super.init();
|
await super.init();
|
||||||
|
|
||||||
|
const registry = this.options.registry as ManagerRegistry;
|
||||||
|
|
||||||
const { createHomeButton } = await import('./buttons/home');
|
const { createHomeButton } = await import('./buttons/home');
|
||||||
const { createZoomBoxButton } = await import('./buttons/zoom-box');
|
const { createZoomBoxButton } = await import('./buttons/zoom-box');
|
||||||
const { createWalkMenuButton } = await import('./buttons/walk/walk-menu');
|
const { createWalkMenuButton } = await import('./buttons/walk/walk-menu');
|
||||||
@@ -21,21 +24,21 @@ export class Toolbar extends BimButtonGroup {
|
|||||||
|
|
||||||
this.addGroup('group-1');
|
this.addGroup('group-1');
|
||||||
|
|
||||||
this.addButton(createHomeButton());
|
this.addButton(createHomeButton(registry));
|
||||||
this.addButton(createZoomBoxButton());
|
this.addButton(createZoomBoxButton(registry));
|
||||||
this.addButton(createMeasureButton());
|
this.addButton(createMeasureButton(registry));
|
||||||
this.addButton(createSectionMenuButton());
|
this.addButton(createSectionMenuButton(registry));
|
||||||
this.addButton(createSectionPlaneButton());
|
this.addButton(createSectionPlaneButton(registry));
|
||||||
this.addButton(createSectionAxisButton());
|
this.addButton(createSectionAxisButton(registry));
|
||||||
this.addButton(createSectionBoxButton());
|
this.addButton(createSectionBoxButton(registry));
|
||||||
this.addButton(createWalkMenuButton());
|
this.addButton(createWalkMenuButton(registry));
|
||||||
this.addButton(createMapButton());
|
this.addButton(createMapButton(registry));
|
||||||
this.addButton(createPropertyButton());
|
this.addButton(createPropertyButton(registry));
|
||||||
this.addGroup('group-2');
|
this.addGroup('group-2');
|
||||||
this.addButton(createAiChatButton());
|
this.addButton(createAiChatButton(registry));
|
||||||
this.addButton(createSettingButton());
|
this.addButton(createSettingButton(registry));
|
||||||
this.addButton(createInfoButton());
|
this.addButton(createInfoButton(registry));
|
||||||
this.addButton(createFullscreenButton());
|
this.addButton(createFullscreenButton(registry));
|
||||||
|
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user