mirror of
https://github.com/Minidoracat/mcp-feedback-enhanced.git
synced 2025-10-10 06:03:55 +08:00
Merge branch 'feature/auto-focus-input-box' of github.com:penn201500/mcp-feedback-enhanced into penn201500-feature/auto-focus-input-box
This commit is contained in:
commit
04798e4aa4
@ -117,7 +117,8 @@
|
|||||||
},
|
},
|
||||||
"window": {
|
"window": {
|
||||||
"title": "Window Positioning",
|
"title": "Window Positioning",
|
||||||
"alwaysCenter": "Always show window at primary screen center"
|
"alwaysCenter": "Always show window at primary screen center",
|
||||||
|
"autoFocus": "Auto-focus input box when window opens"
|
||||||
},
|
},
|
||||||
"reset": {
|
"reset": {
|
||||||
"title": "Reset Settings",
|
"title": "Reset Settings",
|
||||||
|
@ -97,7 +97,8 @@
|
|||||||
},
|
},
|
||||||
"window": {
|
"window": {
|
||||||
"title": "窗口定位",
|
"title": "窗口定位",
|
||||||
"alwaysCenter": "总是在主屏幕中心显示窗口"
|
"alwaysCenter": "总是在主屏幕中心显示窗口",
|
||||||
|
"autoFocus": "窗口打开时自动聚焦到输入框"
|
||||||
},
|
},
|
||||||
"reset": {
|
"reset": {
|
||||||
"title": "重置设置",
|
"title": "重置设置",
|
||||||
|
@ -129,7 +129,8 @@
|
|||||||
},
|
},
|
||||||
"window": {
|
"window": {
|
||||||
"title": "視窗定位",
|
"title": "視窗定位",
|
||||||
"alwaysCenter": "總是在主螢幕中心顯示視窗"
|
"alwaysCenter": "總是在主螢幕中心顯示視窗",
|
||||||
|
"autoFocus": "窗口打開時自動聚焦到輸入框"
|
||||||
},
|
},
|
||||||
"reset": {
|
"reset": {
|
||||||
"title": "重置設定",
|
"title": "重置設定",
|
||||||
|
@ -312,6 +312,12 @@ class SettingsTab(QWidget):
|
|||||||
self.always_center_switch.toggled.connect(self._on_always_center_changed)
|
self.always_center_switch.toggled.connect(self._on_always_center_changed)
|
||||||
options_layout.addWidget(self.always_center_switch)
|
options_layout.addWidget(self.always_center_switch)
|
||||||
|
|
||||||
|
# 自動聚焦開關
|
||||||
|
self.auto_focus_switch = SwitchWithLabel(t('settings.window.autoFocus'))
|
||||||
|
self.auto_focus_switch.setChecked(self.config_manager.get_auto_focus_enabled())
|
||||||
|
self.auto_focus_switch.toggled.connect(self._on_auto_focus_changed)
|
||||||
|
options_layout.addWidget(self.auto_focus_switch)
|
||||||
|
|
||||||
layout.addLayout(options_layout)
|
layout.addLayout(options_layout)
|
||||||
|
|
||||||
def _create_timeout_section(self, layout: QVBoxLayout) -> None:
|
def _create_timeout_section(self, layout: QVBoxLayout) -> None:
|
||||||
@ -485,6 +491,12 @@ class SettingsTab(QWidget):
|
|||||||
self.config_manager.set_always_center_window(checked)
|
self.config_manager.set_always_center_window(checked)
|
||||||
debug_log(f"視窗定位設置已保存: {checked}") # 調試輸出
|
debug_log(f"視窗定位設置已保存: {checked}") # 調試輸出
|
||||||
|
|
||||||
|
def _on_auto_focus_changed(self, checked: bool) -> None:
|
||||||
|
"""自動聚焦選項變更事件處理"""
|
||||||
|
# 立即保存設定
|
||||||
|
self.config_manager.set_auto_focus_enabled(checked)
|
||||||
|
debug_log(f"自動聚焦設置已保存: {checked}") # 調試輸出
|
||||||
|
|
||||||
def _on_timeout_enabled_changed(self, enabled: bool) -> None:
|
def _on_timeout_enabled_changed(self, enabled: bool) -> None:
|
||||||
"""超時啟用狀態變更事件處理"""
|
"""超時啟用狀態變更事件處理"""
|
||||||
# 立即保存設定
|
# 立即保存設定
|
||||||
@ -550,6 +562,8 @@ class SettingsTab(QWidget):
|
|||||||
# 更新切換開關文字
|
# 更新切換開關文字
|
||||||
if hasattr(self, 'always_center_switch'):
|
if hasattr(self, 'always_center_switch'):
|
||||||
self.always_center_switch.setText(t('settings.window.alwaysCenter'))
|
self.always_center_switch.setText(t('settings.window.alwaysCenter'))
|
||||||
|
if hasattr(self, 'auto_focus_switch'):
|
||||||
|
self.auto_focus_switch.setText(t('settings.window.autoFocus'))
|
||||||
if hasattr(self, 'timeout_enabled_switch'):
|
if hasattr(self, 'timeout_enabled_switch'):
|
||||||
self.timeout_enabled_switch.setText(t('timeout.enable'))
|
self.timeout_enabled_switch.setText(t('timeout.enable'))
|
||||||
|
|
||||||
@ -585,6 +599,10 @@ class SettingsTab(QWidget):
|
|||||||
always_center = self.config_manager.get_always_center_window()
|
always_center = self.config_manager.get_always_center_window()
|
||||||
self.always_center_switch.setChecked(always_center)
|
self.always_center_switch.setChecked(always_center)
|
||||||
debug_log(f"重新載入視窗定位設置: {always_center}") # 調試輸出
|
debug_log(f"重新載入視窗定位設置: {always_center}") # 調試輸出
|
||||||
|
if hasattr(self, 'auto_focus_switch'):
|
||||||
|
auto_focus = self.config_manager.get_auto_focus_enabled()
|
||||||
|
self.auto_focus_switch.setChecked(auto_focus)
|
||||||
|
debug_log(f"重新載入自動聚焦設置: {auto_focus}") # 調試輸出
|
||||||
|
|
||||||
# 重新載入超時設定
|
# 重新載入超時設定
|
||||||
if hasattr(self, 'timeout_enabled_switch'):
|
if hasattr(self, 'timeout_enabled_switch'):
|
||||||
|
@ -199,6 +199,15 @@ class ConfigManager:
|
|||||||
})
|
})
|
||||||
debug_log(f"超時設置: {'啟用' if enabled else '停用'}, {seconds} 秒")
|
debug_log(f"超時設置: {'啟用' if enabled else '停用'}, {seconds} 秒")
|
||||||
|
|
||||||
|
def get_auto_focus_enabled(self) -> bool:
|
||||||
|
"""獲取是否啟用自動聚焦到輸入框"""
|
||||||
|
return self.get('auto_focus_enabled', True) # 預設啟用
|
||||||
|
|
||||||
|
def set_auto_focus_enabled(self, enabled: bool) -> None:
|
||||||
|
"""設置是否啟用自動聚焦到輸入框"""
|
||||||
|
self.update_partial_config({'auto_focus_enabled': enabled})
|
||||||
|
debug_log(f"自動聚焦設置: {'啟用' if enabled else '停用'}")
|
||||||
|
|
||||||
def reset_settings(self) -> None:
|
def reset_settings(self) -> None:
|
||||||
"""重置所有設定到預設值"""
|
"""重置所有設定到預設值"""
|
||||||
try:
|
try:
|
||||||
|
@ -61,6 +61,15 @@ class FeedbackWindow(QMainWindow):
|
|||||||
# 如果啟用了超時,自動開始倒數計時
|
# 如果啟用了超時,自動開始倒數計時
|
||||||
self.start_timeout_if_enabled()
|
self.start_timeout_if_enabled()
|
||||||
|
|
||||||
|
# 設置定時器在窗口顯示後自動聚焦到輸入框(如果啟用)
|
||||||
|
if self.config_manager.get_auto_focus_enabled():
|
||||||
|
self._focus_timer = QTimer()
|
||||||
|
self._focus_timer.setSingleShot(True)
|
||||||
|
self._focus_timer.timeout.connect(self._auto_focus_input)
|
||||||
|
self._focus_timer.start(300) # 延遲300ms確保窗口和UI元素完全加載
|
||||||
|
else:
|
||||||
|
debug_log("自動聚焦已停用")
|
||||||
|
|
||||||
def _setup_ui(self) -> None:
|
def _setup_ui(self) -> None:
|
||||||
"""設置用戶介面"""
|
"""設置用戶介面"""
|
||||||
self.setWindowTitle(t('app.title'))
|
self.setWindowTitle(t('app.title'))
|
||||||
@ -780,6 +789,47 @@ class FeedbackWindow(QMainWindow):
|
|||||||
"""延遲保存窗口位置(防抖機制的實際執行)"""
|
"""延遲保存窗口位置(防抖機制的實際執行)"""
|
||||||
self._save_window_position()
|
self._save_window_position()
|
||||||
|
|
||||||
|
def _auto_focus_input(self) -> None:
|
||||||
|
"""自動聚焦到輸入框"""
|
||||||
|
try:
|
||||||
|
# 確保窗口已經顯示並激活
|
||||||
|
self.raise_()
|
||||||
|
self.activateWindow()
|
||||||
|
|
||||||
|
# 獲取回饋輸入框(修正邏輯)
|
||||||
|
feedback_input = None
|
||||||
|
|
||||||
|
# 檢查是否有tab_manager
|
||||||
|
if not hasattr(self, 'tab_manager'):
|
||||||
|
debug_log("tab_manager 不存在")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 檢查 feedback_tab(無論是合併模式還是分離模式)
|
||||||
|
if hasattr(self.tab_manager, 'feedback_tab') and self.tab_manager.feedback_tab:
|
||||||
|
if hasattr(self.tab_manager.feedback_tab, 'feedback_input'):
|
||||||
|
feedback_input = self.tab_manager.feedback_tab.feedback_input
|
||||||
|
debug_log("找到feedback_tab中的輸入框")
|
||||||
|
else:
|
||||||
|
debug_log("feedback_tab存在但沒有feedback_input屬性")
|
||||||
|
else:
|
||||||
|
debug_log("沒有找到feedback_tab")
|
||||||
|
|
||||||
|
# 設置焦點到輸入框
|
||||||
|
if feedback_input:
|
||||||
|
feedback_input.setFocus()
|
||||||
|
feedback_input.raise_() # 確保輸入框可見
|
||||||
|
debug_log("已自動聚焦到輸入框")
|
||||||
|
else:
|
||||||
|
debug_log("未找到回饋輸入框,無法自動聚焦")
|
||||||
|
# 打印調試信息
|
||||||
|
if hasattr(self, 'tab_manager'):
|
||||||
|
debug_log(f"tab_manager 屬性: {dir(self.tab_manager)}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
debug_log(f"自動聚焦失敗: {e}")
|
||||||
|
import traceback
|
||||||
|
debug_log(f"詳細錯誤: {traceback.format_exc()}")
|
||||||
|
|
||||||
def closeEvent(self, event) -> None:
|
def closeEvent(self, event) -> None:
|
||||||
"""窗口關閉事件"""
|
"""窗口關閉事件"""
|
||||||
# 最終保存視窗狀態(大小始終保存,位置根據設置決定)
|
# 最終保存視窗狀態(大小始終保存,位置根據設置決定)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user