14 from PyQt6.QtGui import QCursor |
14 from PyQt6.QtGui import QCursor |
15 from PyQt6.QtWidgets import ( |
15 from PyQt6.QtWidgets import ( |
16 QDialog, QApplication, QMenu, QDialogButtonBox, QTreeWidgetItem, QComboBox |
16 QDialog, QApplication, QMenu, QDialogButtonBox, QTreeWidgetItem, QComboBox |
17 ) |
17 ) |
18 |
18 |
19 from E5Gui.E5Application import e5App |
19 from E5Gui.EricApplication import ericApp |
20 from E5Gui import E5MessageBox |
20 from E5Gui import EricMessageBox |
21 from E5Gui.E5PathPicker import E5PathPickerModes |
21 from E5Gui.EricPathPicker import EricPathPickerModes |
22 |
22 |
23 from .Ui_FindFileDialog import Ui_FindFileDialog |
23 from .Ui_FindFileDialog import Ui_FindFileDialog |
24 |
24 |
25 import Utilities |
25 import Utilities |
26 import Preferences |
26 import Preferences |
57 """ |
57 """ |
58 super().__init__(parent) |
58 super().__init__(parent) |
59 self.setupUi(self) |
59 self.setupUi(self) |
60 self.setWindowFlags(Qt.WindowType.Window) |
60 self.setWindowFlags(Qt.WindowType.Window) |
61 |
61 |
62 self.dirPicker.setMode(E5PathPickerModes.DIRECTORY_MODE) |
62 self.dirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
63 self.dirPicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) |
63 self.dirPicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) |
64 self.dirPicker.setSizeAdjustPolicy( |
64 self.dirPicker.setSizeAdjustPolicy( |
65 QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon) |
65 QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon) |
66 |
66 |
67 self.__replaceMode = replaceMode |
67 self.__replaceMode = replaceMode |
422 filterRe, |
422 filterRe, |
423 excludeHiddenDirs=self.excludeHiddenCheckBox.isChecked(), |
423 excludeHiddenDirs=self.excludeHiddenCheckBox.isChecked(), |
424 excludeHiddenFiles=self.excludeHiddenCheckBox.isChecked(), |
424 excludeHiddenFiles=self.excludeHiddenCheckBox.isChecked(), |
425 ) |
425 ) |
426 elif self.openFilesButton.isChecked(): |
426 elif self.openFilesButton.isChecked(): |
427 vm = e5App().getObject("ViewManager") |
427 vm = ericApp().getObject("ViewManager") |
428 vm.checkAllDirty() |
428 vm.checkAllDirty() |
429 files = vm.getOpenFilenames() |
429 files = vm.getOpenFilenames() |
430 |
430 |
431 self.findList.clear() |
431 self.findList.clear() |
432 QApplication.processEvents() |
432 QApplication.processEvents() |
445 if not cs: |
445 if not cs: |
446 flags |= re.IGNORECASE |
446 flags |= re.IGNORECASE |
447 try: |
447 try: |
448 search = re.compile(txt, flags) |
448 search = re.compile(txt, flags) |
449 except re.error as why: |
449 except re.error as why: |
450 E5MessageBox.critical( |
450 EricMessageBox.critical( |
451 self, |
451 self, |
452 self.tr("Invalid search expression"), |
452 self.tr("Invalid search expression"), |
453 self.tr("""<p>The search expression is not valid.</p>""" |
453 self.tr("""<p>The search expression is not valid.</p>""" |
454 """<p>Error: {0}</p>""").format(str(why))) |
454 """<p>Error: {0}</p>""").format(str(why))) |
455 self.stopButton.setEnabled(False) |
455 self.stopButton.setEnabled(False) |
687 text, encoding, hashStr = ( |
687 text, encoding, hashStr = ( |
688 Utilities.readEncodedFileWithHash(fn) |
688 Utilities.readEncodedFileWithHash(fn) |
689 ) |
689 ) |
690 lines = text.splitlines(True) |
690 lines = text.splitlines(True) |
691 except (UnicodeError, OSError) as err: |
691 except (UnicodeError, OSError) as err: |
692 E5MessageBox.critical( |
692 EricMessageBox.critical( |
693 self, |
693 self, |
694 self.tr("Replace in Files"), |
694 self.tr("Replace in Files"), |
695 self.tr( |
695 self.tr( |
696 """<p>Could not read the file <b>{0}</b>.""" |
696 """<p>Could not read the file <b>{0}</b>.""" |
697 """ Skipping it.</p><p>Reason: {1}</p>""") |
697 """ Skipping it.</p><p>Reason: {1}</p>""") |
701 continue |
701 continue |
702 |
702 |
703 # Check the original and the current hash. Skip the file, |
703 # Check the original and the current hash. Skip the file, |
704 # if hashes are different. |
704 # if hashes are different. |
705 if origHash != hashStr: |
705 if origHash != hashStr: |
706 E5MessageBox.critical( |
706 EricMessageBox.critical( |
707 self, |
707 self, |
708 self.tr("Replace in Files"), |
708 self.tr("Replace in Files"), |
709 self.tr( |
709 self.tr( |
710 """<p>The current and the original hash of the""" |
710 """<p>The current and the original hash of the""" |
711 """ file <b>{0}</b> are different. Skipping it.""" |
711 """ file <b>{0}</b> are different. Skipping it.""" |
726 # write the file |
726 # write the file |
727 txt = "".join(lines) |
727 txt = "".join(lines) |
728 try: |
728 try: |
729 Utilities.writeEncodedFile(fn, txt, encoding) |
729 Utilities.writeEncodedFile(fn, txt, encoding) |
730 except (OSError, Utilities.CodingError, UnicodeError) as err: |
730 except (OSError, Utilities.CodingError, UnicodeError) as err: |
731 E5MessageBox.critical( |
731 EricMessageBox.critical( |
732 self, |
732 self, |
733 self.tr("Replace in Files"), |
733 self.tr("Replace in Files"), |
734 self.tr( |
734 self.tr( |
735 """<p>Could not save the file <b>{0}</b>.""" |
735 """<p>Could not save the file <b>{0}</b>.""" |
736 """ Skipping it.</p><p>Reason: {1}</p>""") |
736 """ Skipping it.</p><p>Reason: {1}</p>""") |