feat: improve file path selection in Setting.vue

This commit is contained in:
purocean
2024-09-05 11:33:12 +08:00
parent 4d1c148fcc
commit c055953d2d
3 changed files with 11 additions and 6 deletions
+7 -6
View File
@@ -154,15 +154,16 @@ export default defineComponent({
const onClick = async (e: Event) => {
const target = e.target as HTMLInputElement
if (target.name && target.name.endsWith('[path]')) {
if (target.tagName === 'INPUT' && target.name) {
const jsonPath = target.name.replace(/\]/g, '').replace(/\[/g, '.')
const field = editor.getEditor(jsonPath)
const { canceled, filePaths } = await api.choosePath({
properties: ['openDirectory', 'createDirectory'],
})
if (!canceled && filePaths[0]) {
field.setValue(filePaths[0])
if (field && field.schema.openDialogOptions) {
const { canceled, filePaths } = await api.choosePath(field.schema.openDialogOptions)
if (!canceled && filePaths[0]) {
field.setValue(filePaths[0])
}
}
}
}
+1
View File
@@ -30,6 +30,7 @@ const schema: SettingSchema = ({
path: {
type: 'string',
title: 'T_setting-panel.schema.repos.path',
openDialogOptions: { properties: ['openDirectory', 'createDirectory'] },
options: {
inputAttributes: { placeholder: 'T_setting-panel.schema.repos.path-placeholder', style: 'cursor: pointer' }
},
+3
View File
@@ -1,4 +1,5 @@
import type { VNode } from 'vue'
import type { OpenDialogOptions } from 'electron'
import type { Language, MsgPath } from '@share/i18n'
import type { Doc, FileItem, PathItem, Repo } from '@share/types'
import type MarkdownIt from 'markdown-it'
@@ -29,6 +30,7 @@ export type SettingSchema = {
defaultValue: BuildInSettings[K] extends any ? BuildInSettings[K] : any,
enum?: string[] | number [],
group: SettingGroup,
openDialogOptions?: OpenDialogOptions,
needReloadWindowWhenChanged?: boolean,
validator?: (schema: SettingSchema['properties'][K], value: BuildInSettings[K], path: string) =>
{path: string, property: K, message: string}[]
@@ -43,6 +45,7 @@ export type SettingSchema = {
options: {
inputAttributes: { placeholder: TTitle }
}
openDialogOptions?: OpenDialogOptions,
}
}
},