Search/replace now fully implemented, although only for currently edited document

This commit is contained in:
Veronica K. B. Olsen
2019-10-06 15:36:34 +02:00
parent 3b34408d33
commit d91d77d5ab
5 changed files with 133 additions and 35 deletions
+58 -12
View File
@@ -13,8 +13,9 @@
import logging
import nw
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QFrame, QGridLayout, QLabel, QLineEdit, QPushButton
from PyQt5.QtWidgets import QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, QApplication
from nw.enum import nwDocAction
@@ -27,26 +28,37 @@ class GuiSearchBar(QFrame):
logger.debug("Initialising GuiSearchBar ...")
self.mainConf = nw.CONFIG
self.theParent = theParent
self.mainConf = nw.CONFIG
self.theParent = theParent
self.repVisible = False
self.setContentsMargins(0,0,0,0)
self.mainBox = QGridLayout(self)
self.setLayout(self.mainBox)
self.searchBox = QLineEdit()
self.closeButton = QPushButton(QIcon.fromTheme("edit-delete"),"")
self.searchButton = QPushButton(QIcon.fromTheme("edit-find"),"")
self.searchBox = QLineEdit()
self.replaceBox = QLineEdit()
self.searchLabel = QLabel("Search")
self.replaceLabel = QLabel("Replace")
self.closeButton = QPushButton(QIcon.fromTheme("edit-delete"),"")
self.searchButton = QPushButton(QIcon.fromTheme("edit-find"),"")
self.replaceButton = QPushButton(QIcon.fromTheme("edit-find-replace"),"")
self.closeButton.clicked.connect(self._doClose)
self.searchButton.clicked.connect(self._doSearch)
self.replaceButton.clicked.connect(self._doReplace)
self.searchBox.returnPressed.connect(self._doSearch)
self.replaceBox.returnPressed.connect(self._doSearch)
self.mainBox.addWidget(QLabel(""), 0,0)
self.mainBox.addWidget(QLabel("Search"), 0,1)
self.mainBox.addWidget(self.searchBox, 0,2)
self.mainBox.addWidget(self.searchButton,0,3)
self.mainBox.addWidget(self.closeButton, 0,4)
self.mainBox.addWidget(QLabel(""), 0,0)
self.mainBox.addWidget(self.searchLabel, 0,1)
self.mainBox.addWidget(self.searchBox, 0,2)
self.mainBox.addWidget(self.searchButton, 0,3)
self.mainBox.addWidget(self.closeButton, 0,4)
self.mainBox.addWidget(self.replaceLabel, 1,1)
self.mainBox.addWidget(self.replaceBox, 1,2)
self.mainBox.addWidget(self.replaceButton, 1,3)
self.mainBox.setColumnStretch(0,1)
self.mainBox.setColumnStretch(1,0)
@@ -55,10 +67,19 @@ class GuiSearchBar(QFrame):
self.mainBox.setColumnStretch(4,0)
self.mainBox.setContentsMargins(0,0,0,0)
self.searchBox.setMinimumWidth(180)
self.replaceBox.setMinimumWidth(180)
self._replaceVisible(False)
logger.debug("GuiSearchBar initialisation complete")
return
##
# Get and Set Functions
##
def setSearchText(self, theText):
if not self.isVisible():
@@ -71,19 +92,44 @@ class GuiSearchBar(QFrame):
return True
def setReplaceText(self, theText):
self._replaceVisible(True)
self.replaceBox.setFocus(True)
self.replaceBox.setText(theText)
return True
def getSearchText(self):
return self.searchBox.text()
def getReplaceText(self):
return self.replaceBox.text()
##
# Internal Functions
##
def _doClose(self):
self._replaceVisible(False)
self.setVisible(False)
return
def _doSearch(self):
self.theParent.docEditor.docAction(nwDocAction.GO_NEXT)
modKey = QApplication.keyboardModifiers()
if modKey == Qt.ShiftModifier:
self.theParent.docEditor.docAction(nwDocAction.GO_PREV)
else:
self.theParent.docEditor.docAction(nwDocAction.GO_NEXT)
return
def _doReplace(self):
self.theParent.docEditor.docAction(nwDocAction.REPL_NEXT)
return
def _replaceVisible(self, isVisible):
self.replaceLabel.setVisible(isVisible)
self.replaceBox.setVisible(isVisible)
self.replaceButton.setVisible(isVisible)
self.repVisible = isVisible
return True
# END Class GuiSearchBar