eric6/UI/FindFileDialog.py

changeset 8220
006ee31b4835
parent 8218
7c09585bd960
child 8235
78e6d29eb773
equal deleted inserted replaced
8219:013aee248a62 8220:006ee31b4835
500 self.findButton.setEnabled(False) 500 self.findButton.setEnabled(False)
501 501
502 # now go through all the files 502 # now go through all the files
503 self.__populating = True 503 self.__populating = True
504 self.findList.setUpdatesEnabled(False) 504 self.findList.setUpdatesEnabled(False)
505 progress = 0
506 breakSearch = False 505 breakSearch = False
507 occurrences = 0 506 occurrences = 0
508 fileOccurrences = 0 507 fileOccurrences = 0
509 for file in files: 508 for progress, file in enumerate(files, start=1):
510 self.__lastFileItem = None 509 self.__lastFileItem = None
511 found = False 510 found = False
512 if self.__cancelSearch or breakSearch: 511 if self.__cancelSearch or breakSearch:
513 break 512 break
514 513
521 # read the file and split it into textlines 520 # read the file and split it into textlines
522 try: 521 try:
523 text, encoding, hashStr = Utilities.readEncodedFileWithHash(fn) 522 text, encoding, hashStr = Utilities.readEncodedFileWithHash(fn)
524 lines = text.splitlines(True) 523 lines = text.splitlines(True)
525 except (UnicodeError, OSError): 524 except (UnicodeError, OSError):
526 progress += 1
527 self.findProgress.setValue(progress) 525 self.findProgress.setValue(progress)
528 continue 526 continue
529 527
530 # now perform the search and display the lines found 528 # now perform the search and display the lines found
531 count = 0 529 for count, line in enumerate(lines, start=1):
532 for line in lines:
533 if self.__cancelSearch: 530 if self.__cancelSearch:
534 break 531 break
535 532
536 count += 1
537 contains = search.search(line) 533 contains = search.search(line)
538 if contains: 534 if contains:
539 occurrences += 1 535 occurrences += 1
540 found = True 536 found = True
541 start = contains.start() 537 start = contains.start()
564 560
565 QApplication.processEvents() 561 QApplication.processEvents()
566 562
567 if found: 563 if found:
568 fileOccurrences += 1 564 fileOccurrences += 1
569 progress += 1
570 self.findProgress.setValue(progress) 565 self.findProgress.setValue(progress)
571 566
572 if not files: 567 if not files:
573 self.findProgress.setMaximum(1) 568 self.findProgress.setMaximum(1)
574 self.findProgress.setValue(1) 569 self.findProgress.setValue(1)
676 Private slot to perform the requested replace actions. 671 Private slot to perform the requested replace actions.
677 """ 672 """
678 self.findProgress.setMaximum(self.findList.topLevelItemCount()) 673 self.findProgress.setMaximum(self.findList.topLevelItemCount())
679 self.findProgress.setValue(0) 674 self.findProgress.setValue(0)
680 675
681 progress = 0
682 for index in range(self.findList.topLevelItemCount()): 676 for index in range(self.findList.topLevelItemCount()):
683 itm = self.findList.topLevelItem(index) 677 itm = self.findList.topLevelItem(index)
684 if itm.checkState(0) in [Qt.CheckState.PartiallyChecked, 678 if itm.checkState(0) in [Qt.CheckState.PartiallyChecked,
685 Qt.CheckState.Checked]: 679 Qt.CheckState.Checked]:
686 file = itm.text(0) 680 file = itm.text(0)
706 self.tr( 700 self.tr(
707 """<p>Could not read the file <b>{0}</b>.""" 701 """<p>Could not read the file <b>{0}</b>."""
708 """ Skipping it.</p><p>Reason: {1}</p>""") 702 """ Skipping it.</p><p>Reason: {1}</p>""")
709 .format(fn, str(err)) 703 .format(fn, str(err))
710 ) 704 )
711 progress += 1 705 self.findProgress.setValue(index)
712 self.findProgress.setValue(progress)
713 continue 706 continue
714 707
715 # Check the original and the current hash. Skip the file, 708 # Check the original and the current hash. Skip the file,
716 # if hashes are different. 709 # if hashes are different.
717 if origHash != hashStr: 710 if origHash != hashStr:
722 """<p>The current and the original hash of the""" 715 """<p>The current and the original hash of the"""
723 """ file <b>{0}</b> are different. Skipping it.""" 716 """ file <b>{0}</b> are different. Skipping it."""
724 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""") 717 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""")
725 .format(fn, origHash, hashStr) 718 .format(fn, origHash, hashStr)
726 ) 719 )
727 progress += 1 720 self.findProgress.setValue(index)
728 self.findProgress.setValue(progress)
729 continue 721 continue
730 722
731 # replace the lines authorized by the user 723 # replace the lines authorized by the user
732 for cindex in range(itm.childCount()): 724 for cindex in range(itm.childCount()):
733 citm = itm.child(cindex) 725 citm = itm.child(cindex)
748 """<p>Could not save the file <b>{0}</b>.""" 740 """<p>Could not save the file <b>{0}</b>."""
749 """ Skipping it.</p><p>Reason: {1}</p>""") 741 """ Skipping it.</p><p>Reason: {1}</p>""")
750 .format(fn, str(err)) 742 .format(fn, str(err))
751 ) 743 )
752 744
753 progress += 1 745 self.findProgress.setValue(index)
754 self.findProgress.setValue(progress)
755 746
756 self.findProgressLabel.setPath("") 747 self.findProgressLabel.setPath("")
757 748
758 self.findList.clear() 749 self.findList.clear()
759 self.replaceButton.setEnabled(False) 750 self.replaceButton.setEnabled(False)

eric ide

mercurial