eric6/UI/FindFileDialog.py

changeset 7264
bedbe458d792
parent 7229
53054eb5b15a
child 7360
9190402e4505
equal deleted inserted replaced
7263:c1af2e327675 7264:bedbe458d792
11 import os 11 import os
12 import re 12 import re
13 13
14 from PyQt5.QtCore import pyqtSignal, Qt, pyqtSlot 14 from PyQt5.QtCore import pyqtSignal, Qt, pyqtSlot
15 from PyQt5.QtGui import QCursor 15 from PyQt5.QtGui import QCursor
16 from PyQt5.QtWidgets import QDialog, QApplication, QMenu, QDialogButtonBox, \ 16 from PyQt5.QtWidgets import (
17 QTreeWidgetItem, QComboBox 17 QDialog, QApplication, QMenu, QDialogButtonBox, QTreeWidgetItem, QComboBox
18 )
18 19
19 from E5Gui.E5Application import e5App 20 from E5Gui.E5Application import e5App
20 from E5Gui import E5MessageBox 21 from E5Gui import E5MessageBox
21 from E5Gui.E5PathPicker import E5PathPickerModes 22 from E5Gui.E5PathPicker import E5PathPickerModes
22 23
64 self.dirPicker.setSizeAdjustPolicy( 65 self.dirPicker.setSizeAdjustPolicy(
65 QComboBox.AdjustToMinimumContentsLength) 66 QComboBox.AdjustToMinimumContentsLength)
66 67
67 self.__replaceMode = replaceMode 68 self.__replaceMode = replaceMode
68 69
69 self.stopButton = \ 70 self.stopButton = self.buttonBox.addButton(
70 self.buttonBox.addButton(self.tr("Stop"), 71 self.tr("Stop"), QDialogButtonBox.ActionRole)
71 QDialogButtonBox.ActionRole)
72 self.stopButton.setEnabled(False) 72 self.stopButton.setEnabled(False)
73 73
74 self.findButton = \ 74 self.findButton = self.buttonBox.addButton(
75 self.buttonBox.addButton(self.tr("Find"), 75 self.tr("Find"), QDialogButtonBox.ActionRole)
76 QDialogButtonBox.ActionRole)
77 self.findButton.setEnabled(False) 76 self.findButton.setEnabled(False)
78 self.findButton.setDefault(True) 77 self.findButton.setDefault(True)
79 78
80 if self.__replaceMode: 79 if self.__replaceMode:
81 self.replaceButton.setEnabled(False) 80 self.replaceButton.setEnabled(False)
263 262
264 def __enableFindButton(self): 263 def __enableFindButton(self):
265 """ 264 """
266 Private slot called to enable the find button. 265 Private slot called to enable the find button.
267 """ 266 """
268 if self.findtextCombo.currentText() == "" or \ 267 if (
269 (self.dirButton.isChecked() and 268 self.findtextCombo.currentText() == "" or
270 (self.dirPicker.currentText() == "" or 269 (self.dirButton.isChecked() and
271 not os.path.exists(os.path.abspath( 270 (self.dirPicker.currentText() == "" or
272 self.dirPicker.currentText())))) or \ 271 not os.path.exists(os.path.abspath(
273 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""): 272 self.dirPicker.currentText())))) or
273 (self.filterCheckBox.isChecked() and
274 self.filterEdit.text() == "")
275 ):
274 self.findButton.setEnabled(False) 276 self.findButton.setEnabled(False)
275 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 277 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
276 else: 278 else:
277 self.findButton.setEnabled(True) 279 self.findButton.setEnabled(True)
278 self.findButton.setDefault(True) 280 self.findButton.setDefault(True)
305 307
306 def __doSearch(self): 308 def __doSearch(self):
307 """ 309 """
308 Private slot to handle the find button being pressed. 310 Private slot to handle the find button being pressed.
309 """ 311 """
310 if self.__replaceMode and \ 312 if (
311 not e5App().getObject("ViewManager").checkAllDirty(): 313 self.__replaceMode and
314 not e5App().getObject("ViewManager").checkAllDirty()
315 ):
312 return 316 return
313 317
314 self.__cancelSearch = False 318 self.__cancelSearch = False
315 319
316 if self.filterCheckBox.isChecked(): 320 if self.filterCheckBox.isChecked():
317 fileFilter = self.filterEdit.text() 321 fileFilter = self.filterEdit.text()
318 fileFilterList = \ 322 fileFilterList = [
319 ["^{0}$".format(filter.replace(".", r"\.").replace("*", ".*")) 323 "^{0}$".format(filter.replace(".", r"\.").replace("*", ".*"))
320 for filter in fileFilter.split(";")] 324 for filter in fileFilter.split(";")
325 ]
321 filterRe = re.compile("|".join(fileFilterList)) 326 filterRe = re.compile("|".join(fileFilterList))
322 327
323 if self.projectButton.isChecked(): 328 if self.projectButton.isChecked():
324 if self.filterCheckBox.isChecked(): 329 if self.filterCheckBox.isChecked():
325 files = [self.project.getRelativePath(file) 330 files = [self.project.getRelativePath(file)
615 else: 620 else:
616 fn = file 621 fn = file
617 622
618 # read the file and split it into textlines 623 # read the file and split it into textlines
619 try: 624 try:
620 text, encoding, hashStr = \ 625 text, encoding, hashStr = (
621 Utilities.readEncodedFileWithHash(fn) 626 Utilities.readEncodedFileWithHash(fn)
627 )
622 lines = text.splitlines(True) 628 lines = text.splitlines(True)
623 except (UnicodeError, IOError) as err: 629 except (UnicodeError, IOError) as err:
624 E5MessageBox.critical( 630 E5MessageBox.critical(
625 self, 631 self,
626 self.tr("Replace in Files"), 632 self.tr("Replace in Files"),

eric ide

mercurial