feat: display the file creation dialog when encountering a "NOENT" error while switching files

This commit is contained in:
purocean
2023-07-17 18:11:30 +08:00
parent c3c81ec08f
commit 128aa83f73
3 changed files with 26 additions and 2 deletions
+18 -2
View File
@@ -1,13 +1,15 @@
import { init } from '@fe/core/plugin'
import { getActionHandler } from '@fe/core/action'
import { registerHook, triggerHook } from '@fe/core/hook'
import store from '@fe/support/store'
import { isElectron } from '@fe/support/env'
import { useToast } from './support/ui/toast'
import { useModal } from '@fe/support/ui/modal'
import * as storage from '@fe/utils/storage'
import { basename } from '@fe/utils/path'
import type { BuildInSettings, Doc, FrontMatterAttrs, Repo } from '@fe/types'
import { reloadMainWindow } from '@fe/services/base'
import { isMarked, markDoc, switchDoc, unmarkDoc } from '@fe/services/document'
import { createDoc, isMarked, markDoc, switchDoc, toUri, unmarkDoc } from '@fe/services/document'
import { refreshTree } from '@fe/services/tree'
import { whenEditorReady } from '@fe/services/editor'
import { getLanguage, setLanguage, t } from '@fe/services/i18n'
@@ -82,9 +84,23 @@ registerHook('DOC_CREATED', refreshTree)
registerHook('DOC_DELETED', refreshTree)
registerHook('DOC_MOVED', refreshTree)
registerHook('DOC_SWITCH_FAILED', refreshTree)
registerHook('DOC_SWITCH_FAILED', (payload?: { doc?: Doc | null, message: string }) => {
registerHook('DOC_SWITCH_FAILED', async (payload?: { doc?: Doc | null, message: string }) => {
if (payload && payload.doc && payload.message?.includes('NOENT')) {
unmarkDoc(payload.doc)
// wait toast show then hide
await Promise.resolve()
await Promise.resolve()
await Promise.resolve()
useToast().hide()
useModal().confirm({
title: t('document.switch-noent-dialog.title'),
content: t('document.switch-noent-dialog.content', payload.doc.path),
}).then(async v => {
getActionHandler('file-tabs.close-tabs')([toUri(payload.doc)])
v && await createDoc(payload.doc!)
})
}
})
+4
View File
@@ -201,6 +201,10 @@ const data = {
'title': 'Attention',
'content': 'The password doesn\'t match the old password, save it with the new password?',
},
'switch-noent-dialog': {
'title': 'File Not Found',
'content': 'File [%s] not found, do you want to create it?',
}
},
'status-bar': {
'view': {
+4
View File
@@ -202,6 +202,10 @@ const data: BaseLanguage = {
'title': '提示',
'content': '密码和上一次输入的密码不一致,是否用新密码保存?',
},
'switch-noent-dialog': {
'title': '文件不存在',
'content': '文件 [%s] 不存在,是否要创建?',
}
},
'status-bar': {
'view': {