Skip to content

Commit 048ca39

Browse files
author
Yang Zhen
committed
Fix welcome page
1 parent 3414fcf commit 048ca39

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

app/commands/commandBindings/file.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function createFolderAtPath (path) {
4646

4747

4848
export function openFile (obj) {
49+
if (!obj.path) return
4950
// 做一些encoding的调度
5051
if (FileState.initData.get('_init')) {
5152
when(() => !FileState.initData.get('_init'), () => {
@@ -276,12 +277,21 @@ const fileCommands = {
276277

277278
// 'file:unsaved_files_list':
278279
'file:open_welcome': (c) => {
279-
TabStore.createTab({
280-
icon: 'fa fa-info-circle',
281-
type: 'welcome',
282-
title: 'Welcome',
283-
})
284-
}
280+
// const activeTabGroup = TabStore.getState().activeTabGroup
281+
const existingTabs = TabStore.findTab(
282+
tab => tab.type === 'welcome'
283+
)
284+
if (existingTabs.length) {
285+
const existingTab = existingTabs[0]
286+
existingTab.activate()
287+
} else {
288+
TabStore.createTab({
289+
icon: 'fa fa-info-circle',
290+
type: 'welcome',
291+
title: 'Welcome',
292+
})
293+
}
294+
},
285295
}
286296

287297
export default fileCommands

app/commons/Tab/state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function TabScope () {
4545
}
4646

4747
@computed get isActive () {
48-
return this.tabGroup.activeTab === this
48+
return this.tabGroup && this.tabGroup.activeTab === this
4949
}
5050

5151
@computed get siblings () {

app/components/Tab/actions.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import mobxStore from 'mobxStore'
33
import { createAction, handleActions, registerAction } from 'utils/actions'
44
import state, { Tab, TabGroup } from './state'
55
import { openFile } from '../../commands/commandBindings/file'
6+
import dispatchCommand from 'commands/dispatchCommand'
67

78
export const TAB_CREATE = 'TAB_CREATE'
89
export const TAB_STORE_HYDRATE = 'TAB_STORE_HYDRATE'
@@ -11,7 +12,11 @@ export const hydrate = registerAction(TAB_STORE_HYDRATE, (json) => {
1112
Object.values(json.tabGroups).forEach((tabGroupsValue) => {
1213
createGroup(tabGroupsValue.id)
1314
})
14-
const openTabs = Object.values(json.tabs).map((tabValue) => {
15+
const tabs = Object.values(json.tabs)
16+
if (tabs.length === 0) {
17+
dispatchCommand('file:open_welcome')
18+
}
19+
const openTabs = tabs.map((tabValue) => {
1520
const { path, editor, ...others } = tabValue
1621
const option = { path, editor, others }
1722
return openFile(option)

app/styles/core-ui/Welcome.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.welcome-page {
22
color: $text-color;
33
padding: 10px 40px;
4+
height: 100%;
5+
width: 100%;
6+
overflow: scroll;
47
h1 {
58
font-weight: normal;
69
padding: 0;

0 commit comments

Comments
 (0)