Skip to content

Commit 2bbf4a5

Browse files
committed
feat: construct the workbench struct
1 parent 9cbec33 commit 2bbf4a5

15 files changed

+146
-201
lines changed

src/common/editor.ts

-3
This file was deleted.

src/common/extension.ts

-59
This file was deleted.

src/common/keybinding.ts

-3
This file was deleted.

src/common/localization.ts

-3
This file was deleted.

src/common/molecule.ts

-18
This file was deleted.

src/common/settings.ts

-3
This file was deleted.

src/common/theme.ts

-32
This file was deleted.

src/common/workbench.ts

-5
This file was deleted.

src/components/scroller/style.scss

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.scroll {
2+
width: 10px;
3+
pointer-events: none;
4+
}

src/controller/molecule.tsx

+23-68
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,30 @@
11
import * as React from 'react';
2-
import { IExtension } from '@/common/extension';
3-
import { ILocalization } from '@/common/localization';
2+
import { IExtension } from '@/core/extension';
3+
import { IMolecule } from '@/core/molecule';
4+
import { ILocalization } from '@/core/localization';
45
import { ExtensionService } from '@/services/extensionService';
6+
import { ActivityBarService } from '@/services/activityBarService';
7+
import { MoleculeService } from '@/services/moleculeService';
8+
9+
// TODO This way just for development
10+
import CustomizedActivityBar from '@/extensions/workbench-extension/src/app';
511

612
interface IMoleculeProps {
713
extensions: IExtension[];
814
locales: ILocalization[];
915
}
1016

11-
interface IMoleculeState {
12-
/**
13-
* Workbench's status
14-
*/
15-
workbench: object;
16-
/**
17-
* Loaded extensions
18-
*/
19-
extensions: IExtension[];
20-
/**
21-
* Default user's setting
22-
*/
23-
settings: object;
24-
/**
25-
* The current theme status
26-
*/
27-
theme: string;
28-
/**
29-
* The icon theme for workbench
30-
*/
31-
iconTheme: string;
32-
/**
33-
* Molecule's language
34-
*/
35-
local: string;
36-
/**
37-
* IDE shortcut keys
38-
*/
39-
shortcutKeys: object;
40-
}
41-
42-
const DEFAULT_COLOR_THEME = 'light-vs';
43-
const DEFAULT_LOCALE_LANG = 'en-us';
44-
45-
const initialState: IMoleculeState = {
46-
47-
workbench: {
48-
editor: {
49-
value: '',
50-
},
51-
panels: [],
52-
terminal: null,
53-
},
54-
55-
extensions: [],
17+
// const DEFAULT_COLOR_THEME = 'light-vs';
18+
// const DEFAULT_LOCALE_LANG = 'en-us';
5619

57-
settings: {},
20+
const initialState: IMolecule = new MoleculeService(
21+
new ActivityBarService(),
22+
);
5823

59-
theme: DEFAULT_COLOR_THEME,
24+
export const MoleculeCtx = React.createContext(initialState);
6025

61-
iconTheme: '',
62-
63-
local: DEFAULT_LOCALE_LANG,
64-
65-
shortcutKeys: {},
66-
};
67-
68-
const MoleculeCtx = React.createContext(initialState);
69-
70-
export class MoleculeProvider
71-
extends React.Component<IMoleculeProps, IMoleculeState> {
72-
public state = initialState;
26+
export class MoleculeProvider extends React.Component<IMoleculeProps> {
27+
public state: IMolecule = initialState;
7328

7429
private extensionService: ExtensionService;
7530

@@ -79,10 +34,9 @@ export class MoleculeProvider
7934
const { extensions, locales } = this.props;
8035
this.loadExtensions(extensions);
8136
this.loadLocales(locales);
82-
}
83-
84-
public componentDidMount() {
85-
console.log('Molecule componentDidMount.');
37+
const ext = new CustomizedActivityBar();
38+
ext.active(this.state);
39+
console.log('Molecule constructed.');
8640
}
8741

8842
public initMolecule() {
@@ -92,9 +46,10 @@ export class MoleculeProvider
9246
public loadExtensions(extensions: IExtension[]) {
9347
if (extensions) {
9448
// TODO register extension to memory, and
95-
this.setState({
96-
extensions: this.extensionService.getAll(extensions),
97-
});
49+
this.extensionService.getAll(extensions);
50+
// this.setState({
51+
// extensions: this.extensionService.getAll(extensions),
52+
// });
9853
}
9954
}
10055

src/typings/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ReactType = React.PureComponent | React.ReactElement | React.Component | React.FunctionComponent | null;
+11-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
@import '@/style/const.scss';
22

3-
.#{$prefix}-activityBar {
3+
$activityBar: 'activityBar';
4+
5+
.#{$prefix}-#{$activityBar} {
46
position: absolute;
57
width: 48px;
68
height: 100%;
79
z-index: 1;
810
// TODO temp style, just for development
911
background-color: rgb(51, 51, 51);
1012
}
13+
14+
.#{$activityBar}-item {
15+
position: relative;
16+
width: 48px;
17+
height: 48px;
18+
z-index: 1;
19+
display: flex;
20+
}

src/workbench/activityBar/index.tsx

+40-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,51 @@
11
import * as React from 'react';
22

33
import { prefixClaName } from '@/common/className';
4+
import { IActivityBarData, IActivityBar } from '@/core/activityBar';
45

56
import './activityBar.scss';
67

7-
export const ActivityBar: React.FunctionComponent = function() {
8+
export interface IActivityBarProps {
9+
activityBar: IActivityBar;
10+
}
11+
12+
export const ROOT_CLASS_NAME = 'activityBar';
13+
14+
export const ActivityBarItem = React.memo(function FnActivityBarItem(props: IActivityBarData) {
15+
const { id, name = '', data = {}, render } = props;
16+
if (render) {
17+
return render();
18+
}
19+
return (
20+
<a
21+
className={prefixClaName('item', ROOT_CLASS_NAME)}
22+
title={name} key={id}
23+
data-item={data}
24+
>
25+
{name}
26+
</a>
27+
);
28+
});
29+
30+
export const ActivityBar = React.memo(function FnActivityBar(props: IActivityBarProps) {
31+
const { activityBar } = props;
32+
33+
let content = activityBar.data?.map((item: IActivityBarData) => (
34+
<ActivityBarItem key={item.id} {...item}/>
35+
));
36+
if (activityBar.render) {
37+
content = activityBar.render();
38+
}
39+
40+
const onClick = (e: React.MouseEvent) => {
41+
activityBar.onClick(e, {} as any );
42+
};
43+
844
return (
9-
<div className={prefixClaName('activityBar')}>
10-
ActivityBar
45+
<div className={prefixClaName(ROOT_CLASS_NAME)} onClick={onClick}>
46+
{content}
1147
</div>
1248
);
13-
};
49+
});
1450

1551
export default ActivityBar;

src/workbench/index.tsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,30 @@ import StatusBar from './statusBar';
1111
import Editor from './editor';
1212
import Panel from './panel';
1313

14+
import { IMolecule } from '@/core/molecule';
15+
1416
import './workbench.scss';
17+
import { MoleculeCtx } from '@/controller/molecule';
18+
19+
export interface IWorkbenchProps {
20+
21+
}
1522

1623
const MainBench: React.FunctionComponent = function(props: any) {
1724
return (
1825
<div className={prefixClaName('mainBench')}>{props.children}</div>
1926
);
2027
};
2128

22-
export const Workbench: React.FunctionComponent = function() {
29+
export const Workbench: React.FunctionComponent<IWorkbenchProps> = function(props: IWorkbenchProps) {
30+
const moleculeCtx: IMolecule = React.useContext(MoleculeCtx);
31+
const { activityBar } = moleculeCtx;
32+
2333
return (
2434
<div className={APP_PREFIX + ' center'}>
2535
<div className={prefixClaName('workbench')}>
2636
<MenuBar />
27-
<ActivityBar />
37+
<ActivityBar activityBar={activityBar}/>
2838
<MainBench>
2939
<SplitPane
3040
split={'vertical'}

0 commit comments

Comments
 (0)