feat: track settings changes and enforce Chinese UI copy

This commit is contained in:
chengma
2026-07-06 11:32:02 +08:00
parent 26e59c8cea
commit 19eaa794cf
10 changed files with 430 additions and 19 deletions
+47
View File
@@ -27,6 +27,9 @@ class MainWindow(QMainWindow):
)
self.setWindowTitle("cmshopee")
self.resize(1180, 760)
self._settings_tab_index = TAB_TITLES.index("⑤ 设置")
self._last_tab_index = 0
self._reverting_tab_change = False
self.tabs = QTabWidget()
self.tabs.setObjectName("mainTabs")
self.tabs.setStyleSheet(TAB_STYLE)
@@ -82,8 +85,52 @@ class MainWindow(QMainWindow):
widget.refresh_tasks()
def _on_tab_changed(self, index):
if self._reverting_tab_change:
self._last_tab_index = index
self.statusBar().showMessage(f"当前:{self.tabs.tabText(index)}")
return
previous = self._last_tab_index
if previous == self._settings_tab_index and index != previous:
if not self._confirm_leave_settings_tab():
self._reverting_tab_change = True
try:
self.tabs.setCurrentIndex(previous)
finally:
self._reverting_tab_change = False
self._last_tab_index = previous
self.statusBar().showMessage(f"当前:{self.tabs.tabText(previous)}")
return
self._last_tab_index = index
self.statusBar().showMessage(f"当前:{self.tabs.tabText(index)}")
def _settings_tab(self):
return self.tabs.widget(self._settings_tab_index)
def _confirm_leave_settings_tab(self):
settings_tab = self._settings_tab()
if not hasattr(settings_tab, "is_dirty") or not settings_tab.is_dirty():
return True
box = QMessageBox(self)
box.setWindowTitle("未保存更改")
box.setText("⑤ 设置有未保存更改。要先保存再离开吗?")
save_button = box.addButton("保存", QMessageBox.AcceptRole)
discard_button = box.addButton("放弃", QMessageBox.DestructiveRole)
cancel_button = box.addButton("取消", QMessageBox.RejectRole)
box.setDefaultButton(save_button)
box.exec()
clicked = box.clickedButton()
if clicked is save_button:
return bool(settings_tab.save_app_settings())
if clicked is discard_button:
return bool(settings_tab.discard_unsaved_changes())
return False
def closeEvent(self, event):
if self._confirm_leave_settings_tab():
event.accept()
return
event.ignore()
def open_accounts_tab(self):
self.tabs.setCurrentIndex(TAB_TITLES.index("④ 账号管理"))