142 self.__lastFileItem = QTreeWidgetItem(self.findList, [file]) |
142 self.__lastFileItem = QTreeWidgetItem(self.findList, [file]) |
143 self.__lastFileItem.setFirstColumnSpanned(True) |
143 self.__lastFileItem.setFirstColumnSpanned(True) |
144 self.__lastFileItem.setExpanded(True) |
144 self.__lastFileItem.setExpanded(True) |
145 if self.__replaceMode: |
145 if self.__replaceMode: |
146 self.__lastFileItem.setFlags( |
146 self.__lastFileItem.setFlags( |
147 self.__lastFileItem.flags() | \ |
147 self.__lastFileItem.flags() | |
148 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) |
148 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) |
149 # Qt bug: |
149 # Qt bug: |
150 # item is not user checkable if setFirstColumnSpanned |
150 # item is not user checkable if setFirstColumnSpanned |
151 # is True (< 4.5.0) |
151 # is True (< 4.5.0) |
152 self.__lastFileItem.setData(0, self.md5Role, md5) |
152 self.__lastFileItem.setData(0, self.md5Role, md5) |
246 def __enableFindButton(self): |
246 def __enableFindButton(self): |
247 """ |
247 """ |
248 Private slot called to enable the find button. |
248 Private slot called to enable the find button. |
249 """ |
249 """ |
250 if self.findtextCombo.currentText() == "" or \ |
250 if self.findtextCombo.currentText() == "" or \ |
251 (self.__replaceMode and \ |
251 (self.__replaceMode and |
252 self.replacetextCombo.currentText() == "") or \ |
252 self.replacetextCombo.currentText() == "") or \ |
253 (self.dirButton.isChecked() and \ |
253 (self.dirButton.isChecked() and |
254 (self.dirCombo.currentText() == "" or \ |
254 (self.dirCombo.currentText() == "" or |
255 not os.path.exists(os.path.abspath( |
255 not os.path.exists(os.path.abspath( |
256 self.dirCombo.currentText())))) or \ |
256 self.dirCombo.currentText())))) or \ |
257 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""): |
257 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""): |
258 self.findButton.setEnabled(False) |
258 self.findButton.setEnabled(False) |
259 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
259 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
298 self.__cancelSearch = False |
298 self.__cancelSearch = False |
299 |
299 |
300 if self.filterCheckBox.isChecked(): |
300 if self.filterCheckBox.isChecked(): |
301 fileFilter = self.filterEdit.text() |
301 fileFilter = self.filterEdit.text() |
302 fileFilterList = \ |
302 fileFilterList = \ |
303 ["^{0}$".format(filter.replace(".", "\.").replace("*", ".*")) \ |
303 ["^{0}$".format(filter.replace(".", "\.").replace("*", ".*")) |
304 for filter in fileFilter.split(";")] |
304 for filter in fileFilter.split(";")] |
305 filterRe = re.compile("|".join(fileFilterList)) |
305 filterRe = re.compile("|".join(fileFilterList)) |
306 |
306 |
307 if self.projectButton.isChecked(): |
307 if self.projectButton.isChecked(): |
308 if self.filterCheckBox.isChecked(): |
308 if self.filterCheckBox.isChecked(): |
309 files = [self.project.getRelativePath(file) \ |
309 files = [self.project.getRelativePath(file) |
310 for file in \ |
310 for file in |
311 self.__getFileList( |
311 self.__getFileList( |
312 self.project.getProjectPath(), filterRe)] |
312 self.project.getProjectPath(), filterRe)] |
313 else: |
313 else: |
314 files = [] |
314 files = [] |
315 if self.sourcesCheckBox.isChecked(): |
315 if self.sourcesCheckBox.isChecked(): |
553 @return list of files to be processed (list of strings) |
553 @return list of files to be processed (list of strings) |
554 """ |
554 """ |
555 path = os.path.abspath(path) |
555 path = os.path.abspath(path) |
556 files = [] |
556 files = [] |
557 for dirname, _, names in os.walk(path): |
557 for dirname, _, names in os.walk(path): |
558 files.extend([os.path.join(dirname, f) \ |
558 files.extend([os.path.join(dirname, f) |
559 for f in names \ |
559 for f in names |
560 if re.match(filterRe, f)] |
560 if re.match(filterRe, f)] |
561 ) |
561 ) |
562 return files |
562 return files |
563 |
563 |
564 def setSearchDirectory(self, searchDir): |
564 def setSearchDirectory(self, searchDir): |
607 E5MessageBox.critical( |
607 E5MessageBox.critical( |
608 self, |
608 self, |
609 self.trUtf8("Replace in Files"), |
609 self.trUtf8("Replace in Files"), |
610 self.trUtf8( |
610 self.trUtf8( |
611 """<p>Could not read the file <b>{0}</b>.""" |
611 """<p>Could not read the file <b>{0}</b>.""" |
612 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
612 """ Skipping it.</p><p>Reason: {1}</p>""") |
613 .format(fn, str(err)) |
613 .format(fn, str(err)) |
614 ) |
614 ) |
615 progress += 1 |
615 progress += 1 |
616 self.findProgress.setValue(progress) |
616 self.findProgress.setValue(progress) |
617 continue |
617 continue |
623 self, |
623 self, |
624 self.trUtf8("Replace in Files"), |
624 self.trUtf8("Replace in Files"), |
625 self.trUtf8( |
625 self.trUtf8( |
626 """<p>The current and the original hash of the""" |
626 """<p>The current and the original hash of the""" |
627 """ file <b>{0}</b> are different. Skipping it.""" |
627 """ file <b>{0}</b> are different. Skipping it.""" |
628 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""")\ |
628 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""") |
629 .format(fn, origHash, hash) |
629 .format(fn, origHash, hash) |
630 ) |
630 ) |
631 progress += 1 |
631 progress += 1 |
632 self.findProgress.setValue(progress) |
632 self.findProgress.setValue(progress) |
633 continue |
633 continue |
648 E5MessageBox.critical( |
648 E5MessageBox.critical( |
649 self, |
649 self, |
650 self.trUtf8("Replace in Files"), |
650 self.trUtf8("Replace in Files"), |
651 self.trUtf8( |
651 self.trUtf8( |
652 """<p>Could not save the file <b>{0}</b>.""" |
652 """<p>Could not save the file <b>{0}</b>.""" |
653 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
653 """ Skipping it.</p><p>Reason: {1}</p>""") |
654 .format(fn, str(err)) |
654 .format(fn, str(err)) |
655 ) |
655 ) |
656 |
656 |
657 progress += 1 |
657 progress += 1 |
658 self.findProgress.setValue(progress) |
658 self.findProgress.setValue(progress) |