56 """ |
57 """ |
57 super(FindFileDialog, self).__init__(parent) |
58 super(FindFileDialog, self).__init__(parent) |
58 self.setupUi(self) |
59 self.setupUi(self) |
59 self.setWindowFlags(Qt.WindowFlags(Qt.Window)) |
60 self.setWindowFlags(Qt.WindowFlags(Qt.Window)) |
60 |
61 |
|
62 self.dirSelectButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
63 |
61 self.__replaceMode = replaceMode |
64 self.__replaceMode = replaceMode |
62 |
65 |
63 self.stopButton = \ |
66 self.stopButton = \ |
64 self.buttonBox.addButton(self.trUtf8("Stop"), |
67 self.buttonBox.addButton(self.tr("Stop"), |
65 QDialogButtonBox.ActionRole) |
68 QDialogButtonBox.ActionRole) |
66 self.stopButton.setEnabled(False) |
69 self.stopButton.setEnabled(False) |
67 |
70 |
68 self.findButton = \ |
71 self.findButton = \ |
69 self.buttonBox.addButton(self.trUtf8("Find"), |
72 self.buttonBox.addButton(self.tr("Find"), |
70 QDialogButtonBox.ActionRole) |
73 QDialogButtonBox.ActionRole) |
71 self.findButton.setEnabled(False) |
74 self.findButton.setEnabled(False) |
72 self.findButton.setDefault(True) |
75 self.findButton.setDefault(True) |
73 |
76 |
74 if self.__replaceMode: |
77 if self.__replaceMode: |
75 self.replaceButton.setEnabled(False) |
78 self.replaceButton.setEnabled(False) |
76 self.setWindowTitle(self.trUtf8("Replace in Files")) |
79 self.setWindowTitle(self.tr("Replace in Files")) |
77 else: |
80 else: |
78 self.replaceLabel.hide() |
81 self.replaceLabel.hide() |
79 self.replacetextCombo.hide() |
82 self.replacetextCombo.hide() |
80 self.replaceButton.hide() |
83 self.replaceButton.hide() |
81 |
84 |
99 self.findList.headerItem().setText(self.findList.columnCount(), "") |
102 self.findList.headerItem().setText(self.findList.columnCount(), "") |
100 self.findList.header().setSortIndicator(0, Qt.AscendingOrder) |
103 self.findList.header().setSortIndicator(0, Qt.AscendingOrder) |
101 self.__section0Size = self.findList.header().sectionSize(0) |
104 self.__section0Size = self.findList.header().sectionSize(0) |
102 self.findList.setExpandsOnDoubleClick(False) |
105 self.findList.setExpandsOnDoubleClick(False) |
103 if self.__replaceMode: |
106 if self.__replaceMode: |
104 font = self.findList.font() |
107 font = Preferences.getEditorOtherFonts("MonospacedFont") |
105 if Utilities.isWindowsPlatform(): |
|
106 font.setFamily("Lucida Console") |
|
107 else: |
|
108 font.setFamily("Monospace") |
|
109 self.findList.setFont(font) |
108 self.findList.setFont(font) |
110 |
109 |
111 # Qt Designer form files |
110 # Qt Designer form files |
112 self.filterForms = r'.*\.ui$' |
111 self.filterForms = r'.*\.ui$' |
113 self.formsExt = ['*.ui'] |
112 self.formsExt = ['*.ui'] |
370 try: |
369 try: |
371 search = re.compile(txt, flags) |
370 search = re.compile(txt, flags) |
372 except re.error as why: |
371 except re.error as why: |
373 E5MessageBox.critical( |
372 E5MessageBox.critical( |
374 self, |
373 self, |
375 self.trUtf8("Invalid search expression"), |
374 self.tr("Invalid search expression"), |
376 self.trUtf8("""<p>The search expression is not valid.</p>""" |
375 self.tr("""<p>The search expression is not valid.</p>""" |
377 """<p>Error: {0}</p>""").format(str(why))) |
376 """<p>Error: {0}</p>""").format(str(why))) |
378 self.stopButton.setEnabled(False) |
377 self.stopButton.setEnabled(False) |
379 self.findButton.setEnabled(True) |
378 self.findButton.setEnabled(True) |
380 self.findButton.setDefault(True) |
379 self.findButton.setDefault(True) |
381 return |
380 return |
382 # reset the findtextCombo |
381 # reset the findtextCombo |
419 # now go through all the files |
418 # now go through all the files |
420 self.__populating = True |
419 self.__populating = True |
421 self.findList.setUpdatesEnabled(False) |
420 self.findList.setUpdatesEnabled(False) |
422 progress = 0 |
421 progress = 0 |
423 breakSearch = False |
422 breakSearch = False |
|
423 occurrences = 0 |
|
424 fileOccurrences = 0 |
424 for file in files: |
425 for file in files: |
425 self.__lastFileItem = None |
426 self.__lastFileItem = None |
|
427 found = False |
426 if self.__cancelSearch or breakSearch: |
428 if self.__cancelSearch or breakSearch: |
427 break |
429 break |
428 |
430 |
429 self.findProgressLabel.setPath(file) |
431 self.findProgressLabel.setPath(file) |
430 |
432 |
474 breakSearch = True |
478 breakSearch = True |
475 break |
479 break |
476 |
480 |
477 QApplication.processEvents() |
481 QApplication.processEvents() |
478 |
482 |
|
483 if found: |
|
484 fileOccurrences += 1 |
479 progress += 1 |
485 progress += 1 |
480 self.findProgress.setValue(progress) |
486 self.findProgress.setValue(progress) |
481 |
487 |
482 if not files: |
488 if not files: |
483 self.findProgress.setMaximum(1) |
489 self.findProgress.setMaximum(1) |
484 self.findProgress.setValue(1) |
490 self.findProgress.setValue(1) |
485 |
491 |
486 self.findProgressLabel.setPath("") |
492 resultFormat = self.tr("{0} / {1}", "occurrences / files") |
|
493 self.findProgressLabel.setPath(resultFormat.format( |
|
494 self.tr("%n occurrence(s)", "", occurrences), |
|
495 self.tr("%n file(s)", "", fileOccurrences))) |
487 |
496 |
488 self.findList.setUpdatesEnabled(True) |
497 self.findList.setUpdatesEnabled(True) |
489 self.findList.sortItems(self.findList.sortColumn(), |
498 self.findList.sortItems(self.findList.sortColumn(), |
490 self.findList.header().sortIndicatorOrder()) |
499 self.findList.header().sortIndicatorOrder()) |
491 self.findList.resizeColumnToContents(1) |
500 self.findList.resizeColumnToContents(1) |
536 """ |
545 """ |
537 Private slot to display a directory selection dialog. |
546 Private slot to display a directory selection dialog. |
538 """ |
547 """ |
539 directory = E5FileDialog.getExistingDirectory( |
548 directory = E5FileDialog.getExistingDirectory( |
540 self, |
549 self, |
541 self.trUtf8("Select directory"), |
550 self.tr("Select directory"), |
542 self.dirCombo.currentText(), |
551 self.dirCombo.currentText(), |
543 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
552 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
544 |
553 |
545 if directory: |
554 if directory: |
546 self.dirCombo.setEditText(Utilities.toNativeSeparators(directory)) |
555 self.dirCombo.setEditText(Utilities.toNativeSeparators(directory)) |
606 Utilities.readEncodedFileWithHash(fn) |
615 Utilities.readEncodedFileWithHash(fn) |
607 lines = text.splitlines(True) |
616 lines = text.splitlines(True) |
608 except (UnicodeError, IOError) as err: |
617 except (UnicodeError, IOError) as err: |
609 E5MessageBox.critical( |
618 E5MessageBox.critical( |
610 self, |
619 self, |
611 self.trUtf8("Replace in Files"), |
620 self.tr("Replace in Files"), |
612 self.trUtf8( |
621 self.tr( |
613 """<p>Could not read the file <b>{0}</b>.""" |
622 """<p>Could not read the file <b>{0}</b>.""" |
614 """ Skipping it.</p><p>Reason: {1}</p>""") |
623 """ Skipping it.</p><p>Reason: {1}</p>""") |
615 .format(fn, str(err)) |
624 .format(fn, str(err)) |
616 ) |
625 ) |
617 progress += 1 |
626 progress += 1 |
621 # Check the original and the current hash. Skip the file, |
630 # Check the original and the current hash. Skip the file, |
622 # if hashes are different. |
631 # if hashes are different. |
623 if origHash != hash: |
632 if origHash != hash: |
624 E5MessageBox.critical( |
633 E5MessageBox.critical( |
625 self, |
634 self, |
626 self.trUtf8("Replace in Files"), |
635 self.tr("Replace in Files"), |
627 self.trUtf8( |
636 self.tr( |
628 """<p>The current and the original hash of the""" |
637 """<p>The current and the original hash of the""" |
629 """ file <b>{0}</b> are different. Skipping it.""" |
638 """ file <b>{0}</b> are different. Skipping it.""" |
630 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""") |
639 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""") |
631 .format(fn, origHash, hash) |
640 .format(fn, origHash, hash) |
632 ) |
641 ) |
647 try: |
656 try: |
648 Utilities.writeEncodedFile(fn, txt, encoding) |
657 Utilities.writeEncodedFile(fn, txt, encoding) |
649 except (IOError, Utilities.CodingError, UnicodeError) as err: |
658 except (IOError, Utilities.CodingError, UnicodeError) as err: |
650 E5MessageBox.critical( |
659 E5MessageBox.critical( |
651 self, |
660 self, |
652 self.trUtf8("Replace in Files"), |
661 self.tr("Replace in Files"), |
653 self.trUtf8( |
662 self.tr( |
654 """<p>Could not save the file <b>{0}</b>.""" |
663 """<p>Could not save the file <b>{0}</b>.""" |
655 """ Skipping it.</p><p>Reason: {1}</p>""") |
664 """ Skipping it.</p><p>Reason: {1}</p>""") |
656 .format(fn, str(err)) |
665 .format(fn, str(err)) |
657 ) |
666 ) |
658 |
667 |
672 |
681 |
673 @param pos position the context menu shall be shown (QPoint) |
682 @param pos position the context menu shall be shown (QPoint) |
674 """ |
683 """ |
675 menu = QMenu(self) |
684 menu = QMenu(self) |
676 |
685 |
677 menu.addAction(self.trUtf8("Open"), self.__openFile) |
686 menu.addAction(self.tr("Open"), self.__openFile) |
678 menu.addAction(self.trUtf8("Copy Path to Clipboard"), |
687 menu.addAction(self.tr("Copy Path to Clipboard"), |
679 self.__copyToClipboard) |
688 self.__copyToClipboard) |
680 |
689 |
681 menu.exec_(QCursor.pos()) |
690 menu.exec_(QCursor.pos()) |
682 |
691 |
683 def __openFile(self): |
692 def __openFile(self): |