Allow moving split document to trash (#1217)
This commit is contained in:
@@ -192,7 +192,7 @@ class DocSplitter:
|
|||||||
"""An iterator that will write each document in the buffer, and
|
"""An iterator that will write each document in the buffer, and
|
||||||
return its new handle, parent handle, and sibling handle.
|
return its new handle, parent handle, and sibling handle.
|
||||||
"""
|
"""
|
||||||
if self._srcHandle is None:
|
if self._srcHandle is None or self._srcItem is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
pHandle = self._parHandle
|
pHandle = self._parHandle
|
||||||
@@ -224,6 +224,10 @@ class DocSplitter:
|
|||||||
dHandle = self.theProject.newFile(docLabel, pHandle)
|
dHandle = self.theProject.newFile(docLabel, pHandle)
|
||||||
hHandle[hLevel] = dHandle
|
hHandle[hLevel] = dHandle
|
||||||
|
|
||||||
|
newItem = self.theProject.tree[dHandle]
|
||||||
|
newItem.setStatus(self._srcItem.itemStatus)
|
||||||
|
newItem.setImport(self._srcItem.itemImport)
|
||||||
|
|
||||||
outDoc = NWDoc(self.theProject, dHandle)
|
outDoc = NWDoc(self.theProject, dHandle)
|
||||||
status = outDoc.writeDocument("\n".join(docText))
|
status = outDoc.writeDocument("\n".join(docText))
|
||||||
if not status:
|
if not status:
|
||||||
|
|||||||
@@ -103,14 +103,19 @@ class GuiDocSplit(QDialog):
|
|||||||
self.hierarchySwitch = QSwitch(width=2*iPx, height=iPx)
|
self.hierarchySwitch = QSwitch(width=2*iPx, height=iPx)
|
||||||
self.hierarchySwitch.setChecked(docHierarchy)
|
self.hierarchySwitch.setChecked(docHierarchy)
|
||||||
|
|
||||||
|
self.trashLabel = QLabel(self.tr("Move split document to Trash"))
|
||||||
|
self.trashSwitch = QSwitch(width=2*iPx, height=iPx)
|
||||||
|
|
||||||
self.optBox = QGridLayout()
|
self.optBox = QGridLayout()
|
||||||
self.optBox.addWidget(self.folderLabel, 0, 0)
|
self.optBox.addWidget(self.folderLabel, 0, 0)
|
||||||
self.optBox.addWidget(self.folderSwitch, 0, 1)
|
self.optBox.addWidget(self.folderSwitch, 0, 1)
|
||||||
self.optBox.addWidget(self.hierarchyLabel, 1, 0)
|
self.optBox.addWidget(self.hierarchyLabel, 1, 0)
|
||||||
self.optBox.addWidget(self.hierarchySwitch, 1, 1)
|
self.optBox.addWidget(self.hierarchySwitch, 1, 1)
|
||||||
|
self.optBox.addWidget(self.trashLabel, 2, 0)
|
||||||
|
self.optBox.addWidget(self.trashSwitch, 2, 1)
|
||||||
self.optBox.setVerticalSpacing(vSp)
|
self.optBox.setVerticalSpacing(vSp)
|
||||||
self.optBox.setHorizontalSpacing(hSp)
|
self.optBox.setHorizontalSpacing(hSp)
|
||||||
self.optBox.setColumnStretch(2, 1)
|
self.optBox.setColumnStretch(3, 1)
|
||||||
|
|
||||||
# Buttons
|
# Buttons
|
||||||
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||||
@@ -155,11 +160,13 @@ class GuiDocSplit(QDialog):
|
|||||||
spLevel = self.splitLevel.currentData()
|
spLevel = self.splitLevel.currentData()
|
||||||
intoFolder = self.folderSwitch.isChecked()
|
intoFolder = self.folderSwitch.isChecked()
|
||||||
docHierarchy = self.hierarchySwitch.isChecked()
|
docHierarchy = self.hierarchySwitch.isChecked()
|
||||||
|
moveToTrash = self.trashSwitch.isChecked()
|
||||||
|
|
||||||
self._data["spLevel"] = spLevel
|
self._data["spLevel"] = spLevel
|
||||||
self._data["headerList"] = headerList
|
self._data["headerList"] = headerList
|
||||||
self._data["intoFolder"] = intoFolder
|
self._data["intoFolder"] = intoFolder
|
||||||
self._data["docHierarchy"] = docHierarchy
|
self._data["docHierarchy"] = docHierarchy
|
||||||
|
self._data["moveToTrash"] = moveToTrash
|
||||||
|
|
||||||
pOptions = self.theProject.options
|
pOptions = self.theProject.options
|
||||||
pOptions.setValue("GuiDocSplit", "spLevel", spLevel)
|
pOptions.setValue("GuiDocSplit", "spLevel", spLevel)
|
||||||
|
|||||||
@@ -254,6 +254,8 @@ class GuiOutlineToolBar(QToolBar):
|
|||||||
self.addWidget(self.tbColumns)
|
self.addWidget(self.tbColumns)
|
||||||
self.addWidget(stretch)
|
self.addWidget(stretch)
|
||||||
|
|
||||||
|
self.updateTheme()
|
||||||
|
|
||||||
logger.debug("GuiOutlineToolBar initialisation complete")
|
logger.debug("GuiOutlineToolBar initialisation complete")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1612,6 +1612,9 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
self.tr("Could not write document content."), docSplit.getError()
|
self.tr("Could not write document content."), docSplit.getError()
|
||||||
], nwAlert.ERROR)
|
], nwAlert.ERROR)
|
||||||
|
|
||||||
|
if splitData.get("moveToTrash", False):
|
||||||
|
self.moveItemToTrash(tHandle, askFirst=False, flush=True)
|
||||||
|
|
||||||
self.saveTreeOrder()
|
self.saveTreeOrder()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ def testCoreDocTools_DocSplitter(monkeypatch, mockGUI, fncDir, outDir, refDir, m
|
|||||||
docText = "\n\n".join(docData)
|
docText = "\n\n".join(docData)
|
||||||
docRaw = docText.splitlines()
|
docRaw = docText.splitlines()
|
||||||
assert NWDoc(theProject, hSplitDoc).writeDocument(docText) is True
|
assert NWDoc(theProject, hSplitDoc).writeDocument(docText) is True
|
||||||
|
theProject.tree[hSplitDoc].setStatus(C.sFinished)
|
||||||
|
theProject.tree[hSplitDoc].setImport(C.iMain)
|
||||||
|
|
||||||
docSplitter = DocSplitter(theProject, hSplitDoc)
|
docSplitter = DocSplitter(theProject, hSplitDoc)
|
||||||
assert docSplitter._srcItem.isFileType()
|
assert docSplitter._srcItem.isFileType()
|
||||||
@@ -242,6 +244,11 @@ def testCoreDocTools_DocSplitter(monkeypatch, mockGUI, fncDir, outDir, refDir, m
|
|||||||
"000000000002e", # Scene Five is after Scene Four
|
"000000000002e", # Scene Five is after Scene Four
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Check that status and importance has been preserved
|
||||||
|
for rHandle in resDocHandle:
|
||||||
|
assert theProject.tree[rHandle].itemStatus == C.sFinished
|
||||||
|
assert theProject.tree[rHandle].itemImport == C.iMain
|
||||||
|
|
||||||
# Check handling of improper initialisation
|
# Check handling of improper initialisation
|
||||||
docSplitter = DocSplitter(theProject, C.hInvalid)
|
docSplitter = DocSplitter(theProject, C.hInvalid)
|
||||||
assert docSplitter._srcHandle is None
|
assert docSplitter._srcHandle is None
|
||||||
|
|||||||
@@ -837,14 +837,17 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, fncDir, mockRnd, ip
|
|||||||
assert tHandle in theProject.tree
|
assert tHandle in theProject.tree
|
||||||
assert os.path.isfile(os.path.join(prjDir, "content", f"{tHandle}.nwd"))
|
assert os.path.isfile(os.path.join(prjDir, "content", f"{tHandle}.nwd"))
|
||||||
|
|
||||||
# Add to a folder
|
# Add to a folder and move source to trash
|
||||||
splitData["intoFolder"] = True
|
splitData["intoFolder"] = True
|
||||||
|
splitData["moveToTrash"] = True
|
||||||
assert projTree._splitDocument(hSplitDoc) is True
|
assert projTree._splitDocument(hSplitDoc) is True
|
||||||
assert "0000000000029" in theProject.tree # The folder
|
assert "0000000000029" in theProject.tree # The folder
|
||||||
for tHandle in trdSet:
|
for tHandle in trdSet:
|
||||||
assert tHandle in theProject.tree
|
assert tHandle in theProject.tree
|
||||||
assert os.path.isfile(os.path.join(prjDir, "content", f"{tHandle}.nwd"))
|
assert os.path.isfile(os.path.join(prjDir, "content", f"{tHandle}.nwd"))
|
||||||
|
|
||||||
|
assert theProject.tree.isTrash(hSplitDoc) is True
|
||||||
|
|
||||||
# Cancelled by user
|
# Cancelled by user
|
||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr(GuiDocSplit, "result", lambda *a: QDialog.Rejected)
|
mp.setattr(GuiDocSplit, "result", lambda *a: QDialog.Rejected)
|
||||||
|
|||||||
Reference in New Issue
Block a user