Skip to content

Commit 5db28ec

Browse files
linhewewoor
linhe
authored andcommitted
feat(status bar): tuning the status bar component
1 parent 1ee9eae commit 5db28ec

File tree

8 files changed

+106
-56
lines changed

8 files changed

+106
-56
lines changed

src/controller/editor.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { editorService, statusBarService, explorerService } from 'mo/services';
1414
import { IMenuItem } from 'mo/components/menu';
1515
import { singleton } from 'tsyringe';
1616
import * as monaco from 'monaco-editor';
17-
import { editorLineColumnItem } from './statusBar';
17+
import { STATUS_EDITOR_INFO } from 'mo/model/workbench/statusBar';
1818
import { IMonacoEditorProps } from 'mo/components/monaco';
1919

2020
export interface IEditorController {
@@ -314,12 +314,11 @@ export class EditorController extends Controller implements IEditorController {
314314
if (editorInstance) {
315315
const position = editorInstance.getPosition();
316316
statusBarService.updateItem(
317-
Object.assign(editorLineColumnItem, {
318-
render: () => (
319-
<span>
320-
Ln {position?.lineNumber}, Col {position?.column}
321-
</span>
322-
),
317+
Object.assign(STATUS_EDITOR_INFO, {
318+
data: {
319+
ln: position?.lineNumber,
320+
col: position?.column,
321+
},
323322
})
324323
);
325324
}

src/model/workbench/statusBar.ts

-45
This file was deleted.

src/model/workbench/statusBar.tsx

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as React from 'react';
2+
import { injectable } from 'tsyringe';
3+
import { EditorMarkers } from 'mo/workbench/statusBar/editor';
4+
import { ProblemsMarkers } from 'mo/workbench/statusBar/problems';
5+
export interface IStatusBarItem<T = any> extends HTMLElementProps {
6+
id: string;
7+
sortIndex: number;
8+
data?: T;
9+
onClick?(e: React.MouseEvent, item?: IStatusBarItem);
10+
render?: (item: IStatusBarItem) => ReactNode;
11+
name?: string;
12+
}
13+
14+
export interface IStatusBar {
15+
rightItems: IStatusBarItem[];
16+
leftItems: IStatusBarItem[];
17+
hidden?: boolean;
18+
}
19+
20+
export const STATUS_PROBLEMS: IStatusBarItem = {
21+
id: 'MoProblems',
22+
sortIndex: 1,
23+
data: {
24+
warnings: 0,
25+
errors: 0,
26+
infos: 0,
27+
},
28+
name: 'Problems',
29+
render: (item: IStatusBarItem) => <ProblemsMarkers {...item} />,
30+
};
31+
32+
export const STATUS_EDITOR_INFO: IStatusBarItem = {
33+
id: 'MoEditorInfo',
34+
sortIndex: 2,
35+
data: {
36+
ln: 0,
37+
col: 0,
38+
},
39+
name: 'Go to Line/Column',
40+
render: (item: IStatusBarItem) => <EditorMarkers {...item} />,
41+
};
42+
43+
/**
44+
* The activity bar event definition
45+
*/
46+
export enum StatusBarEvent {
47+
/**
48+
* Selected an activity bar
49+
*/
50+
onClick = 'statusBar.onClick',
51+
/**
52+
* Activity bar data changed
53+
*/
54+
DataChanged = 'statusBar.data',
55+
}
56+
@injectable()
57+
export class StatusBarModel implements IStatusBar {
58+
public leftItems: IStatusBarItem[] = [];
59+
public rightItems: IStatusBarItem[] = [];
60+
public hidden = false;
61+
62+
constructor(
63+
leftItems: IStatusBarItem[] = [STATUS_PROBLEMS],
64+
rightItems: IStatusBarItem[] = [STATUS_EDITOR_INFO],
65+
hidden = false
66+
) {
67+
this.leftItems = leftItems;
68+
this.rightItems = rightItems;
69+
this.hidden = hidden;
70+
}
71+
}

src/services/workbench/statusBarService.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class StatusBarService
5252

5353
public showHide(): void {
5454
this.setState({
55+
...this.state,
5556
hidden: !this.state.hidden,
5657
});
5758
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from 'react';
2+
3+
export function EditorMarkers(props: any) {
4+
const { data = { ln: 0, col: 0 } } = props;
5+
return <span>{`Ln ${data.ln}, Col ${data.col}`}</span>;
6+
}

src/workbench/statusBar/item.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ import { classNames } from 'mo/common/className';
22
import { IStatusBarItem } from 'mo/model/workbench/statusBar';
33
import * as React from 'react';
44
import { memo } from 'react';
5+
import { statusBarService } from 'mo/services';
56
import { itemClassName } from './base';
67

78
function StatusItem(props: IStatusBarItem) {
8-
const { className, onClick, name, render, ...extra } = props;
9-
9+
const { className, onClick, name, data, render, ...extra } = props;
1010
const clsName = classNames(itemClassName, className);
11+
const { hidden } = statusBarService.getState();
12+
const display = hidden ? 'none' : 'block';
1113
const events = {
1214
onClick: function (e: React.MouseEvent) {
1315
onClick?.(e, props);
1416
},
1517
};
1618

1719
return (
18-
<div className={clsName} {...extra}>
20+
<div className={clsName} {...extra} style={{ display }}>
1921
<a tabIndex={-1} title={name} {...events}>
20-
{render ? render() : name}
22+
{render ? render(props) : name}
2123
</a>
2224
</div>
2325
);
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react';
2+
import { Icon } from 'mo/components/icon';
3+
export function ProblemsMarkers(props: any) {
4+
const { data = { errors: 0, warnings: 0, infos: 0 } } = props;
5+
return (
6+
<React.Fragment>
7+
<Icon type="error" />
8+
{` ${data.errors} `}
9+
<Icon type="warning" />
10+
{` ${data.warnings} `}
11+
<Icon type="info" />
12+
{` ${data.infos}`}
13+
</React.Fragment>
14+
);
15+
}

src/workbench/statusBar/style.scss

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
&__left-items,
1515
&__right-items {
16+
align-items: center;
1617
display: flex;
1718
height: 100%;
1819
}

0 commit comments

Comments
 (0)