From ad21c6e3a4a63d9a0420f3ee6618c069192f6d56 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 17 Jun 2020 19:16:32 +0200 Subject: [PATCH] Continue search in next file is now working --- nw/gui/build.py | 2 +- nw/gui/doceditor.py | 17 ++++++++++------- nw/gui/projtree.py | 39 ++++++++++++++++++++++++++++++++------- nw/guimain.py | 25 +++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/nw/gui/build.py b/nw/gui/build.py index 70ea0703..51a9dd68 100644 --- a/nw/gui/build.py +++ b/nw/gui/build.py @@ -459,7 +459,7 @@ class GuiBuildNovel(QDialog): makeHtml.setStyles(not noStyling) # Make sure the tree order is correct - self.theParent.treeView.saveTreeOrder() + self.theParent.treeView.flushTreeOrder() self.buildProgress.setMaximum(len(self.theProject.projTree)) self.buildProgress.setValue(0) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 950fef73..382fc123 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -1167,13 +1167,16 @@ class GuiDocEditor(QTextEdit): searchFor = self.docSearch.getSearchText() wasFound = self.find(searchFor, findOpt) - if not wasFound and self.docSearch.doLoop: - theCursor = self.textCursor() - theCursor.movePosition( - QTextCursor.End if isBackward else QTextCursor.Start - ) - self.setTextCursor(theCursor) - self.find(searchFor, findOpt) + if not wasFound: + if self.docSearch.doLoop: + theCursor = self.textCursor() + theCursor.movePosition( + QTextCursor.End if isBackward else QTextCursor.Start + ) + self.setTextCursor(theCursor) + self.find(searchFor, findOpt) + elif self.docSearch.doNextFile: + self.theParent.openNextDocument(self.theHandle) return diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index 02e850ad..236b9f90 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -60,8 +60,9 @@ class GuiProjectTree(QTreeWidget): self.theProject = theParent.theProject # Tree Settings - self.theMap = None - self.orphRoot = None + self.theMap = None + self.orphRoot = None + self.treeChanged = False self.ctxMenu = GuiProjectTreeMenu(self) self.clearTree() @@ -256,7 +257,7 @@ class GuiProjectTree(QTreeWidget): pItem.insertChild(nIndex, cItem) self.clearSelection() cItem.setSelected(True) - self.theProject.setProjectChanged(True) + self._setTreeChanged(True) else: return False return True @@ -276,6 +277,16 @@ class GuiProjectTree(QTreeWidget): self.theProject.setTreeOrder(theList) return True + def flushTreeOrder(self): + """Calls saveTreeOrder if there are unsaved changes, otherwise + does nothing. + """ + if self.treeChanged: + logger.verbose("Flushing project tree to project class") + self.saveTreeOrder() + self._setTreeChanged(False) + return + def getTreeFromHandle(self, tHandle): """Recursively return all the children items starting from a given item handle. @@ -332,6 +343,9 @@ class GuiProjectTree(QTreeWidget): continue self.deleteItem(tHandle, True) + if nTrash > 0: + self._setTreeChanged(True) + return True def deleteItem(self, tHandle=None, alreadyAsked=False, askForTrash=False): @@ -413,7 +427,7 @@ class GuiProjectTree(QTreeWidget): trItemT.addChild(trItemC) nwItemS.setParent(self.theProject.projTree.trashRoot()) - self.theProject.setProjectChanged(True) + self._setTreeChanged(True) self.theParent.theIndex.deleteHandle(tHandle) elif nwItemS.itemType == nwItemType.FOLDER: @@ -436,7 +450,7 @@ class GuiProjectTree(QTreeWidget): if trItemS.childCount() == 0: self.takeTopLevelItem(tIndex) self.theParent.mainMenu.setAvailableRoot() - self.theProject.setProjectChanged(True) + self._setTreeChanged(True) else: self.makeAlert("Cannot delete root folder. It is not empty.", nwAlert.ERROR) return False @@ -732,6 +746,8 @@ class GuiProjectTree(QTreeWidget): elif nwItem.itemType == nwItemType.TRASH: newItem.setIcon(self.C_NAME, self.theTheme.getIcon(nwLabels.CLASS_ICON[tClass])) + self._setTreeChanged(True) + return newItem def _addTrashRoot(self): @@ -747,6 +763,7 @@ class GuiProjectTree(QTreeWidget): self.theProject.projTree[trashHandle] ) trItem.setExpanded(True) + self._setTreeChanged(True) return trItem def _addOrphanedRoot(self): @@ -793,7 +810,7 @@ class GuiProjectTree(QTreeWidget): nwItemS.setParent(pHandle) self.propagateCount(tHandle, wC) self.setTreeItemValues(tHandle) - self.theProject.setProjectChanged(True) + self._setTreeChanged(True) logger.debug("The parent of item %s has been changed to %s" % (tHandle,pHandle)) @@ -815,7 +832,15 @@ class GuiProjectTree(QTreeWidget): pHandle = trItemP.data(self.C_NAME, Qt.UserRole) nwItemS.setParent(pHandle) self.setTreeItemValues(tHandle) - self.theProject.setProjectChanged(True) + self._setTreeChanged(True) + return + + def _setTreeChanged(self, theState): + """Set the tree change flag, and propagate to the project. + """ + self.treeChanged = theState + if theState: + self.theProject.setProjectChanged(True) return # END Class GuiProjectTree diff --git a/nw/guimain.py b/nw/guimain.py index 5bfad545..1116f9aa 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -476,6 +476,31 @@ class GuiMain(QMainWindow): return False return True + def openNextDocument(self, tHandle): + """Opens the next document in the project tree, following the + document with the given handle. Stops when reaching the end. + """ + if self.hasProject: + self.treeView.flushTreeOrder() + nHandle = None + goNext = False + for tItem in self.theProject.projTree: + if tItem is None: + continue + if tItem.itemType != nwItemType.FILE: + continue + if tItem.itemHandle == tHandle: + goNext = True + elif goNext: + nHandle = tItem.itemHandle + break + + if nHandle is not None: + self.openDocument(nHandle, tLine=0) + return True + + return False + def saveDocument(self): """Save the current documents. """