Automatically select the first build if no builds are selected in the build tool
This commit is contained in:
@@ -330,15 +330,13 @@ class GuiManuscript(QDialog):
|
|||||||
def _buildManuscript(self):
|
def _buildManuscript(self):
|
||||||
"""Open the build dialog and build the manuscript."""
|
"""Open the build dialog and build the manuscript."""
|
||||||
build = self._getSelectedBuild()
|
build = self._getSelectedBuild()
|
||||||
if build is None:
|
if isinstance(build, BuildSettings):
|
||||||
return
|
dlgBuild = GuiManuscriptBuild(self, self.mainGui, build)
|
||||||
|
dlgBuild.exec_()
|
||||||
|
|
||||||
dlgBuild = GuiManuscriptBuild(self, self.mainGui, build)
|
# After the build is done, save build settings changes
|
||||||
dlgBuild.exec_()
|
if build.changed:
|
||||||
|
self._builds.setBuild(build)
|
||||||
# After the build is done, save build settings changes
|
|
||||||
if build.changed:
|
|
||||||
self._builds.setBuild(build)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -376,10 +374,13 @@ class GuiManuscript(QDialog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _getSelectedBuild(self) -> BuildSettings | None:
|
def _getSelectedBuild(self) -> BuildSettings | None:
|
||||||
"""Get the currently selected build."""
|
"""Get the currently selected build. If none are selected,
|
||||||
bItems = self.buildList.selectedItems()
|
automatically select the first one.
|
||||||
if bItems:
|
"""
|
||||||
build = self._builds.getBuild(bItems[0].data(self.D_KEY))
|
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):
|
if isinstance(build, BuildSettings):
|
||||||
return build
|
return build
|
||||||
return None
|
return None
|
||||||
@@ -634,7 +635,7 @@ class _PreviewWidget(QTextBrowser):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
strBuildTime = self.tr("Unknown")
|
strBuildTime = self.tr("Unknown")
|
||||||
text = "{0} {1}".format(self.tr("Built"), strBuildTime)
|
text = "{0}: {1}".format(self.tr("Built"), strBuildTime)
|
||||||
if self._buildName:
|
if self._buildName:
|
||||||
text = "<b>{0}</b><br>{1}".format(self._buildName, text)
|
text = "<b>{0}</b><br>{1}".format(self._buildName, text)
|
||||||
self.ageLabel.setText(text)
|
self.ageLabel.setText(text)
|
||||||
|
|||||||
@@ -168,11 +168,12 @@ def testManuscript_Features(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath:
|
|||||||
# ========
|
# ========
|
||||||
|
|
||||||
# No build selected
|
# No build selected
|
||||||
manus.buildList.clearSelection()
|
manus.buildList.clear()
|
||||||
manus.btnPreview.click()
|
manus.btnPreview.click()
|
||||||
qtbot.wait(200) # Should be enough to run the build
|
qtbot.wait(200) # Should be enough to run the build
|
||||||
assert manus.docPreview.toPlainText().strip() == ""
|
assert manus.docPreview.toPlainText().strip() == ""
|
||||||
assert cacheFile.exists() is False
|
assert cacheFile.exists() is False
|
||||||
|
manus._updateBuildsList()
|
||||||
|
|
||||||
# Preview the first, but fail to save cache
|
# Preview the first, but fail to save cache
|
||||||
manus.buildList.setCurrentRow(0)
|
manus.buildList.setCurrentRow(0)
|
||||||
@@ -207,12 +208,6 @@ def testManuscript_Features(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath:
|
|||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr("novelwriter.tools.manusbuild.GuiManuscriptBuild.exec_", lambda *a: None)
|
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.buildList.setCurrentRow(0)
|
||||||
manus.btnBuild.click()
|
manus.btnBuild.click()
|
||||||
for obj in manus.children():
|
for obj in manus.children():
|
||||||
|
|||||||
Reference in New Issue
Block a user