mirror of
https://github.com/Minidoracat/mcp-feedback-enhanced.git
synced 2025-07-27 02:22:26 +08:00
✨ 優化GUI配置管理統一接口,避免保存配置衝突
This commit is contained in:
parent
d1932b3d5d
commit
00bbf1e113
@ -462,9 +462,11 @@ class SettingsTab(QWidget):
|
||||
|
||||
# 檢查是否真的有變更
|
||||
if new_combined_mode != self.combined_mode or new_orientation != self.layout_orientation:
|
||||
# 先保存配置
|
||||
self.config_manager.set_layout_mode(new_combined_mode)
|
||||
self.config_manager.set_layout_orientation(new_orientation)
|
||||
# 批量保存配置(避免多次寫入文件)
|
||||
self.config_manager.update_partial_config({
|
||||
'combined_mode': new_combined_mode,
|
||||
'layout_orientation': new_orientation
|
||||
})
|
||||
|
||||
# 更新內部狀態
|
||||
self.combined_mode = new_combined_mode
|
||||
|
@ -60,13 +60,37 @@ class ConfigManager:
|
||||
self._config_cache[key] = value
|
||||
self._save_config()
|
||||
|
||||
def update_partial_config(self, updates: Dict[str, Any]) -> None:
|
||||
"""批量更新配置項目,只保存指定的設定而不影響其他參數"""
|
||||
try:
|
||||
# 重新載入當前磁碟上的配置,確保我們有最新的數據
|
||||
current_config = {}
|
||||
if self._config_file.exists():
|
||||
with open(self._config_file, 'r', encoding='utf-8') as f:
|
||||
current_config = json.load(f)
|
||||
|
||||
# 只更新指定的項目
|
||||
for key, value in updates.items():
|
||||
current_config[key] = value
|
||||
# 同時更新內存緩存
|
||||
self._config_cache[key] = value
|
||||
|
||||
# 保存到文件
|
||||
with open(self._config_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(current_config, f, ensure_ascii=False, indent=2)
|
||||
|
||||
debug_log(f"部分配置已更新: {list(updates.keys())}")
|
||||
|
||||
except Exception as e:
|
||||
debug_log(f"更新部分配置失敗: {e}")
|
||||
|
||||
def get_layout_mode(self) -> bool:
|
||||
"""獲取佈局模式(False=分離模式,True=合併模式)"""
|
||||
return self.get('combined_mode', False)
|
||||
|
||||
def set_layout_mode(self, combined_mode: bool) -> None:
|
||||
"""設置佈局模式"""
|
||||
self.set('combined_mode', combined_mode)
|
||||
self.update_partial_config({'combined_mode': combined_mode})
|
||||
debug_log(f"佈局模式設置: {'合併模式' if combined_mode else '分離模式'}")
|
||||
|
||||
def get_layout_orientation(self) -> str:
|
||||
@ -77,7 +101,7 @@ class ConfigManager:
|
||||
"""設置佈局方向"""
|
||||
if orientation not in ['vertical', 'horizontal']:
|
||||
orientation = 'vertical'
|
||||
self.set('layout_orientation', orientation)
|
||||
self.update_partial_config({'layout_orientation': orientation})
|
||||
debug_log(f"佈局方向設置: {'垂直(上下)' if orientation == 'vertical' else '水平(左右)'}")
|
||||
|
||||
def get_language(self) -> str:
|
||||
@ -86,7 +110,7 @@ class ConfigManager:
|
||||
|
||||
def set_language(self, language: str) -> None:
|
||||
"""設置語言"""
|
||||
self.set('language', language)
|
||||
self.update_partial_config({'language': language})
|
||||
debug_log(f"語言設置: {language}")
|
||||
|
||||
def get_splitter_sizes(self, splitter_name: str) -> list:
|
||||
@ -98,7 +122,7 @@ class ConfigManager:
|
||||
|
||||
def set_splitter_sizes(self, splitter_name: str, sizes: list) -> None:
|
||||
"""設置分割器尺寸"""
|
||||
self.set(f'splitter_sizes.{splitter_name}', sizes)
|
||||
self.update_partial_config({f'splitter_sizes.{splitter_name}': sizes})
|
||||
debug_log(f"保存分割器 {splitter_name} 尺寸: {sizes}")
|
||||
|
||||
def get_window_geometry(self) -> dict:
|
||||
@ -109,8 +133,8 @@ class ConfigManager:
|
||||
return geometry
|
||||
|
||||
def set_window_geometry(self, geometry: dict) -> None:
|
||||
"""設置窗口幾何信息"""
|
||||
self.set('window_geometry', geometry)
|
||||
"""設置窗口幾何信息(使用部分更新避免覆蓋其他設定)"""
|
||||
self.update_partial_config({'window_geometry': geometry})
|
||||
debug_log(f"保存窗口幾何信息: {geometry}")
|
||||
|
||||
def get_always_center_window(self) -> bool:
|
||||
@ -119,7 +143,7 @@ class ConfigManager:
|
||||
|
||||
def set_always_center_window(self, always_center: bool) -> None:
|
||||
"""設置總是在主螢幕中心顯示視窗"""
|
||||
self.set('always_center_window', always_center)
|
||||
self.update_partial_config({'always_center_window': always_center})
|
||||
debug_log(f"視窗定位設置: {'總是中心顯示' if always_center else '智能定位'}")
|
||||
|
||||
def reset_settings(self) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user