-
Notifications
You must be signed in to change notification settings - Fork 120
/
panel.tsx
96 lines (87 loc) · 3.16 KB
/
panel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import 'reflect-metadata';
import { container, singleton } from 'tsyringe';
import React from 'react';
import { IActionBarItemProps } from 'mo/components/actionBar';
import { Controller } from 'mo/react/controller';
import { PanelEvent } from 'mo/model/workbench/panel';
import {
BuiltinService,
IBuiltinService,
IPanelService,
PanelService,
} from 'mo/services';
import { IMonacoService, MonacoService } from 'mo/monaco/monacoService';
import { QuickTogglePanelAction } from 'mo/monaco/quickTogglePanelAction';
import Output from 'mo/workbench/panel/output';
import type { UniqueId } from 'mo/common/types';
export interface IPanelController extends Partial<Controller> {
onTabChange?(key: UniqueId): void;
onToolbarClick?(e: React.MouseEvent, item: IActionBarItemProps): void;
onClose?(key: UniqueId): void;
}
@singleton()
export class PanelController extends Controller implements IPanelController {
private readonly panelService: IPanelService;
private readonly monacoService: IMonacoService;
private readonly builtinService: IBuiltinService;
constructor() {
super();
this.panelService = container.resolve(PanelService);
this.monacoService = container.resolve(MonacoService);
this.builtinService = container.resolve(BuiltinService);
}
public initView() {
const {
builtInOutputPanel,
builtInPanelToolbox,
builtInPanelToolboxResize,
} = this.builtinService.getModules();
if (builtInOutputPanel) {
const output = builtInOutputPanel;
output.renderPane = (item) => (
<Output
onUpdateEditorIns={(instance) => {
// Please notice the problem about memory out
// 'Cause we didn't dispose the older instance
item.outputEditorInstance = instance;
}}
{...item}
/>
);
this.panelService.add(output);
this.panelService.setActive(output.id);
}
const toolbox = [builtInPanelToolboxResize, builtInPanelToolbox].filter(
Boolean
) as IActionBarItemProps[];
this.panelService.setState({
toolbox,
});
}
public readonly onTabChange = (key: UniqueId): void => {
if (key) {
this.panelService.setActive(key);
}
this.emit(PanelEvent.onTabChange, key);
};
public readonly onClose = (key: UniqueId) => {
if (key) {
this.emit(PanelEvent.onTabClose, key);
}
};
public readonly onToolbarClick = (
e: React.MouseEvent,
item: IActionBarItemProps
): void => {
const { PANEL_TOOLBOX_CLOSE, PANEL_TOOLBOX_RESIZE } =
this.builtinService.getConstants();
if (item.id === PANEL_TOOLBOX_CLOSE) {
this.monacoService.commandService.executeCommand(
QuickTogglePanelAction.ID
);
} else if (item.id === PANEL_TOOLBOX_RESIZE) {
this.panelService.toggleMaximize();
}
this.emit(PanelEvent.onToolbarClick, e, item);
};
}