143 # It's a new file |
143 # It's a new file |
144 self.__lastFileItem = QTreeWidgetItem(self.findList, [file]) |
144 self.__lastFileItem = QTreeWidgetItem(self.findList, [file]) |
145 self.__lastFileItem.setFirstColumnSpanned(True) |
145 self.__lastFileItem.setFirstColumnSpanned(True) |
146 self.__lastFileItem.setExpanded(True) |
146 self.__lastFileItem.setExpanded(True) |
147 if self.__replaceMode: |
147 if self.__replaceMode: |
148 self.__lastFileItem.setFlags(self.__lastFileItem.flags() | \ |
148 self.__lastFileItem.setFlags( |
|
149 self.__lastFileItem.flags() | \ |
149 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) |
150 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) |
150 # Qt bug: |
151 # Qt bug: |
151 # item is not user checkable if setFirstColumnSpanned |
152 # item is not user checkable if setFirstColumnSpanned |
152 # is True (< 4.5.0) |
153 # is True (< 4.5.0) |
153 self.__lastFileItem.setData(0, self.md5Role, md5) |
154 self.__lastFileItem.setData(0, self.md5Role, md5) |
367 if not cs: |
368 if not cs: |
368 flags |= re.IGNORECASE |
369 flags |= re.IGNORECASE |
369 try: |
370 try: |
370 search = re.compile(txt, flags) |
371 search = re.compile(txt, flags) |
371 except re.error as why: |
372 except re.error as why: |
372 E5MessageBox.critical(self, |
373 E5MessageBox.critical( |
|
374 self, |
373 self.trUtf8("Invalid search expression"), |
375 self.trUtf8("Invalid search expression"), |
374 self.trUtf8("""<p>The search expression is not valid.</p>""" |
376 self.trUtf8("""<p>The search expression is not valid.</p>""" |
375 """<p>Error: {0}</p>""").format(str(why))) |
377 """<p>Error: {0}</p>""").format(str(why))) |
376 self.stopButton.setEnabled(False) |
378 self.stopButton.setEnabled(False) |
377 self.findButton.setEnabled(True) |
379 self.findButton.setEnabled(True) |
602 try: |
604 try: |
603 text, encoding, hash = \ |
605 text, encoding, hash = \ |
604 Utilities.readEncodedFileWithHash(fn) |
606 Utilities.readEncodedFileWithHash(fn) |
605 lines = text.splitlines(True) |
607 lines = text.splitlines(True) |
606 except (UnicodeError, IOError) as err: |
608 except (UnicodeError, IOError) as err: |
607 E5MessageBox.critical(self, |
609 E5MessageBox.critical( |
|
610 self, |
608 self.trUtf8("Replace in Files"), |
611 self.trUtf8("Replace in Files"), |
609 self.trUtf8( |
612 self.trUtf8( |
610 """<p>Could not read the file <b>{0}</b>.""" |
613 """<p>Could not read the file <b>{0}</b>.""" |
611 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
614 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
612 .format(fn, str(err)) |
615 .format(fn, str(err)) |
616 continue |
619 continue |
617 |
620 |
618 # Check the original and the current hash. Skip the file, |
621 # Check the original and the current hash. Skip the file, |
619 # if hashes are different. |
622 # if hashes are different. |
620 if origHash != hash: |
623 if origHash != hash: |
621 E5MessageBox.critical(self, |
624 E5MessageBox.critical( |
|
625 self, |
622 self.trUtf8("Replace in Files"), |
626 self.trUtf8("Replace in Files"), |
623 self.trUtf8( |
627 self.trUtf8( |
624 """<p>The current and the original hash of the""" |
628 """<p>The current and the original hash of the""" |
625 """ file <b>{0}</b> are different. Skipping it.""" |
629 """ file <b>{0}</b> are different. Skipping it.""" |
626 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""")\ |
630 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""")\ |
641 # write the file |
645 # write the file |
642 txt = "".join(lines) |
646 txt = "".join(lines) |
643 try: |
647 try: |
644 Utilities.writeEncodedFile(fn, txt, encoding) |
648 Utilities.writeEncodedFile(fn, txt, encoding) |
645 except (IOError, Utilities.CodingError, UnicodeError) as err: |
649 except (IOError, Utilities.CodingError, UnicodeError) as err: |
646 E5MessageBox.critical(self, |
650 E5MessageBox.critical( |
|
651 self, |
647 self.trUtf8("Replace in Files"), |
652 self.trUtf8("Replace in Files"), |
648 self.trUtf8( |
653 self.trUtf8( |
649 """<p>Could not save the file <b>{0}</b>.""" |
654 """<p>Could not save the file <b>{0}</b>.""" |
650 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
655 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
651 .format(fn, str(err)) |
656 .format(fn, str(err)) |