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:
"""Set a specific value for a build setting."""
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
return
+13 -7
View File
@@ -80,7 +80,8 @@ class GuiBuildSettings(NToolDialog):
logger.debug("Create: 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.setMinimumSize(700, 400)
@@ -184,6 +185,7 @@ class GuiBuildSettings(NToolDialog):
settings.
"""
logger.debug("Closing: GuiBuildSettings")
self._applyChanges()
self._askToSaveBuild()
self._saveSettings()
event.accept()
@@ -209,6 +211,7 @@ class GuiBuildSettings(NToolDialog):
@pyqtSlot("QAbstractButton*")
def _dialogButtonClicked(self, button: QAbstractButton) -> None:
"""Handle button clicks from the dialog button box."""
self._applyChanges()
role = self.buttonBox.buttonRole(button)
if role == QtRoleApply:
self._emitBuildData()
@@ -216,6 +219,7 @@ class GuiBuildSettings(NToolDialog):
self._emitBuildData()
self.close()
elif role == QtRoleReject:
self._build.resetChangedState()
self.close()
return
@@ -228,10 +232,9 @@ class GuiBuildSettings(NToolDialog):
whether the user wants to save them.
"""
if self._build.changed:
response = SHARED.question(self.tr(
if SHARED.question(self.tr(
"Do you want to save your changes to '{0}'?"
).format(self._build.name))
if response:
).format(self._build.name)):
self._emitBuildData()
self._build.resetChangedState()
return
@@ -246,14 +249,17 @@ class GuiBuildSettings(NToolDialog):
pOptions.setValue("GuiBuildSettings", "treeWidth", treeWidth)
pOptions.setValue("GuiBuildSettings", "filterWidth", filterWidth)
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
def _emitBuildData(self) -> None:
"""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._build.resetChangedState()
return