Searching through files can now loop back to first file again

This commit is contained in:
Veronica K. B. Olsen
2020-06-17 19:29:25 +02:00
parent ad21c6e3a4
commit 32052b1bc3
2 changed files with 16 additions and 8 deletions
+5 -3
View File
@@ -1168,15 +1168,17 @@ class GuiDocEditor(QTextEdit):
searchFor = self.docSearch.getSearchText()
wasFound = self.find(searchFor, findOpt)
if not wasFound:
if self.docSearch.doLoop:
if self.docSearch.doNextFile and not isBackward:
self.theParent.openNextDocument(
self.theHandle, wrapAround=self.docSearch.doLoop
)
elif 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
+11 -5
View File
@@ -476,28 +476,34 @@ class GuiMain(QMainWindow):
return False
return True
def openNextDocument(self, tHandle):
def openNextDocument(self, tHandle, wrapAround=False):
"""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
nHandle = None # The next handle after tHandle
fHandle = None # The first file handle we encounter
foundIt = False # We've found tHandle, pick the next we see
for tItem in self.theProject.projTree:
if tItem is None:
continue
if tItem.itemType != nwItemType.FILE:
continue
if fHandle is None:
fHandle = tItem.itemHandle
if tItem.itemHandle == tHandle:
goNext = True
elif goNext:
foundIt = True
elif foundIt:
nHandle = tItem.itemHandle
break
if nHandle is not None:
self.openDocument(nHandle, tLine=0)
return True
elif wrapAround:
self.openDocument(fHandle, tLine=0)
return False
return False