From 724e597d9cffe87265591fafe7a1809081af6df2 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 30 May 2020 15:34:28 +0200 Subject: [PATCH] Added some extra checks for deleting files when the file is brand new, and updated the test to check it works --- nw/core/project.py | 18 +++++++++++------- nw/gui/elements/doctree.py | 12 ++++++------ tests/reference/gui/1_nwProject.nwx | 13 ++++++++++--- tests/test_gui.py | 9 +++++++++ 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/nw/core/project.py b/nw/core/project.py index 517e10ef..be62ffae 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -152,15 +152,19 @@ class NWProject(): self.projTree.append(None, pHandle, newItem) return newItem.itemHandle - def addTrash(self): + def trashFolder(self): """Add the special trash root folder to the project. """ - newItem = NWItem(self) - newItem.setName("Trash") - newItem.setType(nwItemType.TRASH) - newItem.setClass(nwItemClass.TRASH) - self.projTree.append(None, None, newItem) - return newItem.itemHandle + trashHandle = self.projTree.trashRoot() + if trashHandle is None: + newItem = NWItem(self) + newItem.setName("Trash") + newItem.setType(nwItemType.TRASH) + newItem.setClass(nwItemClass.TRASH) + self.projTree.append(None, None, newItem) + return newItem.itemHandle + + return trashHandle ## # Project Methods diff --git a/nw/gui/elements/doctree.py b/nw/gui/elements/doctree.py index 02db9bde..6da9e5d7 100644 --- a/nw/gui/elements/doctree.py +++ b/nw/gui/elements/doctree.py @@ -200,8 +200,8 @@ class GuiDocTree(QTreeWidget): def revealTreeItem(self, tHandle): """Reveal a newly added project item in the project tree. """ - nwItem = self.theProject.projTree[tHandle] - trItem = self._addTreeItem(nwItem) + nwItem = self.theProject.projTree[tHandle] + trItem = self._addTreeItem(nwItem) pHandle = nwItem.parHandle if pHandle is not None and pHandle in self.theMap.keys(): self.theMap[pHandle].setExpanded(True) @@ -608,15 +608,15 @@ class GuiDocTree(QTreeWidget): """Adds the trash root folder if it doesn't already exist in the project tree. """ - trashHandle = self.theProject.projTree.trashRoot() + trashHandle = self.theProject.trashFolder() if trashHandle is None: - self.theProject.addTrash() + return None + trItem = self._getTreeItem(trashHandle) + if trItem is None: trItem = self._addTreeItem( self.theProject.projTree[trashHandle] ) trItem.setExpanded(True) - else: - trItem = self._getTreeItem(trashHandle) return trItem def _addOrphanedRoot(self): diff --git a/tests/reference/gui/1_nwProject.nwx b/tests/reference/gui/1_nwProject.nwx index a09a089f..ab090c92 100644 --- a/tests/reference/gui/1_nwProject.nwx +++ b/tests/reference/gui/1_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -9,7 +9,7 @@ True True 31489056e0916 - 31489056e0916 + None 86 @@ -35,7 +35,7 @@ Main - + Novel ROOT @@ -119,5 +119,12 @@ 1 68 + + Trash + TRASH + TRASH + None + True + diff --git a/tests/test_gui.py b/tests/test_gui.py index c638e77f..e006cabb 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -235,6 +235,15 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp): assert nwGUI.closeDocViewer() qtbot.wait(stepDelay) + # Check a Quick Create and Delete + assert nwGUI.treeView.newTreeItem(nwItemType.FILE, None) + newHandle = nwGUI.treeView.getSelectedHandle() + assert nwGUI.theProject.projTree["031b4af5197ec"] is not None + assert nwGUI.treeView.deleteItem() + assert nwGUI.treeView.setSelectedHandle(newHandle) + assert nwGUI.treeView.deleteItem() + assert nwGUI.saveProject() + # Check the files refFile = path.join(nwTempGUI, "nwProject.nwx") assert cmpFiles(refFile, path.join(nwRef, "gui", "1_nwProject.nwx"), [2])