From 81868e8d3740ce51f6b900a3b89779b8b499a746 Mon Sep 17 00:00:00 2001 From: landaiqing Date: Tue, 3 Jun 2025 00:19:16 +0800 Subject: [PATCH] :art: Change configuration structure --- .../voidraft/internal/models/models.ts | 291 +++++++++++------- .../internal/services/documentservice.ts | 6 +- frontend/src/components/toolbar/Toolbar.vue | 128 ++++---- frontend/src/stores/configStore.ts | 177 +++++++---- frontend/src/stores/editorStore.ts | 2 +- frontend/src/views/editor/Editor.vue | 54 ++-- .../views/settings/pages/AppearancePage.vue | 2 +- .../src/views/settings/pages/EditingPage.vue | 30 +- .../src/views/settings/pages/GeneralPage.vue | 10 +- internal/models/config.go | 107 ++++--- internal/services/config_service.go | 76 ++--- internal/services/document_service.go | 28 +- 12 files changed, 525 insertions(+), 386 deletions(-) diff --git a/frontend/bindings/voidraft/internal/models/models.ts b/frontend/bindings/voidraft/internal/models/models.ts index 0a4e4ed..f6e114a 100644 --- a/frontend/bindings/voidraft/internal/models/models.ts +++ b/frontend/bindings/voidraft/internal/models/models.ts @@ -10,23 +10,33 @@ import {Create as $Create} from "@wailsio/runtime"; import * as time$0 from "../../../time/models.js"; /** - * AppConfig 应用配置 - 包含业务配置和路径配置 + * AppConfig 应用配置 - 按照前端设置页面分类组织 */ export class AppConfig { /** - * 编辑器配置 + * 通用设置 */ - "editor": EditorConfig; + "general": GeneralConfig; /** - * 文档配置 + * 编辑设置 */ - "document": DocumentConfig; + "editing": EditingConfig; /** - * 路径配置 + * 外观设置 */ - "paths": PathsConfig; + "appearance": AppearanceConfig; + + /** + * 快捷键设置 + */ + "keyBindings": KeyBindingsConfig; + + /** + * 更新设置 + */ + "updates": UpdatesConfig; /** * 配置元数据 @@ -35,14 +45,20 @@ export class AppConfig { /** Creates a new AppConfig instance. */ constructor($$source: Partial = {}) { - if (!("editor" in $$source)) { - this["editor"] = (new EditorConfig()); + if (!("general" in $$source)) { + this["general"] = (new GeneralConfig()); } - if (!("document" in $$source)) { - this["document"] = (new DocumentConfig()); + if (!("editing" in $$source)) { + this["editing"] = (new EditingConfig()); } - if (!("paths" in $$source)) { - this["paths"] = (new PathsConfig()); + if (!("appearance" in $$source)) { + this["appearance"] = (new AppearanceConfig()); + } + if (!("keyBindings" in $$source)) { + this["keyBindings"] = (new KeyBindingsConfig()); + } + if (!("updates" in $$source)) { + this["updates"] = (new UpdatesConfig()); } if (!("metadata" in $$source)) { this["metadata"] = (new ConfigMetadata()); @@ -59,23 +75,58 @@ export class AppConfig { const $$createField1_0 = $$createType1; const $$createField2_0 = $$createType2; const $$createField3_0 = $$createType3; + const $$createField4_0 = $$createType4; + const $$createField5_0 = $$createType5; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - if ("editor" in $$parsedSource) { - $$parsedSource["editor"] = $$createField0_0($$parsedSource["editor"]); + if ("general" in $$parsedSource) { + $$parsedSource["general"] = $$createField0_0($$parsedSource["general"]); } - if ("document" in $$parsedSource) { - $$parsedSource["document"] = $$createField1_0($$parsedSource["document"]); + if ("editing" in $$parsedSource) { + $$parsedSource["editing"] = $$createField1_0($$parsedSource["editing"]); } - if ("paths" in $$parsedSource) { - $$parsedSource["paths"] = $$createField2_0($$parsedSource["paths"]); + if ("appearance" in $$parsedSource) { + $$parsedSource["appearance"] = $$createField2_0($$parsedSource["appearance"]); + } + if ("keyBindings" in $$parsedSource) { + $$parsedSource["keyBindings"] = $$createField3_0($$parsedSource["keyBindings"]); + } + if ("updates" in $$parsedSource) { + $$parsedSource["updates"] = $$createField4_0($$parsedSource["updates"]); } if ("metadata" in $$parsedSource) { - $$parsedSource["metadata"] = $$createField3_0($$parsedSource["metadata"]); + $$parsedSource["metadata"] = $$createField5_0($$parsedSource["metadata"]); } return new AppConfig($$parsedSource as Partial); } } +/** + * AppearanceConfig 外观设置配置 + */ +export class AppearanceConfig { + /** + * 界面语言 + */ + "language": LanguageType; + + /** Creates a new AppearanceConfig instance. */ + constructor($$source: Partial = {}) { + if (!("language" in $$source)) { + this["language"] = ("" as LanguageType); + } + + Object.assign(this, $$source); + } + + /** + * Creates a new AppearanceConfig instance from a string or object. + */ + static createFrom($$source: any = {}): AppearanceConfig { + let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; + return new AppearanceConfig($$parsedSource as Partial); + } +} + /** * ConfigMetadata 配置元数据 */ @@ -141,7 +192,7 @@ export class Document { * Creates a new Document instance from a string or object. */ static createFrom($$source: any = {}): Document { - const $$createField0_0 = $$createType4; + const $$createField0_0 = $$createType6; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; if ("meta" in $$parsedSource) { $$parsedSource["meta"] = $$createField0_0($$parsedSource["meta"]); @@ -150,49 +201,6 @@ export class Document { } } -/** - * DocumentConfig 定义文档配置 - */ -export class DocumentConfig { - /** - * 自动保存延迟(毫秒)- 内容变更后多久自动保存 - */ - "autoSaveDelay": number; - - /** - * 变更字符阈值,超过此阈值立即触发保存 - */ - "changeThreshold": number; - - /** - * 最小保存间隔(毫秒)- 两次保存之间的最小时间间隔,避免频繁IO - */ - "minSaveInterval": number; - - /** Creates a new DocumentConfig instance. */ - constructor($$source: Partial = {}) { - if (!("autoSaveDelay" in $$source)) { - this["autoSaveDelay"] = 0; - } - if (!("changeThreshold" in $$source)) { - this["changeThreshold"] = 0; - } - if (!("minSaveInterval" in $$source)) { - this["minSaveInterval"] = 0; - } - - Object.assign(this, $$source); - } - - /** - * Creates a new DocumentConfig instance from a string or object. - */ - static createFrom($$source: any = {}): DocumentConfig { - let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - return new DocumentConfig($$parsedSource as Partial); - } -} - /** * DocumentMeta 文档元数据 */ @@ -245,10 +253,11 @@ export class DocumentMeta { } /** - * EditorConfig 定义编辑器配置 + * EditingConfig 编辑设置配置 */ -export class EditorConfig { +export class EditingConfig { /** + * 字体设置 * 字体大小 */ "fontSize": number; @@ -269,6 +278,7 @@ export class EditorConfig { "lineHeight": number; /** + * Tab设置 * 是否启用Tab缩进 */ "enableTabIndent": boolean; @@ -284,17 +294,23 @@ export class EditorConfig { "tabType": TabType; /** - * 界面语言 + * 保存选项 + * 自动保存延迟(毫秒) */ - "language": LanguageType; + "autoSaveDelay": number; /** - * 窗口是否置顶 + * 变更字符阈值 */ - "alwaysOnTop": boolean; + "changeThreshold": number; - /** Creates a new EditorConfig instance. */ - constructor($$source: Partial = {}) { + /** + * 最小保存间隔(毫秒) + */ + "minSaveInterval": number; + + /** Creates a new EditingConfig instance. */ + constructor($$source: Partial = {}) { if (!("fontSize" in $$source)) { this["fontSize"] = 0; } @@ -316,22 +332,80 @@ export class EditorConfig { if (!("tabType" in $$source)) { this["tabType"] = ("" as TabType); } - if (!("language" in $$source)) { - this["language"] = ("" as LanguageType); + if (!("autoSaveDelay" in $$source)) { + this["autoSaveDelay"] = 0; } - if (!("alwaysOnTop" in $$source)) { - this["alwaysOnTop"] = false; + if (!("changeThreshold" in $$source)) { + this["changeThreshold"] = 0; + } + if (!("minSaveInterval" in $$source)) { + this["minSaveInterval"] = 0; } Object.assign(this, $$source); } /** - * Creates a new EditorConfig instance from a string or object. + * Creates a new EditingConfig instance from a string or object. */ - static createFrom($$source: any = {}): EditorConfig { + static createFrom($$source: any = {}): EditingConfig { let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - return new EditorConfig($$parsedSource as Partial); + return new EditingConfig($$parsedSource as Partial); + } +} + +/** + * GeneralConfig 通用设置配置 + */ +export class GeneralConfig { + /** + * 窗口是否置顶 + */ + "alwaysOnTop": boolean; + + /** + * 数据存储路径 + */ + "dataPath": string; + + /** Creates a new GeneralConfig instance. */ + constructor($$source: Partial = {}) { + if (!("alwaysOnTop" in $$source)) { + this["alwaysOnTop"] = false; + } + if (!("dataPath" in $$source)) { + this["dataPath"] = ""; + } + + Object.assign(this, $$source); + } + + /** + * Creates a new GeneralConfig instance from a string or object. + */ + static createFrom($$source: any = {}): GeneralConfig { + let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; + return new GeneralConfig($$parsedSource as Partial); + } +} + +/** + * KeyBindingsConfig 快捷键设置配置 + */ +export class KeyBindingsConfig { + + /** Creates a new KeyBindingsConfig instance. */ + constructor($$source: Partial = {}) { + + Object.assign(this, $$source); + } + + /** + * Creates a new KeyBindingsConfig instance from a string or object. + */ + static createFrom($$source: any = {}): KeyBindingsConfig { + let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; + return new KeyBindingsConfig($$parsedSource as Partial); } } @@ -355,33 +429,6 @@ export enum LanguageType { LangEnUS = "en-US", }; -/** - * PathsConfig 路径配置集合 - */ -export class PathsConfig { - /** - * 数据存储路径 - */ - "dataPath": string; - - /** Creates a new PathsConfig instance. */ - constructor($$source: Partial = {}) { - if (!("dataPath" in $$source)) { - this["dataPath"] = ""; - } - - Object.assign(this, $$source); - } - - /** - * Creates a new PathsConfig instance from a string or object. - */ - static createFrom($$source: any = {}): PathsConfig { - let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - return new PathsConfig($$parsedSource as Partial); - } -} - /** * TabType 定义了制表符类型 */ @@ -402,9 +449,31 @@ export enum TabType { TabTypeTab = "tab", }; +/** + * UpdatesConfig 更新设置配置 + */ +export class UpdatesConfig { + + /** Creates a new UpdatesConfig instance. */ + constructor($$source: Partial = {}) { + + Object.assign(this, $$source); + } + + /** + * Creates a new UpdatesConfig instance from a string or object. + */ + static createFrom($$source: any = {}): UpdatesConfig { + let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; + return new UpdatesConfig($$parsedSource as Partial); + } +} + // Private type creation functions -const $$createType0 = EditorConfig.createFrom; -const $$createType1 = DocumentConfig.createFrom; -const $$createType2 = PathsConfig.createFrom; -const $$createType3 = ConfigMetadata.createFrom; -const $$createType4 = DocumentMeta.createFrom; +const $$createType0 = GeneralConfig.createFrom; +const $$createType1 = EditingConfig.createFrom; +const $$createType2 = AppearanceConfig.createFrom; +const $$createType3 = KeyBindingsConfig.createFrom; +const $$createType4 = UpdatesConfig.createFrom; +const $$createType5 = ConfigMetadata.createFrom; +const $$createType6 = DocumentMeta.createFrom; diff --git a/frontend/bindings/voidraft/internal/services/documentservice.ts b/frontend/bindings/voidraft/internal/services/documentservice.ts index 30021b7..bc6c3df 100644 --- a/frontend/bindings/voidraft/internal/services/documentservice.ts +++ b/frontend/bindings/voidraft/internal/services/documentservice.ts @@ -61,7 +61,7 @@ export function GetDiffInfo(oldText: string, newText: string): Promise<$models.D /** * GetSaveSettings 获取文档保存设置 */ -export function GetSaveSettings(): Promise & { cancel(): void } { +export function GetSaveSettings(): Promise & { cancel(): void } { let $resultPromise = $Call.ByID(4257471801) as any; let $typingPromise = $resultPromise.then(($result: any) => { return $$createType4($result); @@ -129,7 +129,7 @@ export function UpdateActiveDocumentContent(content: string): Promise & { /** * UpdateSaveSettings 更新文档保存设置 */ -export function UpdateSaveSettings(docConfig: models$0.DocumentConfig): Promise & { cancel(): void } { +export function UpdateSaveSettings(docConfig: models$0.EditingConfig): Promise & { cancel(): void } { let $resultPromise = $Call.ByID(1245479534, docConfig) as any; return $resultPromise; } @@ -138,5 +138,5 @@ export function UpdateSaveSettings(docConfig: models$0.DocumentConfig): Promise< const $$createType0 = models$0.Document.createFrom; const $$createType1 = $Create.Nullable($$createType0); const $$createType2 = $models.DiffResult.createFrom; -const $$createType3 = models$0.DocumentConfig.createFrom; +const $$createType3 = models$0.EditingConfig.createFrom; const $$createType4 = $Create.Nullable($$createType3); diff --git a/frontend/src/components/toolbar/Toolbar.vue b/frontend/src/components/toolbar/Toolbar.vue index 186ba62..eedd0cc 100644 --- a/frontend/src/components/toolbar/Toolbar.vue +++ b/frontend/src/components/toolbar/Toolbar.vue @@ -1,75 +1,79 @@ @@ -86,34 +90,30 @@ watch(() => configStore.configLoaded, (isLoaded) => { {{ t('toolbar.editor.selected') }}: {{ editorStore.documentStats.selectedCharacters }} - - {{ logStore.latestLog.message }} -
- {{ configStore.config.fontSize }}px + {{ configStore.config.editing.fontSize }}px - - {{ t('toolbar.tabType.' + (configStore.config.tabType === 'spaces' ? 'spaces' : 'tab')) }} + + {{ t('toolbar.tabType.' + (configStore.config.editing.tabType === 'spaces' ? 'spaces' : 'tab')) }} - - - {{ configStore.config.tabSize }} - + + + {{ configStore.config.editing.tabSize }} +
@@ -130,7 +130,7 @@ watch(() => configStore.configLoaded, (isLoaded) => {
configStore.configLoaded, (isLoaded) => {
- - {{ configStore.config.fontSize }}px + {{ configStore.config.editing.fontSize }}px
@@ -167,7 +167,7 @@ const handleToggleTabType = async () => { >