mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
feat: display the file creation dialog when encountering a "NOENT" error while switching files
This commit is contained in:
+18
-2
@@ -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!)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -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': {
|
||||
|
||||
@@ -202,6 +202,10 @@ const data: BaseLanguage = {
|
||||
'title': '提示',
|
||||
'content': '密码和上一次输入的密码不一致,是否用新密码保存?',
|
||||
},
|
||||
'switch-noent-dialog': {
|
||||
'title': '文件不存在',
|
||||
'content': '文件 [%s] 不存在,是否要创建?',
|
||||
}
|
||||
},
|
||||
'status-bar': {
|
||||
'view': {
|
||||
|
||||
Reference in New Issue
Block a user