Add duplicate build feature
This commit is contained in:
@@ -502,6 +502,15 @@ class BuildSettings:
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def duplicate(cls, source: BuildSettings) -> BuildSettings:
|
||||
"""Make a copy of another build."""
|
||||
cls = BuildSettings()
|
||||
cls.unpack(source.pack())
|
||||
cls._uuid = str(uuid.uuid4())
|
||||
cls._name = f"{source.name} 2"
|
||||
return cls
|
||||
|
||||
|
||||
class BuildCollection:
|
||||
"""Core: Build Collection Class
|
||||
|
||||
@@ -116,6 +116,11 @@ class GuiManuscript(NToolDialog):
|
||||
self.tbDel.setStyleSheet(buttonStyle)
|
||||
self.tbDel.clicked.connect(self._deleteSelectedBuild)
|
||||
|
||||
self.tbCopy = NIconToolButton(self, iSz, "copy")
|
||||
self.tbCopy.setToolTip(self.tr("Duplicate Selected Build"))
|
||||
self.tbCopy.setStyleSheet(buttonStyle)
|
||||
self.tbCopy.clicked.connect(self._copySelectedBuild)
|
||||
|
||||
self.tbEdit = NIconToolButton(self, iSz, "edit")
|
||||
self.tbEdit.setToolTip(self.tr("Edit Selected Build"))
|
||||
self.tbEdit.setStyleSheet(buttonStyle)
|
||||
@@ -128,6 +133,7 @@ class GuiManuscript(NToolDialog):
|
||||
self.listToolBox.addStretch(1)
|
||||
self.listToolBox.addWidget(self.tbAdd)
|
||||
self.listToolBox.addWidget(self.tbDel)
|
||||
self.listToolBox.addWidget(self.tbCopy)
|
||||
self.listToolBox.addWidget(self.tbEdit)
|
||||
self.listToolBox.setSpacing(0)
|
||||
|
||||
@@ -291,6 +297,17 @@ class GuiManuscript(NToolDialog):
|
||||
self._openSettingsDialog(build)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _copySelectedBuild(self) -> None:
|
||||
"""Copy the currently selected build settings entry."""
|
||||
if build := self._getSelectedBuild():
|
||||
new = BuildSettings.duplicate(build)
|
||||
self._builds.setBuild(new)
|
||||
self._updateBuildsList()
|
||||
if item := self._buildMap.get(new.buildID):
|
||||
item.setSelected(True)
|
||||
return
|
||||
|
||||
@pyqtSlot("QListWidgetItem*", "QListWidgetItem*")
|
||||
def _updateBuildDetails(self, current: QListWidgetItem, previous: QListWidgetItem) -> None:
|
||||
"""Process change of build selection to update the details."""
|
||||
@@ -460,9 +477,8 @@ class GuiManuscript(NToolDialog):
|
||||
|
||||
def _updateBuildItem(self, build: BuildSettings) -> None:
|
||||
"""Update the entry of a specific build item."""
|
||||
bItem = self._buildMap.get(build.buildID, None)
|
||||
if isinstance(bItem, QListWidgetItem):
|
||||
bItem.setText(build.name)
|
||||
if item := self._buildMap.get(build.buildID):
|
||||
item.setText(build.name)
|
||||
else: # Probably a new item
|
||||
self._updateBuildsList()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user