Skip to content

Commit 1f9b24b

Browse files
authored
feat: support to customize welcome page (#202)
1 parent fb3c370 commit 1f9b24b

File tree

7 files changed

+81
-8
lines changed

7 files changed

+81
-8
lines changed

src/extensions/editor/statusBarView/index.tsx

-6
This file was deleted.

src/model/workbench/editor.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface IEditor {
4646
*/
4747
current?: IEditorGroup | null;
4848
groups?: IEditorGroup[];
49+
entry?: React.ReactNode;
4950
}
5051

5152
export const EDITOR_MENU_CLOSE_TO_RIGHT = 'editor.closeToRight';
@@ -125,12 +126,15 @@ export class EditorGroupModel<E = any, T = any> implements IEditorGroup<E, T> {
125126
export class EditorModel implements IEditor {
126127
public current: IEditorGroup | null;
127128
public groups: IEditorGroup[];
129+
public entry: React.ReactNode;
128130

129131
constructor(
130132
current: IEditorGroup | null = null,
131-
groups: IEditorGroup[] = []
133+
groups: IEditorGroup[] = [],
134+
entry: React.ReactNode
132135
) {
133136
this.current = current;
134137
this.groups = groups;
138+
this.entry = entry;
135139
}
136140
}

src/services/workbench/editorService.ts

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export interface IEditorService extends Component<IEditor> {
2424
group: IEditorGroup
2525
): IEditorTab<T> | undefined;
2626
updateTab(tab: IEditorTab, groupId: number): IEditorTab;
27+
/**
28+
* Specify a entry page for editor
29+
*/
30+
setEntry(component: React.ReactNode): void;
2731
closeTab(tabId: string, groupId: number): void;
2832
closeOthers(tab: IEditorTab, groupId: number): void;
2933
closeToRight(tab: IEditorTab, groupId: number): void;
@@ -68,6 +72,12 @@ export class EditorService
6872
this.state = container.resolve(EditorModel);
6973
}
7074

75+
public setEntry(component: React.ReactNode) {
76+
this.setState({
77+
entry: component,
78+
});
79+
}
80+
7181
public getTabById<T>(
7282
tabId: string,
7383
group: IEditorGroup

src/workbench/editor/editor.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function Editor(props: IEditor & IEditorController) {
1313
const {
1414
groups = [],
1515
current,
16+
entry = <Welcome />,
1617
onClickContextMenu,
1718
onCloseTab,
1819
onMoveTab,
@@ -73,7 +74,7 @@ export function Editor(props: IEditor & IEditorController) {
7374

7475
return (
7576
<div className={defaultEditorClassName}>
76-
{current ? renderGroups() : <Welcome />}
77+
{current ? renderGroups() : entry}
7778
</div>
7879
);
7980
}

stories/extensions/test/entry.scss

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.entry {
2+
align-items: center;
3+
background-color: var(--panel-background);
4+
display: flex;
5+
flex-direction: column;
6+
justify-content: center;
7+
text-align: center;
8+
width: 100%;
9+
10+
* {
11+
font-family: monospace;
12+
}
13+
14+
dl {
15+
border-collapse: separate;
16+
border-spacing: 13px 17px;
17+
color: hsla(0, 0%, 100%, 0.6);
18+
cursor: default;
19+
display: table-row;
20+
font-size: 13px;
21+
margin: 0;
22+
23+
dt {
24+
display: table-cell;
25+
letter-spacing: 0.04em;
26+
text-align: right;
27+
}
28+
29+
dd {
30+
display: table-cell;
31+
margin-left: 12px;
32+
text-align: left;
33+
}
34+
}
35+
}

stories/extensions/test/entry.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import './entry.scss';
3+
4+
export const Entry = () => {
5+
return (
6+
<div className="entry">
7+
<h1>molecule</h1>
8+
<dl>
9+
<dt>显示所有命令</dt>
10+
<dd> command + b</dd>
11+
</dl>
12+
<dl>
13+
<dt>打开文件或文件夹</dt>
14+
<dd> command + b</dd>
15+
</dl>
16+
<dl>
17+
<dt>打开最近文件</dt>
18+
<dd> command + b</dd>
19+
</dl>
20+
<dl>
21+
<dt>新的无标题文件</dt>
22+
<dd> command + b</dd>
23+
</dl>
24+
</div>
25+
);
26+
};

stories/extensions/test/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { IExtension } from 'mo/model';
1010

1111
import TestPane from './testPane';
12+
import { Entry } from './entry';
1213

1314
export const ExtendTestPane: IExtension = {
1415
activate() {
@@ -30,6 +31,8 @@ export const ExtendTestPane: IExtension = {
3031
molecule.activityBar.addBar(newItem);
3132
molecule.sidebar.addPane(testSidePane);
3233

34+
molecule.editor.setEntry(<Entry />);
35+
3336
molecule.settings.onChangeConfiguration(async (value) => {
3437
console.log('onChangeConfiguration:', value);
3538
molecule.settings.update(value);

0 commit comments

Comments
 (0)