Skip to content

Commit a15245f

Browse files
authored
feat: extract layoutService (#176)
* feat: extract size or direction maximized etc property for controll free layout * ci: fix ci error * feat: add getContainer interface for layoutService * ci: fix type check error * fix: remove unless showhide method * fix: optimize getContainer returnType definition * feat: add onChange ts typeDefinition for react-split-pane library * feat: add getSideBarPosition and setSideBarPosition interface for Layout * fix: monacoService rely on layoutService to getWorkbenchContainer * fix: delete unless code * fix: abstract and cache workbenchContainer * fix: fix ci static check * fix: initial workbenchConatiner on Molecule container didMount * fix: initial workbenchConatiner on Molecule container didMount
1 parent 098c78c commit a15245f

28 files changed

+337
-198
lines changed

src/controller/activityBar.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import 'reflect-metadata';
2+
import { Controller } from 'mo/react/controller';
3+
import { container, singleton } from 'tsyringe';
4+
import { MenuBarController, IMenuBarController } from 'mo/controller';
25
import { IMenuItemProps } from 'mo/components/menu';
36
import {
47
ActivityBarEvent,
@@ -11,15 +14,11 @@ import {
1114
CONTEXT_MENU_SETTINGS,
1215
IActivityBarItem,
1316
} from 'mo/model';
14-
import { Controller } from 'mo/react/controller';
15-
import { container, singleton } from 'tsyringe';
1617
import { SelectColorThemeAction } from 'mo/monaco/selectColorThemeAction';
1718

1819
import {
1920
ActivityBarService,
20-
MenuBarService,
2121
IActivityBarService,
22-
IMenuBarService,
2322
ISettingsService,
2423
SettingsService,
2524
} from 'mo/services';
@@ -39,16 +38,16 @@ export class ActivityBarController
3938
extends Controller
4039
implements IActivityBarController {
4140
private readonly activityBarService: IActivityBarService;
42-
private readonly menuBarService: IMenuBarService;
4341
private readonly settingsService: ISettingsService;
4442
private readonly monacoService: IMonacoService;
43+
private readonly menuBarController: IMenuBarController;
4544

4645
constructor() {
4746
super();
4847
this.activityBarService = container.resolve(ActivityBarService);
49-
this.menuBarService = container.resolve(MenuBarService);
5048
this.settingsService = container.resolve(SettingsService);
5149
this.monacoService = container.resolve(MonacoService);
50+
this.menuBarController = container.resolve(MenuBarController);
5251
}
5352

5453
public readonly onSelect = (
@@ -91,7 +90,7 @@ export class ActivityBarController
9190
switch (contextMenuId) {
9291
// activityBar contextMenu
9392
case CONTEXT_MENU_MENU: {
94-
this.menuBarService.showHide();
93+
this.menuBarController.updateMenuBar!();
9594
break;
9695
}
9796
case CONTEXT_MENU_EXPLORER: {
@@ -103,7 +102,7 @@ export class ActivityBarController
103102
break;
104103
}
105104
case CONTEXT_MENU_HIDE: {
106-
this.activityBarService.showHide();
105+
this.menuBarController.updateActivityBar!();
107106
break;
108107
}
109108
// manage button contextMenu

src/controller/explorer/explorer.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'reflect-metadata';
22
import * as React from 'react';
33
import { Controller } from 'mo/react/controller';
4+
import { MenuBarController, IMenuBarController } from 'mo/controller';
45
import { container, singleton } from 'tsyringe';
56
import { connect } from 'mo/react';
67
import { Explorer, FolderTreeView } from 'mo/workbench/sidebar/explore';
@@ -63,6 +64,7 @@ export class ExplorerController
6364
private readonly folderTreeService: IFolderTreeService;
6465
private readonly menuBarService: IMenuBarService;
6566
private readonly folderTreeController: IFolderTreeController;
67+
private readonly menuBarController: IMenuBarController;
6668

6769
constructor() {
6870
super();
@@ -72,6 +74,7 @@ export class ExplorerController
7274
this.folderTreeService = container.resolve(FolderTreeService);
7375
this.menuBarService = container.resolve(MenuBarService);
7476
this.folderTreeController = container.resolve(FolderTreeController);
77+
this.menuBarController = container.resolve(MenuBarController);
7578

7679
this.initView();
7780
}
@@ -103,13 +106,11 @@ export class ExplorerController
103106
};
104107

105108
this.activityBarService.onSelect((e, item: IActivityBarItem) => {
106-
const { hidden } = this.sidebarService.getState();
107109
if (item.id === EXPLORER_ACTIVITY_ITEM) {
108-
const isShow = hidden ? !hidden : hidden;
109110
this.sidebarService.setState({
110111
current: explorePane.id,
111-
hidden: isShow,
112112
});
113+
this.menuBarController.updateSideBar!();
113114
this.menuBarService.update(MENU_VIEW_SIDEBAR, {
114115
icon: 'check',
115116
});

src/controller/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export * from './problems';
77
export * from './settings';
88
export * from './sidebar';
99
export * from './statusBar';
10-
export * from './workbench';
10+
export * from './layout';
1111
export * from './explorer/explorer';
1212
export * from './explorer/folderTree';
1313
export * from './explorer/editorTree';

src/controller/layout.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'reflect-metadata';
2+
import { container, singleton } from 'tsyringe';
3+
import { Controller } from 'mo/react/controller';
4+
import { ILayoutService, LayoutService } from 'mo/services';
5+
6+
export interface ILayoutController {
7+
onPaneSizeChange: (splitPanePos: string[]) => void;
8+
onHorizontalPaneSizeChange: (horizontalSplitPanePos: string[]) => void;
9+
}
10+
11+
@singleton()
12+
export class LayoutController extends Controller implements ILayoutController {
13+
private readonly layoutService: ILayoutService;
14+
15+
constructor() {
16+
super();
17+
this.layoutService = container.resolve(LayoutService);
18+
}
19+
20+
public onPaneSizeChange = (splitPanePos: string[]) => {
21+
this.layoutService.setPaneSize(splitPanePos);
22+
};
23+
24+
public onHorizontalPaneSizeChange = (horizontalSplitPanePos: string[]) => {
25+
this.layoutService.setHorizontalPaneSize(horizontalSplitPanePos);
26+
};
27+
}

src/controller/menuBar.ts

+24-20
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,36 @@ import {
1111
} from 'mo/model/workbench/menuBar';
1212
import { Controller } from 'mo/react/controller';
1313
import {
14-
ActivityBarService,
1514
EditorService,
16-
IActivityBarService,
1715
IEditorService,
1816
IMenuBarService,
19-
ISidebarService,
20-
IStatusBarService,
17+
ILayoutService,
2118
MenuBarService,
22-
SidebarService,
23-
StatusBarService,
19+
LayoutService,
2420
} from 'mo/services';
2521

2622
export interface IMenuBarController {
2723
onSelect?: (key: string, item?: IActivityBarItem) => void;
2824
onClick: (event: React.MouseEvent<any, any>, item: IMenuBarItem) => void;
25+
updateStatusBar?: () => void;
26+
updateMenuBar?: () => void;
27+
updateActivityBar?: () => void;
28+
updateSideBar?: () => void;
2929
}
3030

3131
@singleton()
3232
export class MenuBarController
3333
extends Controller
3434
implements IMenuBarController {
35-
private readonly activityBarService: IActivityBarService;
3635
private readonly editorService: IEditorService;
3736
private readonly menuBarService: IMenuBarService;
38-
private readonly statusBarService: IStatusBarService;
39-
private readonly sidebarService: ISidebarService;
37+
private readonly layoutService: ILayoutService;
4038

4139
constructor() {
4240
super();
43-
this.activityBarService = container.resolve(ActivityBarService);
4441
this.editorService = container.resolve(EditorService);
4542
this.menuBarService = container.resolve(MenuBarService);
46-
this.statusBarService = container.resolve(StatusBarService);
47-
this.sidebarService = container.resolve(SidebarService);
43+
this.layoutService = container.resolve(LayoutService);
4844
}
4945

5046
public readonly onClick = (event: React.MouseEvent, item: IMenuBarItem) => {
@@ -80,32 +76,40 @@ export class MenuBarController
8076
};
8177

8278
public updateActivityBar = () => {
83-
this.activityBarService.showHide();
84-
const { hidden } = this.activityBarService.getState();
79+
this.layoutService.setActivityBarHidden();
80+
const {
81+
activityBar: { hidden },
82+
} = this.layoutService.getState();
8583
this.menuBarService.update(MENU_VIEW_ACTIVITYBAR, {
8684
icon: hidden ? '' : 'check',
8785
});
8886
};
8987

9088
public updateMenuBar = () => {
91-
this.menuBarService.showHide();
92-
const { hidden } = this.menuBarService.getState();
89+
this.layoutService.setMenuBarHidden();
90+
const {
91+
menuBar: { hidden },
92+
} = this.layoutService.getState();
9393
this.menuBarService.update(MENU_VIEW_MENUBAR, {
9494
icon: hidden ? '' : 'check',
9595
});
9696
};
9797

9898
public updateStatusBar = () => {
99-
this.statusBarService.showHide();
100-
const { hidden } = this.statusBarService.getState();
99+
this.layoutService.setStatusBarHidden();
100+
const {
101+
statusBar: { hidden },
102+
} = this.layoutService.getState();
101103
this.menuBarService.update(MENU_VIEW_STATUSBAR, {
102104
icon: hidden ? '' : 'check',
103105
});
104106
};
105107

106108
public updateSideBar = () => {
107-
this.sidebarService.showHide();
108-
const { hidden } = this.sidebarService.getState();
109+
this.layoutService.setSideBarHidden();
110+
const {
111+
sideBar: { hidden },
112+
} = this.layoutService.getState();
109113
this.menuBarService.update(MENU_VIEW_SIDEBAR, {
110114
icon: hidden ? '' : 'check',
111115
});

src/controller/panel.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import {
88
PANEL_TOOLBOX_CLOSE,
99
PANEL_TOOLBOX_RESIZE,
1010
} from 'mo/model/workbench/panel';
11-
import { IPanelService, PanelService } from 'mo/services';
11+
import {
12+
IPanelService,
13+
PanelService,
14+
ILayoutService,
15+
LayoutService,
16+
} from 'mo/services';
1217

1318
export interface IPanelController {
1419
onTabChange(key: string | undefined): void;
@@ -18,10 +23,12 @@ export interface IPanelController {
1823
@singleton()
1924
export class PanelController extends Controller implements IPanelController {
2025
private readonly panelService: IPanelService;
26+
private readonly layoutService: ILayoutService;
2127

2228
constructor() {
2329
super();
2430
this.panelService = container.resolve(PanelService);
31+
this.layoutService = container.resolve(LayoutService);
2532
}
2633

2734
public readonly onTabChange = (key: string | undefined): void => {
@@ -39,7 +46,7 @@ export class PanelController extends Controller implements IPanelController {
3946
item: IActionBarItemProps
4047
): void => {
4148
if (item.id === PANEL_TOOLBOX_CLOSE) {
42-
this.panelService.showHide();
49+
this.layoutService.setPanelHidden();
4350
} else if (item.id === PANEL_TOOLBOX_RESIZE) {
4451
this.panelService.maximizeRestore();
4552
}

src/controller/problems.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
PanelService,
88
IStatusBarService,
99
StatusBarService,
10+
ILayoutService,
11+
LayoutService,
1012
} from 'mo/services';
1113
import { singleton, container } from 'tsyringe';
1214
import { builtInPanelProblems, builtInStatusProblems } from 'mo/model/problems';
@@ -19,24 +21,29 @@ export class ProblemsController
1921
implements IProblemsController {
2022
private readonly panelService: IPanelService;
2123
private readonly statusBarService: IStatusBarService;
24+
private readonly layoutService: ILayoutService;
2225

2326
constructor() {
2427
super();
2528
this.panelService = container.resolve(PanelService);
2629
this.statusBarService = container.resolve(StatusBarService);
30+
this.layoutService = container.resolve(LayoutService);
2731
this.init();
2832
}
2933

3034
private showHideProblems() {
31-
const { current, hidden } = this.panelService.getState();
35+
const { current } = this.panelService.getState();
36+
const {
37+
panel: { hidden },
38+
} = this.layoutService.getState();
3239
if (hidden) {
33-
this.panelService.showHide();
40+
this.layoutService.setPanelHidden();
3441
this.panelService.open(builtInPanelProblems());
3542
} else {
3643
if (current?.id !== builtInPanelProblems().id) {
3744
this.panelService.open(builtInPanelProblems());
3845
} else {
39-
this.panelService.showHide();
46+
this.layoutService.setPanelHidden();
4047
}
4148
}
4249
}

src/controller/workbench.ts

-28
This file was deleted.

src/model/workbench/activityBar.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export interface IActivityBar {
3636
data?: IActivityBarItem[];
3737
contextMenu?: IMenuItemProps[];
3838
selected?: string;
39-
hidden?: boolean;
4039
}
4140

4241
export const ACTIVITY_BAR_GLOBAL_SETTINGS = 'global.menu.settings';
@@ -113,16 +112,13 @@ export class ActivityBarModel implements IActivityBar {
113112
public data: IActivityBarItem[];
114113
public contextMenu: IMenuItemProps[];
115114
public selected: string;
116-
public hidden = false;
117115
constructor(
118116
data: IActivityBarItem[] = [],
119117
contextMenu: IMenuItemProps[] = [],
120-
selected: string = '',
121-
hidden = false
118+
selected: string = ''
122119
) {
123120
this.data = data;
124121
this.contextMenu = contextMenu;
125122
this.selected = selected;
126-
this.hidden = hidden;
127123
}
128124
}

0 commit comments

Comments
 (0)