59 self.dirSelectButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
60 self.dirSelectButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
60 |
61 |
61 self.__replaceMode = replaceMode |
62 self.__replaceMode = replaceMode |
62 |
63 |
63 self.stopButton = \ |
64 self.stopButton = \ |
64 self.buttonBox.addButton(self.trUtf8("Stop"), |
65 self.buttonBox.addButton(self.tr("Stop"), |
65 QDialogButtonBox.ActionRole) |
66 QDialogButtonBox.ActionRole) |
66 self.stopButton.setEnabled(False) |
67 self.stopButton.setEnabled(False) |
67 |
68 |
68 self.findButton = \ |
69 self.findButton = \ |
69 self.buttonBox.addButton(self.trUtf8("Find"), |
70 self.buttonBox.addButton(self.tr("Find"), |
70 QDialogButtonBox.ActionRole) |
71 QDialogButtonBox.ActionRole) |
71 self.findButton.setEnabled(False) |
72 self.findButton.setEnabled(False) |
72 self.findButton.setDefault(True) |
73 self.findButton.setDefault(True) |
73 |
74 |
74 if self.__replaceMode: |
75 if self.__replaceMode: |
75 self.replaceButton.setEnabled(False) |
76 self.replaceButton.setEnabled(False) |
76 self.setWindowTitle(self.trUtf8("Replace in Files")) |
77 self.setWindowTitle(self.tr("Replace in Files")) |
77 else: |
78 else: |
78 self.replaceLabel.hide() |
79 self.replaceLabel.hide() |
79 self.replacetextCombo.hide() |
80 self.replacetextCombo.hide() |
80 self.replaceButton.hide() |
81 self.replaceButton.hide() |
81 |
82 |
370 try: |
371 try: |
371 search = re.compile(txt, flags) |
372 search = re.compile(txt, flags) |
372 except re.error as why: |
373 except re.error as why: |
373 E5MessageBox.critical( |
374 E5MessageBox.critical( |
374 self, |
375 self, |
375 self.trUtf8("Invalid search expression"), |
376 self.tr("Invalid search expression"), |
376 self.trUtf8("""<p>The search expression is not valid.</p>""" |
377 self.tr("""<p>The search expression is not valid.</p>""" |
377 """<p>Error: {0}</p>""").format(str(why))) |
378 """<p>Error: {0}</p>""").format(str(why))) |
378 self.stopButton.setEnabled(False) |
379 self.stopButton.setEnabled(False) |
379 self.findButton.setEnabled(True) |
380 self.findButton.setEnabled(True) |
380 self.findButton.setDefault(True) |
381 self.findButton.setDefault(True) |
381 return |
382 return |
382 # reset the findtextCombo |
383 # reset the findtextCombo |
536 """ |
537 """ |
537 Private slot to display a directory selection dialog. |
538 Private slot to display a directory selection dialog. |
538 """ |
539 """ |
539 directory = E5FileDialog.getExistingDirectory( |
540 directory = E5FileDialog.getExistingDirectory( |
540 self, |
541 self, |
541 self.trUtf8("Select directory"), |
542 self.tr("Select directory"), |
542 self.dirCombo.currentText(), |
543 self.dirCombo.currentText(), |
543 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
544 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
544 |
545 |
545 if directory: |
546 if directory: |
546 self.dirCombo.setEditText(Utilities.toNativeSeparators(directory)) |
547 self.dirCombo.setEditText(Utilities.toNativeSeparators(directory)) |
606 Utilities.readEncodedFileWithHash(fn) |
607 Utilities.readEncodedFileWithHash(fn) |
607 lines = text.splitlines(True) |
608 lines = text.splitlines(True) |
608 except (UnicodeError, IOError) as err: |
609 except (UnicodeError, IOError) as err: |
609 E5MessageBox.critical( |
610 E5MessageBox.critical( |
610 self, |
611 self, |
611 self.trUtf8("Replace in Files"), |
612 self.tr("Replace in Files"), |
612 self.trUtf8( |
613 self.tr( |
613 """<p>Could not read the file <b>{0}</b>.""" |
614 """<p>Could not read the file <b>{0}</b>.""" |
614 """ Skipping it.</p><p>Reason: {1}</p>""") |
615 """ Skipping it.</p><p>Reason: {1}</p>""") |
615 .format(fn, str(err)) |
616 .format(fn, str(err)) |
616 ) |
617 ) |
617 progress += 1 |
618 progress += 1 |
621 # Check the original and the current hash. Skip the file, |
622 # Check the original and the current hash. Skip the file, |
622 # if hashes are different. |
623 # if hashes are different. |
623 if origHash != hash: |
624 if origHash != hash: |
624 E5MessageBox.critical( |
625 E5MessageBox.critical( |
625 self, |
626 self, |
626 self.trUtf8("Replace in Files"), |
627 self.tr("Replace in Files"), |
627 self.trUtf8( |
628 self.tr( |
628 """<p>The current and the original hash of the""" |
629 """<p>The current and the original hash of the""" |
629 """ file <b>{0}</b> are different. Skipping it.""" |
630 """ file <b>{0}</b> are different. Skipping it.""" |
630 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""") |
631 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""") |
631 .format(fn, origHash, hash) |
632 .format(fn, origHash, hash) |
632 ) |
633 ) |
647 try: |
648 try: |
648 Utilities.writeEncodedFile(fn, txt, encoding) |
649 Utilities.writeEncodedFile(fn, txt, encoding) |
649 except (IOError, Utilities.CodingError, UnicodeError) as err: |
650 except (IOError, Utilities.CodingError, UnicodeError) as err: |
650 E5MessageBox.critical( |
651 E5MessageBox.critical( |
651 self, |
652 self, |
652 self.trUtf8("Replace in Files"), |
653 self.tr("Replace in Files"), |
653 self.trUtf8( |
654 self.tr( |
654 """<p>Could not save the file <b>{0}</b>.""" |
655 """<p>Could not save the file <b>{0}</b>.""" |
655 """ Skipping it.</p><p>Reason: {1}</p>""") |
656 """ Skipping it.</p><p>Reason: {1}</p>""") |
656 .format(fn, str(err)) |
657 .format(fn, str(err)) |
657 ) |
658 ) |
658 |
659 |
672 |
673 |
673 @param pos position the context menu shall be shown (QPoint) |
674 @param pos position the context menu shall be shown (QPoint) |
674 """ |
675 """ |
675 menu = QMenu(self) |
676 menu = QMenu(self) |
676 |
677 |
677 menu.addAction(self.trUtf8("Open"), self.__openFile) |
678 menu.addAction(self.tr("Open"), self.__openFile) |
678 menu.addAction(self.trUtf8("Copy Path to Clipboard"), |
679 menu.addAction(self.tr("Copy Path to Clipboard"), |
679 self.__copyToClipboard) |
680 self.__copyToClipboard) |
680 |
681 |
681 menu.exec_(QCursor.pos()) |
682 menu.exec_(QCursor.pos()) |
682 |
683 |
683 def __openFile(self): |
684 def __openFile(self): |