Automatically select the first build if no builds are selected in the build tool

This commit is contained in:
Veronica Berglyd Olsen
2023-08-06 22:27:15 +02:00
parent 61836c8c04
commit 4951e4f8fe
2 changed files with 16 additions and 20 deletions
+14 -13
View File
@@ -330,15 +330,13 @@ class GuiManuscript(QDialog):
def _buildManuscript(self):
"""Open the build dialog and build the manuscript."""
build = self._getSelectedBuild()
if build is None:
return
if isinstance(build, BuildSettings):
dlgBuild = GuiManuscriptBuild(self, self.mainGui, build)
dlgBuild.exec_()
dlgBuild = GuiManuscriptBuild(self, self.mainGui, build)
dlgBuild.exec_()
# After the build is done, save build settings changes
if build.changed:
self._builds.setBuild(build)
# After the build is done, save build settings changes
if build.changed:
self._builds.setBuild(build)
return
@@ -376,10 +374,13 @@ class GuiManuscript(QDialog):
return
def _getSelectedBuild(self) -> BuildSettings | None:
"""Get the currently selected build."""
bItems = self.buildList.selectedItems()
if bItems:
build = self._builds.getBuild(bItems[0].data(self.D_KEY))
"""Get the currently selected build. If none are selected,
automatically select the first one.
"""
items = self.buildList.selectedItems()
item = items[0] if items else self.buildList.item(0)
if item:
build = self._builds.getBuild(item.data(self.D_KEY))
if isinstance(build, BuildSettings):
return build
return None
@@ -634,7 +635,7 @@ class _PreviewWidget(QTextBrowser):
)
else:
strBuildTime = self.tr("Unknown")
text = "{0} {1}".format(self.tr("Built"), strBuildTime)
text = "{0}: {1}".format(self.tr("Built"), strBuildTime)
if self._buildName:
text = "<b>{0}</b><br>{1}".format(self._buildName, text)
self.ageLabel.setText(text)
+2 -7
View File
@@ -168,11 +168,12 @@ def testManuscript_Features(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath:
# ========
# No build selected
manus.buildList.clearSelection()
manus.buildList.clear()
manus.btnPreview.click()
qtbot.wait(200) # Should be enough to run the build
assert manus.docPreview.toPlainText().strip() == ""
assert cacheFile.exists() is False
manus._updateBuildsList()
# Preview the first, but fail to save cache
manus.buildList.setCurrentRow(0)
@@ -207,12 +208,6 @@ def testManuscript_Features(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath:
with monkeypatch.context() as mp:
mp.setattr("novelwriter.tools.manusbuild.GuiManuscriptBuild.exec_", lambda *a: None)
# With no selection, no dialog should be created
manus.btnBuild.click()
for obj in manus.children():
assert not isinstance(obj, GuiManuscriptBuild)
# With a selection, there should be one
manus.buildList.setCurrentRow(0)
manus.btnBuild.click()
for obj in manus.children():