From fdd9c58235d02dce07a2365e954a09602f382578 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sun, 19 May 2019 22:20:54 +0200 Subject: [PATCH] Document tree is now refreshed when status colours change --- nw/gui/doctree.py | 8 +++----- nw/gui/projecteditor.py | 12 ++++++++---- nw/gui/winmain.py | 12 ++++++++---- nw/project/project.py | 7 +++++++ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/nw/gui/doctree.py b/nw/gui/doctree.py index e0f066ad..5ff18107 100644 --- a/nw/gui/doctree.py +++ b/nw/gui/doctree.py @@ -229,7 +229,7 @@ class GuiDocTree(QTreeWidget): trItemP.takeChild(tIndex) self.clearSelection() trItemP.setSelected(True) - self.theProject.setProjectChanged(True) + self.theProject.deleteItem(tHandle) else: self.makeAlert(["Cannot delete folder.","It is not empty."], nwAlert.ERROR) return @@ -261,12 +261,10 @@ class GuiDocTree(QTreeWidget): tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout] iStatus = nwItem.itemStatus if tClass == nwItemClass.NOVEL: - if iStatus is None: - iStatus = self.theProject.statusItems.checkEntry(iStatus) + iStatus = self.theProject.statusItems.checkEntry(iStatus) # Make sure it's a valid index flagIcon = self.theParent.statusIcons[iStatus] else: - if iStatus is None: - iStatus = self.theProject.importItems.checkEntry(iStatus) + iStatus = self.theProject.importItems.checkEntry(iStatus) # Make sure it's a valid index flagIcon = self.theParent.importIcons[iStatus] trItem.setText(self.C_NAME, tName) diff --git a/nw/gui/projecteditor.py b/nw/gui/projecteditor.py index 6f5556a2..d5e41a77 100644 --- a/nw/gui/projecteditor.py +++ b/nw/gui/projecteditor.py @@ -82,10 +82,14 @@ class GuiProjectEditor(QDialog): self.theProject.setBookTitle(bookTitle) self.theProject.setBookAuthors(bookAuthors) - statusCol = self.tabStatus.getNewList() - importCol = self.tabImport.getNewList() - self.theProject.setStatusColours(statusCol) - self.theProject.setImportColours(importCol) + if self.tabStatus.colChanged: + statusCol = self.tabStatus.getNewList() + self.theProject.setStatusColours(statusCol) + if self.tabImport.colChanged: + importCol = self.tabImport.getNewList() + self.theProject.setImportColours(importCol) + if self.tabStatus.colChanged or self.tabImport.colChanged: + self.theParent.rebuildTree() self.close() diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index 9369569a..20a0aa50 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -184,12 +184,9 @@ class GuiMain(QMainWindow): projFile = self.openProjectDialog() if projFile is None: return False - self.treeView.clearTree() self.theProject.openProject(projFile) - self.treeView.buildTree() self._setWindowTitle(self.theProject.projName) - self._makeStatusIcons() - self._makeImportIcons() + self.rebuildTree() self.docEditor.setPwl(path.join(self.theProject.projMeta,"wordlist.txt")) self.docEditor.setSpellCheck(self.theProject.spellCheck) self.mainMenu.updateMenu() @@ -300,6 +297,13 @@ class GuiMain(QMainWindow): return + def rebuildTree(self): + self._makeStatusIcons() + self._makeImportIcons() + self.treeView.clearTree() + self.treeView.buildTree() + return + ## # Main Dialogs ## diff --git a/nw/project/project.py b/nw/project/project.py index c607763d..2d75f1b7 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -430,6 +430,13 @@ class NWProject(): # Class Methods ## + def deleteItem(self, tHandle): + """This only removed the item from the order list, but not from the project tree. + """ + self.treeOrder.remove(tHandle) + self.setProjectChanged(True) + return True + def findRootItem(self, theClass): for aRoot in self.treeRoots: if theClass == self.projTree[aRoot].itemClass: