330 if not cs: |
331 if not cs: |
331 flags |= re.IGNORECASE |
332 flags |= re.IGNORECASE |
332 try: |
333 try: |
333 search = re.compile(txt, flags) |
334 search = re.compile(txt, flags) |
334 except re.error as why: |
335 except re.error as why: |
335 QMessageBox.critical(None, |
336 E5MessageBox.critical(self, |
336 self.trUtf8("Invalid search expression"), |
337 self.trUtf8("Invalid search expression"), |
337 self.trUtf8("""<p>The search expression is not valid.</p>""" |
338 self.trUtf8("""<p>The search expression is not valid.</p>""" |
338 """<p>Error: {0}</p>""").format(str(why))) |
339 """<p>Error: {0}</p>""").format(str(why))) |
339 self.stopButton.setEnabled(False) |
340 self.stopButton.setEnabled(False) |
340 self.findButton.setEnabled(True) |
341 self.findButton.setEnabled(True) |
552 # read the file and split it into textlines |
553 # read the file and split it into textlines |
553 try: |
554 try: |
554 text, encoding = Utilities.readEncodedFile(fn) |
555 text, encoding = Utilities.readEncodedFile(fn) |
555 lines = text.splitlines() |
556 lines = text.splitlines() |
556 except (UnicodeError, IOError): |
557 except (UnicodeError, IOError): |
557 QMessageBox.critical(self, |
558 E5MessageBox.critical(self, |
558 self.trUtf8("Replace in Files"), |
559 self.trUtf8("Replace in Files"), |
559 self.trUtf8("""<p>Could not read the file <b>{0}</b>.""" |
560 self.trUtf8("""<p>Could not read the file <b>{0}</b>.""" |
560 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
561 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
561 .format(fn, str(err)) |
562 .format(fn, str(err)) |
562 ) |
563 ) |
575 # write the file |
576 # write the file |
576 txt = Utilities.linesep().join(lines) |
577 txt = Utilities.linesep().join(lines) |
577 try: |
578 try: |
578 Utilities.writeEncodedFile(fn, txt, encoding) |
579 Utilities.writeEncodedFile(fn, txt, encoding) |
579 except (IOError, Utilities.CodingError, UnicodeError) as err: |
580 except (IOError, Utilities.CodingError, UnicodeError) as err: |
580 QMessageBox.critical(self, |
581 E5MessageBox.critical(self, |
581 self.trUtf8("Replace in Files"), |
582 self.trUtf8("Replace in Files"), |
582 self.trUtf8("""<p>Could not save the file <b>{0}</b>.""" |
583 self.trUtf8("""<p>Could not save the file <b>{0}</b>.""" |
583 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
584 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
584 .format(fn, str(err)) |
585 .format(fn, str(err)) |
585 ) |
586 ) |