Skip to content

Commit 6cab8f0

Browse files
wewoormumiao
authored andcommitted
feat: add onTabChange and onToolbarClick interfaces in panelService
re #45
1 parent 5330ece commit 6cab8f0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/controller/panel.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Controller } from 'mo/react/controller';
44
import { panelService } from 'mo/services';
55
import { singleton } from 'tsyringe';
66
import {
7+
PanelEvent,
78
PANEL_TOOLBOX_CLOSE,
89
PANEL_TOOLBOX_RESIZE,
910
} from 'mo/model/workbench/panel';
@@ -19,13 +20,14 @@ export class PanelController extends Controller implements IPanelController {
1920
super();
2021
}
2122

22-
public readonly onTabChange = (key: string): void => {
23+
public readonly onTabChange = (key: string | undefined): void => {
2324
const state = panelService.getState();
2425
if (key) {
2526
panelService.setState({
2627
current: state.data?.find((item) => item.id === key),
2728
});
2829
}
30+
this.emit(PanelEvent.onTabChange, key);
2931
};
3032

3133
public readonly onToolbarClick = (
@@ -37,5 +39,6 @@ export class PanelController extends Controller implements IPanelController {
3739
} else if (item.id === PANEL_TOOLBOX_RESIZE.id) {
3840
panelService.maximizeRestore();
3941
}
42+
this.emit(PanelEvent.onToolbarClick, e, item);
4043
};
4144
}

src/services/workbench/panelService.ts

+16
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { singleton, container } from 'tsyringe';
33
import {
44
IPanel,
55
IPanelItem,
6+
PanelEvent,
67
PanelModel,
78
PANEL_OUTPUT,
89
PANEL_PROBLEMS,
910
PANEL_TOOLBOX_RESIZE,
1011
} from 'mo/model/workbench/panel';
1112

1213
import { searchById } from '../helper';
14+
import { IActionBarItem } from 'mo/components/actionBar';
1315
export interface IPanelService extends Component<IPanel> {
1416
open(data: IPanelItem): void;
1517
getById(id: string): IPanelItem | undefined;
@@ -23,6 +25,10 @@ export interface IPanelService extends Component<IPanel> {
2325
clearProblems(): void;
2426
showHide(): void;
2527
maximizeRestore(): void;
28+
onTabChange(callback: (key: string) => void): void;
29+
onToolbarClick(
30+
callback: (e: React.MouseEvent, item: IActionBarItem) => void
31+
): void;
2632
}
2733

2834
@singleton()
@@ -138,4 +144,14 @@ export class PanelService extends Component<IPanel> implements IPanelService {
138144
}
139145
return undefined;
140146
}
147+
148+
public onTabChange(callback: (key: string) => void) {
149+
this.subscribe(PanelEvent.onTabChange, callback);
150+
}
151+
152+
public onToolbarClick(
153+
callback: (e: React.MouseEvent, item: IActionBarItem) => void
154+
) {
155+
this.subscribe(PanelEvent.onToolbarClick, callback);
156+
}
141157
}

0 commit comments

Comments
 (0)