--- a/eric7/UI/FindFileWidget.py Fri Apr 29 11:40:00 2022 +0200 +++ b/eric7/UI/FindFileWidget.py Fri Apr 29 15:40:17 2022 +0200 @@ -14,7 +14,8 @@ from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QPoint, QUrl from PyQt6.QtGui import QCursor, QDesktopServices, QImageReader from PyQt6.QtWidgets import ( - QWidget, QApplication, QMenu, QTreeWidgetItem, QComboBox + QWidget, QApplication, QMenu, QTreeWidgetItem, QComboBox, QDialog, + QDialogButtonBox, QVBoxLayout ) from EricWidgets.EricApplication import ericApp @@ -89,16 +90,20 @@ self.stopButton.setEnabled(False) self.stopButton.clicked.connect(self.__stopSearch) self.stopButton.setIcon(UI.PixmapCache.getIcon("stopLoading")) + self.stopButton.setAutoDefault(False) self.findButton.setEnabled(False) self.findButton.clicked.connect(self.__doSearch) self.findButton.setIcon(UI.PixmapCache.getIcon("find")) + self.findButton.setAutoDefault(False) self.clearButton.setEnabled(False) self.clearButton.clicked.connect(self.__clearResults) self.clearButton.setIcon(UI.PixmapCache.getIcon("clear")) + self.clearButton.setAutoDefault(False) self.replaceButton.setIcon(UI.PixmapCache.getIcon("editReplace")) + self.replaceButton.setAutoDefault(False) self.modeToggleButton.clicked.connect(self.__toggleReplaceMode) @@ -898,4 +903,96 @@ cb = QApplication.clipboard() cb.setText(fn) -# TODO: add separate dialog variant + +class FindFileDialog(QDialog): + """ + Class implementing a dialog to search for text in files and replace it + with some other text. + + The occurrences found are displayed in a tree showing the file name, + the line number and the text found. The file will be opened upon a double + click onto the respective entry of the list. If the widget is in replace + mode the line below shows the text after replacement. Replacements can + be authorized by ticking them on. Pressing the replace button performs + all ticked replacement operations. + + @signal sourceFile(str, int, str, int, int) emitted to open a source file + at a specificline + @signal designerFile(str) emitted to open a Qt-Designer file + @signal linguistFile(str) emitted to open a Qt-Linguist (*.ts) file + @signal trpreview([str]) emitted to preview Qt-Linguist (*.qm) files + @signal pixmapFile(str) emitted to open a pixmap file + @signal svgFile(str) emitted to open a SVG file + @signal umlFile(str) emitted to open an eric UML file + """ + sourceFile = pyqtSignal(str, int, str, int, int) + designerFile = pyqtSignal(str) + linguistFile = pyqtSignal(str) + trpreview = pyqtSignal(list) + pixmapFile = pyqtSignal(str) + svgFile = pyqtSignal(str) + umlFile = pyqtSignal(str) + + def __init__(self, project, parent=None): + """ + Constructor + + @param project reference to the project object + @type Project + @param parent parent widget of this dialog (defaults to None) + @type QWidget (optional) + """ + super().__init__(parent) + self.setWindowFlags(Qt.WindowType.Window) + + self.__layout = QVBoxLayout() + + self.__findWidget = FindFileWidget(project, self) + self.__layout.addWidget(self.__findWidget) + + self.__buttonBox = QDialogButtonBox( + QDialogButtonBox.StandardButton.Close, + Qt.Orientation.Horizontal, + self + ) + self.__buttonBox.button( + QDialogButtonBox.StandardButton.Close).setAutoDefault(False) + self.__layout.addWidget(self.__buttonBox) + + self.setLayout(self.__layout) + self.resize(600, 800) + + # connect the widgets + self.__findWidget.sourceFile.connect(self.sourceFile) + self.__findWidget.designerFile.connect(self.designerFile) + self.__findWidget.linguistFile.connect(self.linguistFile) + self.__findWidget.trpreview.connect(self.trpreview) + self.__findWidget.pixmapFile.connect(self.pixmapFile) + self.__findWidget.svgFile.connect(self.svgFile) + self.__findWidget.umlFile.connect(self.umlFile) + + self.__buttonBox.accepted.connect(self.accept) + self.__buttonBox.rejected.connect(self.reject) + + def activate(self, replaceMode=False, txt="", searchDir="", + openFiles=False): + """ + Public method to activate the dialog with a given mode, a text + to search for and some search parameters. + + @param replaceMode flag indicating replacement mode (defaults to False) + @type bool (optional) + @param txt text to be searched for (defaults to "") + @type str (optional) + @param searchDir directory to search in (defaults to "") + @type str (optional) + @param openFiles flag indicating to operate on open files only + (defaults to False) + @type bool (optional) + """ + self.__findWidget.activate(replaceMode=replaceMode, txt=txt, + searchDir=searchDir, openFiles=openFiles) + + self.raise_() + self.activateWindow() + self.show()