From d9e3fd7a01441c7ac083fe0f0a8f1cc35057ab88 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 23 Apr 2022 19:34:40 +0200 Subject: [PATCH] Make some minor improvements to how expanded status is saved for items --- novelwriter/gui/projtree.py | 10 ++++++++-- sample/nwProject.nwx | 8 ++++---- tests/reference/guiEditor_Main_Final_nwProject.nwx | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index eadbe5b8..cb59c9ee 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -825,6 +825,7 @@ class GuiProjectTree(QTreeWidget): # is updated accordingly, and update word count pHandle = trItemP.data(self.C_NAME, Qt.UserRole) nwItemS.setParent(pHandle) + trItemP.setExpanded(True) logger.debug("The parent of item '%s' has been changed to '%s'", tHandle, pHandle) mHandles = self.getTreeFromHandle(tHandle) @@ -873,12 +874,17 @@ class GuiProjectTree(QTreeWidget): starting at a given QTreeWidgetItem. """ tHandle = tItem.data(self.C_NAME, Qt.UserRole) + cCount = tItem.childCount() + + # Update tree-related meta data nwItem = self.theProject.projTree[tHandle] - nwItem.setExpanded(tItem.isExpanded()) + nwItem.setExpanded(tItem.isExpanded() and cCount > 0) nwItem.setOrder(tIndex) + theList.append(tHandle) - for i in range(tItem.childCount()): + for i in range(cCount): self._scanChildren(theList, tItem.child(i), i) + return theList def _addTreeItem(self, nwItem, nHandle=None): diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 3a012406..406fa423 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1323 + 1327 207 - 66237 + 66285 False @@ -74,7 +74,7 @@ Chapter One - + Making a Scene diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index e29290ca..c4ba847c 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -85,7 +85,7 @@ New Note - + Trash