-
Notifications
You must be signed in to change notification settings - Fork 120
/
problems.tsx
102 lines (91 loc) · 3.43 KB
/
problems.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
97
98
99
100
101
102
import 'reflect-metadata';
import React from 'react';
import { Float, IStatusBarItem } from 'mo/model';
import { Controller } from 'mo/react/controller';
import {
IPanelService,
PanelService,
IStatusBarService,
StatusBarService,
ILayoutService,
LayoutService,
ProblemsService,
IBuiltinService,
BuiltinService,
} from 'mo/services';
import { singleton, container } from 'tsyringe';
import { IMonacoService, MonacoService } from 'mo/monaco/monacoService';
import { QuickTogglePanelAction } from 'mo/monaco/quickTogglePanelAction';
import { ProblemsPaneView, ProblemsStatusBarView } from 'mo/workbench/problems';
import { connect } from 'mo/react';
export interface IProblemsController extends Partial<Controller> {
onClick?: (e: React.MouseEvent, item: IStatusBarItem) => void;
}
@singleton()
export class ProblemsController
extends Controller
implements IProblemsController {
private readonly panelService: IPanelService;
private readonly statusBarService: IStatusBarService;
private readonly layoutService: ILayoutService;
private readonly monacoService: IMonacoService;
private readonly problemsService: ProblemsService;
private readonly builtinService: IBuiltinService;
constructor() {
super();
this.panelService = container.resolve(PanelService);
this.statusBarService = container.resolve(StatusBarService);
this.monacoService = container.resolve(MonacoService);
this.layoutService = container.resolve(LayoutService);
this.problemsService = container.resolve(ProblemsService);
this.builtinService = container.resolve(BuiltinService);
}
private showHideProblems() {
const { panel } = this.layoutService.getState();
const { current } = this.panelService.getState();
const { builtInPanelProblems } = this.builtinService.getModules();
if (builtInPanelProblems) {
if (panel.hidden || current?.id === builtInPanelProblems.id) {
this.monacoService.commandService.executeCommand(
QuickTogglePanelAction.ID
);
}
this.panelService.open(builtInPanelProblems);
}
}
public onClick = (e: React.MouseEvent, item: IStatusBarItem) => {
this.showHideProblems();
};
public initView() {
const {
builtInStatusProblems: statusProblems,
builtInPanelProblems,
} = this.builtinService.getModules();
if (statusProblems) {
statusProblems.render = (item) => (
<ProblemsStatusBarView {...item} />
);
statusProblems.onClick = this.onClick;
this.statusBarService.add(statusProblems, Float.left);
}
if (builtInPanelProblems) {
// keep ProblemsPaneView updated to problems' state
const ProblemsView = connect(
this.problemsService,
ProblemsPaneView
);
const problemsPanel = builtInPanelProblems;
problemsPanel.renderPane = () => <ProblemsView />;
this.panelService.add(problemsPanel);
this.panelService.setActive(problemsPanel.id);
}
const {
PROBLEM_MODEL_ID,
PROBLEM_MODEL_NAME,
} = this.builtinService.getConstants();
this.problemsService.setState({
id: PROBLEM_MODEL_ID,
name: PROBLEM_MODEL_NAME,
});
}
}