Use a copy of the build settings for the build settings dialog (#2350)

This commit is contained in:
Veronica Berglyd Olsen
2025-05-20 21:16:34 +02:00
parent e7e0d6bf2b
commit 6b4aac0235
2 changed files with 14 additions and 8 deletions
+1 -1
View File
@@ -390,7 +390,7 @@ class BuildSettings:
def setValue(self, key: str, value: T_BuildValue) -> None: def setValue(self, key: str, value: T_BuildValue) -> None:
"""Set a specific value for a build setting.""" """Set a specific value for a build setting."""
if (d := SETTINGS_TEMPLATE.get(key)) and len(d) == 2 and isinstance(value, d[0]): if (d := SETTINGS_TEMPLATE.get(key)) and len(d) == 2 and isinstance(value, d[0]):
self._changed = value != self._settings[key] self._changed |= (value != self._settings[key])
self._settings[key] = value self._settings[key] = value
return return
+13 -7
View File
@@ -80,7 +80,8 @@ class GuiBuildSettings(NToolDialog):
logger.debug("Create: GuiBuildSettings") logger.debug("Create: GuiBuildSettings")
self.setObjectName("GuiBuildSettings") self.setObjectName("GuiBuildSettings")
self._build = build # Make a copy of the build object
self._build = BuildSettings.fromDict(build.pack())
self.setWindowTitle(self.tr("Manuscript Build Settings")) self.setWindowTitle(self.tr("Manuscript Build Settings"))
self.setMinimumSize(700, 400) self.setMinimumSize(700, 400)
@@ -184,6 +185,7 @@ class GuiBuildSettings(NToolDialog):
settings. settings.
""" """
logger.debug("Closing: GuiBuildSettings") logger.debug("Closing: GuiBuildSettings")
self._applyChanges()
self._askToSaveBuild() self._askToSaveBuild()
self._saveSettings() self._saveSettings()
event.accept() event.accept()
@@ -209,6 +211,7 @@ class GuiBuildSettings(NToolDialog):
@pyqtSlot("QAbstractButton*") @pyqtSlot("QAbstractButton*")
def _dialogButtonClicked(self, button: QAbstractButton) -> None: def _dialogButtonClicked(self, button: QAbstractButton) -> None:
"""Handle button clicks from the dialog button box.""" """Handle button clicks from the dialog button box."""
self._applyChanges()
role = self.buttonBox.buttonRole(button) role = self.buttonBox.buttonRole(button)
if role == QtRoleApply: if role == QtRoleApply:
self._emitBuildData() self._emitBuildData()
@@ -216,6 +219,7 @@ class GuiBuildSettings(NToolDialog):
self._emitBuildData() self._emitBuildData()
self.close() self.close()
elif role == QtRoleReject: elif role == QtRoleReject:
self._build.resetChangedState()
self.close() self.close()
return return
@@ -228,10 +232,9 @@ class GuiBuildSettings(NToolDialog):
whether the user wants to save them. whether the user wants to save them.
""" """
if self._build.changed: if self._build.changed:
response = SHARED.question(self.tr( if SHARED.question(self.tr(
"Do you want to save your changes to '{0}'?" "Do you want to save your changes to '{0}'?"
).format(self._build.name)) ).format(self._build.name)):
if response:
self._emitBuildData() self._emitBuildData()
self._build.resetChangedState() self._build.resetChangedState()
return return
@@ -246,14 +249,17 @@ class GuiBuildSettings(NToolDialog):
pOptions.setValue("GuiBuildSettings", "treeWidth", treeWidth) pOptions.setValue("GuiBuildSettings", "treeWidth", treeWidth)
pOptions.setValue("GuiBuildSettings", "filterWidth", filterWidth) pOptions.setValue("GuiBuildSettings", "filterWidth", filterWidth)
pOptions.saveSettings() pOptions.saveSettings()
return
def _applyChanges(self) -> None:
"""Apply all settings changes to the build object."""
self._build.setName(self.editBuildName.text())
self.optTabHeadings.saveContent()
self.optTabFormatting.saveContent()
return return
def _emitBuildData(self) -> None: def _emitBuildData(self) -> None:
"""Assemble the build data and emit the signal.""" """Assemble the build data and emit the signal."""
self._build.setName(self.editBuildName.text())
self.optTabHeadings.saveContent()
self.optTabFormatting.saveContent()
self.newSettingsReady.emit(self._build) self.newSettingsReady.emit(self._build)
self._build.resetChangedState() self._build.resetChangedState()
return return