🎨 Change configuration structure
This commit is contained in:
@@ -68,7 +68,7 @@ func (cs *ConfigService) validateAndFixValue(key string, value interface{}) (int
|
||||
fixed := false
|
||||
|
||||
switch key {
|
||||
case "editor.font_size":
|
||||
case "editing.font_size":
|
||||
if intVal, ok := value.(int); ok {
|
||||
if intVal < limits.FontSizeMin {
|
||||
cs.logger.Warning("Config: Font size too small, fixing", "original", intVal, "fixed", limits.FontSizeMin)
|
||||
@@ -80,7 +80,7 @@ func (cs *ConfigService) validateAndFixValue(key string, value interface{}) (int
|
||||
}
|
||||
}
|
||||
|
||||
case "editor.tab_size":
|
||||
case "editing.tab_size":
|
||||
if intVal, ok := value.(int); ok {
|
||||
if intVal < limits.TabSizeMin {
|
||||
cs.logger.Warning("Config: Tab size too small, fixing", "original", intVal, "fixed", limits.TabSizeMin)
|
||||
@@ -92,7 +92,7 @@ func (cs *ConfigService) validateAndFixValue(key string, value interface{}) (int
|
||||
}
|
||||
}
|
||||
|
||||
case "editor.tab_type":
|
||||
case "editing.tab_type":
|
||||
if strVal, ok := value.(string); ok {
|
||||
validTypes := []string{string(models.TabTypeSpaces), string(models.TabTypeTab)}
|
||||
isValid := false
|
||||
@@ -108,7 +108,7 @@ func (cs *ConfigService) validateAndFixValue(key string, value interface{}) (int
|
||||
}
|
||||
}
|
||||
|
||||
case "editor.language":
|
||||
case "appearance.language":
|
||||
if strVal, ok := value.(string); ok {
|
||||
validLanguages := []string{string(models.LangZhCN), string(models.LangEnUS)}
|
||||
isValid := false
|
||||
@@ -124,7 +124,7 @@ func (cs *ConfigService) validateAndFixValue(key string, value interface{}) (int
|
||||
}
|
||||
}
|
||||
|
||||
case "document.auto_save_delay":
|
||||
case "editing.auto_save_delay":
|
||||
if intVal, ok := value.(int); ok {
|
||||
if intVal < 1000 {
|
||||
cs.logger.Warning("Config: Auto save delay too small, fixing", "original", intVal, "fixed", 1000)
|
||||
@@ -136,7 +136,7 @@ func (cs *ConfigService) validateAndFixValue(key string, value interface{}) (int
|
||||
}
|
||||
}
|
||||
|
||||
case "document.change_threshold":
|
||||
case "editing.change_threshold":
|
||||
if intVal, ok := value.(int); ok {
|
||||
if intVal < 10 {
|
||||
cs.logger.Warning("Config: Change threshold too small, fixing", "original", intVal, "fixed", 10)
|
||||
@@ -148,7 +148,7 @@ func (cs *ConfigService) validateAndFixValue(key string, value interface{}) (int
|
||||
}
|
||||
}
|
||||
|
||||
case "document.min_save_interval":
|
||||
case "editing.min_save_interval":
|
||||
if intVal, ok := value.(int); ok {
|
||||
if intVal < 100 {
|
||||
cs.logger.Warning("Config: Min save interval too small, fixing", "original", intVal, "fixed", 100)
|
||||
@@ -175,39 +175,39 @@ func (cs *ConfigService) validateAllConfig() error {
|
||||
}
|
||||
|
||||
// 验证编辑器配置
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editor.font_size", config.Editor.FontSize); fixed {
|
||||
cs.viper.Set("editor.font_size", fixedValue)
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editing.font_size", config.Editing.FontSize); fixed {
|
||||
cs.viper.Set("editing.font_size", fixedValue)
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editor.tab_size", config.Editor.TabSize); fixed {
|
||||
cs.viper.Set("editor.tab_size", fixedValue)
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editing.tab_size", config.Editing.TabSize); fixed {
|
||||
cs.viper.Set("editing.tab_size", fixedValue)
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editor.tab_type", string(config.Editor.TabType)); fixed {
|
||||
cs.viper.Set("editor.tab_type", fixedValue)
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editing.tab_type", string(config.Editing.TabType)); fixed {
|
||||
cs.viper.Set("editing.tab_type", fixedValue)
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editor.language", string(config.Editor.Language)); fixed {
|
||||
cs.viper.Set("editor.language", fixedValue)
|
||||
if fixedValue, fixed := cs.validateAndFixValue("appearance.language", string(config.Appearance.Language)); fixed {
|
||||
cs.viper.Set("appearance.language", fixedValue)
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
// 验证文档配置
|
||||
if fixedValue, fixed := cs.validateAndFixValue("document.auto_save_delay", config.Document.AutoSaveDelay); fixed {
|
||||
cs.viper.Set("document.auto_save_delay", fixedValue)
|
||||
// 验证保存选项配置
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editing.auto_save_delay", config.Editing.AutoSaveDelay); fixed {
|
||||
cs.viper.Set("editing.auto_save_delay", fixedValue)
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
if fixedValue, fixed := cs.validateAndFixValue("document.change_threshold", config.Document.ChangeThreshold); fixed {
|
||||
cs.viper.Set("document.change_threshold", fixedValue)
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editing.change_threshold", config.Editing.ChangeThreshold); fixed {
|
||||
cs.viper.Set("editing.change_threshold", fixedValue)
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
if fixedValue, fixed := cs.validateAndFixValue("document.min_save_interval", config.Document.MinSaveInterval); fixed {
|
||||
cs.viper.Set("document.min_save_interval", fixedValue)
|
||||
if fixedValue, fixed := cs.validateAndFixValue("editing.min_save_interval", config.Editing.MinSaveInterval); fixed {
|
||||
cs.viper.Set("editing.min_save_interval", fixedValue)
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
@@ -280,24 +280,24 @@ func NewConfigService(logger *log.LoggerService) *ConfigService {
|
||||
func setDefaults(v *viper.Viper) {
|
||||
defaultConfig := models.NewDefaultAppConfig()
|
||||
|
||||
// 编辑器配置默认值
|
||||
v.SetDefault("editor.font_size", defaultConfig.Editor.FontSize)
|
||||
v.SetDefault("editor.font_family", defaultConfig.Editor.FontFamily)
|
||||
v.SetDefault("editor.font_weight", defaultConfig.Editor.FontWeight)
|
||||
v.SetDefault("editor.line_height", defaultConfig.Editor.LineHeight)
|
||||
v.SetDefault("editor.enable_tab_indent", defaultConfig.Editor.EnableTabIndent)
|
||||
v.SetDefault("editor.tab_size", defaultConfig.Editor.TabSize)
|
||||
v.SetDefault("editor.tab_type", defaultConfig.Editor.TabType)
|
||||
v.SetDefault("editor.language", defaultConfig.Editor.Language)
|
||||
v.SetDefault("editor.always_on_top", defaultConfig.Editor.AlwaysOnTop)
|
||||
// 通用设置默认值
|
||||
v.SetDefault("general.always_on_top", defaultConfig.General.AlwaysOnTop)
|
||||
v.SetDefault("general.data_path", defaultConfig.General.DataPath)
|
||||
|
||||
// 文档配置默认值
|
||||
v.SetDefault("document.auto_save_delay", defaultConfig.Document.AutoSaveDelay)
|
||||
v.SetDefault("document.change_threshold", defaultConfig.Document.ChangeThreshold)
|
||||
v.SetDefault("document.min_save_interval", defaultConfig.Document.MinSaveInterval)
|
||||
// 编辑设置默认值
|
||||
v.SetDefault("editing.font_size", defaultConfig.Editing.FontSize)
|
||||
v.SetDefault("editing.font_family", defaultConfig.Editing.FontFamily)
|
||||
v.SetDefault("editing.font_weight", defaultConfig.Editing.FontWeight)
|
||||
v.SetDefault("editing.line_height", defaultConfig.Editing.LineHeight)
|
||||
v.SetDefault("editing.enable_tab_indent", defaultConfig.Editing.EnableTabIndent)
|
||||
v.SetDefault("editing.tab_size", defaultConfig.Editing.TabSize)
|
||||
v.SetDefault("editing.tab_type", defaultConfig.Editing.TabType)
|
||||
v.SetDefault("editing.auto_save_delay", defaultConfig.Editing.AutoSaveDelay)
|
||||
v.SetDefault("editing.change_threshold", defaultConfig.Editing.ChangeThreshold)
|
||||
v.SetDefault("editing.min_save_interval", defaultConfig.Editing.MinSaveInterval)
|
||||
|
||||
// 路径配置默认值
|
||||
v.SetDefault("paths.data_path", defaultConfig.Paths.DataPath)
|
||||
// 外观设置默认值
|
||||
v.SetDefault("appearance.language", defaultConfig.Appearance.Language)
|
||||
|
||||
// 元数据默认值
|
||||
v.SetDefault("metadata.version", defaultConfig.Metadata.Version)
|
||||
|
@@ -147,9 +147,9 @@ func (ds *DocumentService) scheduleAutoSave() {
|
||||
|
||||
// 打印保存设置,便于调试
|
||||
ds.logger.Debug("Document: Auto save settings",
|
||||
"autoSaveDelay", config.Document.AutoSaveDelay,
|
||||
"changeThreshold", config.Document.ChangeThreshold,
|
||||
"minSaveInterval", config.Document.MinSaveInterval)
|
||||
"autoSaveDelay", config.Editing.AutoSaveDelay,
|
||||
"changeThreshold", config.Editing.ChangeThreshold,
|
||||
"minSaveInterval", config.Editing.MinSaveInterval)
|
||||
|
||||
ds.lock.Lock()
|
||||
defer ds.lock.Unlock()
|
||||
@@ -160,7 +160,7 @@ func (ds *DocumentService) scheduleAutoSave() {
|
||||
}
|
||||
|
||||
// 创建新的自动保存定时器
|
||||
autoSaveDelay := config.Document.AutoSaveDelay
|
||||
autoSaveDelay := config.Editing.AutoSaveDelay
|
||||
ds.logger.Debug("Document: Scheduling auto save", "delay", autoSaveDelay)
|
||||
ds.scheduleTimerWithDelay(autoSaveDelay)
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (ds *DocumentService) saveToStore(trigger SaveTrigger) {
|
||||
|
||||
// 如果成功获取了配置,使用配置值
|
||||
if err == nil && config != nil {
|
||||
minInterval = config.Document.MinSaveInterval
|
||||
minInterval = config.Editing.MinSaveInterval
|
||||
}
|
||||
|
||||
// 如果是自动保存,检查最小保存间隔
|
||||
@@ -305,7 +305,7 @@ func (ds *DocumentService) ensureDocumentsDir() error {
|
||||
}
|
||||
|
||||
// 创建文档目录
|
||||
docsDir := filepath.Join(config.Paths.DataPath, "docs")
|
||||
docsDir := filepath.Join(config.General.DataPath, "docs")
|
||||
err = os.MkdirAll(docsDir, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -320,7 +320,7 @@ func (ds *DocumentService) getDocumentsDir() (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(config.Paths.DataPath, "docs"), nil
|
||||
return filepath.Join(config.General.DataPath, "docs"), nil
|
||||
}
|
||||
|
||||
// getDefaultDocumentPath 获取默认文档路径
|
||||
@@ -405,7 +405,7 @@ func (ds *DocumentService) UpdateActiveDocumentContent(content string) error {
|
||||
|
||||
// 如果成功获取了配置,使用配置值
|
||||
if err == nil && config != nil {
|
||||
threshold = config.Document.ChangeThreshold
|
||||
threshold = config.Editing.ChangeThreshold
|
||||
}
|
||||
|
||||
ds.lock.Lock()
|
||||
@@ -520,26 +520,26 @@ func (ds *DocumentService) GetDiffInfo(oldText, newText string) DiffResult {
|
||||
}
|
||||
|
||||
// GetSaveSettings 获取文档保存设置
|
||||
func (ds *DocumentService) GetSaveSettings() (*models.DocumentConfig, error) {
|
||||
func (ds *DocumentService) GetSaveSettings() (*models.EditingConfig, error) {
|
||||
config, err := ds.configService.GetConfig()
|
||||
if err != nil {
|
||||
return nil, &DocumentError{Operation: "get_save_settings", Err: err}
|
||||
}
|
||||
return &config.Document, nil
|
||||
return &config.Editing, nil
|
||||
}
|
||||
|
||||
// UpdateSaveSettings 更新文档保存设置
|
||||
func (ds *DocumentService) UpdateSaveSettings(docConfig models.DocumentConfig) error {
|
||||
func (ds *DocumentService) UpdateSaveSettings(docConfig models.EditingConfig) error {
|
||||
// 使用配置服务的 Set 方法更新文档配置
|
||||
if err := ds.configService.Set("document.auto_save_delay", docConfig.AutoSaveDelay); err != nil {
|
||||
if err := ds.configService.Set("editing.auto_save_delay", docConfig.AutoSaveDelay); err != nil {
|
||||
return &DocumentError{Operation: "update_save_settings_auto_save_delay", Err: err}
|
||||
}
|
||||
|
||||
if err := ds.configService.Set("document.change_threshold", docConfig.ChangeThreshold); err != nil {
|
||||
if err := ds.configService.Set("editing.change_threshold", docConfig.ChangeThreshold); err != nil {
|
||||
return &DocumentError{Operation: "update_save_settings_change_threshold", Err: err}
|
||||
}
|
||||
|
||||
if err := ds.configService.Set("document.min_save_interval", docConfig.MinSaveInterval); err != nil {
|
||||
if err := ds.configService.Set("editing.min_save_interval", docConfig.MinSaveInterval); err != nil {
|
||||
return &DocumentError{Operation: "update_save_settings_min_save_interval", Err: err}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user