144 self.__lastFileItem = QTreeWidgetItem(self.findList, [file]) |
144 self.__lastFileItem = QTreeWidgetItem(self.findList, [file]) |
145 self.__lastFileItem.setFirstColumnSpanned(True) |
145 self.__lastFileItem.setFirstColumnSpanned(True) |
146 self.__lastFileItem.setExpanded(True) |
146 self.__lastFileItem.setExpanded(True) |
147 if self.__replaceMode: |
147 if self.__replaceMode: |
148 self.__lastFileItem.setFlags( |
148 self.__lastFileItem.setFlags( |
149 self.__lastFileItem.flags() | \ |
149 self.__lastFileItem.flags() | |
150 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) |
150 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) |
151 # Qt bug: |
151 # Qt bug: |
152 # item is not user checkable if setFirstColumnSpanned |
152 # item is not user checkable if setFirstColumnSpanned |
153 # is True (< 4.5.0) |
153 # is True (< 4.5.0) |
154 self.__lastFileItem.setData(0, self.md5Role, md5) |
154 self.__lastFileItem.setData(0, self.md5Role, md5) |
248 def __enableFindButton(self): |
248 def __enableFindButton(self): |
249 """ |
249 """ |
250 Private slot called to enable the find button. |
250 Private slot called to enable the find button. |
251 """ |
251 """ |
252 if self.findtextCombo.currentText() == "" or \ |
252 if self.findtextCombo.currentText() == "" or \ |
253 (self.__replaceMode and \ |
253 (self.__replaceMode and |
254 self.replacetextCombo.currentText() == "") or \ |
254 self.replacetextCombo.currentText() == "") or \ |
255 (self.dirButton.isChecked() and \ |
255 (self.dirButton.isChecked() and |
256 (self.dirCombo.currentText() == "" or \ |
256 (self.dirCombo.currentText() == "" or |
257 not os.path.exists(os.path.abspath( |
257 not os.path.exists(os.path.abspath( |
258 self.dirCombo.currentText())))) or \ |
258 self.dirCombo.currentText())))) or \ |
259 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""): |
259 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""): |
260 self.findButton.setEnabled(False) |
260 self.findButton.setEnabled(False) |
261 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
261 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
300 self.__cancelSearch = False |
300 self.__cancelSearch = False |
301 |
301 |
302 if self.filterCheckBox.isChecked(): |
302 if self.filterCheckBox.isChecked(): |
303 fileFilter = self.filterEdit.text() |
303 fileFilter = self.filterEdit.text() |
304 fileFilterList = \ |
304 fileFilterList = \ |
305 ["^{0}$".format(filter.replace(".", "\.").replace("*", ".*")) \ |
305 ["^{0}$".format(filter.replace(".", "\.").replace("*", ".*")) |
306 for filter in fileFilter.split(";")] |
306 for filter in fileFilter.split(";")] |
307 filterRe = re.compile("|".join(fileFilterList)) |
307 filterRe = re.compile("|".join(fileFilterList)) |
308 |
308 |
309 if self.projectButton.isChecked(): |
309 if self.projectButton.isChecked(): |
310 if self.filterCheckBox.isChecked(): |
310 if self.filterCheckBox.isChecked(): |
311 files = [self.project.getRelativePath(file) \ |
311 files = [self.project.getRelativePath(file) |
312 for file in \ |
312 for file in |
313 self.__getFileList( |
313 self.__getFileList( |
314 self.project.getProjectPath(), filterRe)] |
314 self.project.getProjectPath(), filterRe)] |
315 else: |
315 else: |
316 files = [] |
316 files = [] |
317 if self.sourcesCheckBox.isChecked(): |
317 if self.sourcesCheckBox.isChecked(): |
318 files += self.project.pdata["SOURCES"] |
318 files += self.project.pdata["SOURCES"] |
319 if self.formsCheckBox.isChecked(): |
319 if self.formsCheckBox.isChecked(): |
328 if self.sourcesCheckBox.isChecked(): |
328 if self.sourcesCheckBox.isChecked(): |
329 filters.extend( |
329 filters.extend( |
330 ["^{0}$".format( |
330 ["^{0}$".format( |
331 assoc.replace(".", "\.").replace("*", ".*")) |
331 assoc.replace(".", "\.").replace("*", ".*")) |
332 for assoc in list( |
332 for assoc in list( |
333 Preferences.getEditorLexerAssocs().keys()) |
333 Preferences.getEditorLexerAssocs().keys()) |
334 if assoc not in self.formsExt + self.interfacesExt]) |
334 if assoc not in self.formsExt + self.interfacesExt]) |
335 if self.formsCheckBox.isChecked(): |
335 if self.formsCheckBox.isChecked(): |
336 filters.append(self.filterForms) |
336 filters.append(self.filterForms) |
337 if self.interfacesCheckBox.isChecked(): |
337 if self.interfacesCheckBox.isChecked(): |
338 filters.append(self.filterInterfaces) |
338 filters.append(self.filterInterfaces) |
555 @return list of files to be processed (list of strings) |
555 @return list of files to be processed (list of strings) |
556 """ |
556 """ |
557 path = os.path.abspath(path) |
557 path = os.path.abspath(path) |
558 files = [] |
558 files = [] |
559 for dirname, _, names in os.walk(path): |
559 for dirname, _, names in os.walk(path): |
560 files.extend([os.path.join(dirname, f) \ |
560 files.extend([os.path.join(dirname, f) |
561 for f in names \ |
561 for f in names |
562 if re.match(filterRe, f)] |
562 if re.match(filterRe, f)] |
563 ) |
563 ) |
564 return files |
564 return files |
565 |
565 |
566 def setSearchDirectory(self, searchDir): |
566 def setSearchDirectory(self, searchDir): |
567 """ |
567 """ |
568 Public slot to set the name of the directory to search in. |
568 Public slot to set the name of the directory to search in. |
609 E5MessageBox.critical( |
609 E5MessageBox.critical( |
610 self, |
610 self, |
611 self.trUtf8("Replace in Files"), |
611 self.trUtf8("Replace in Files"), |
612 self.trUtf8( |
612 self.trUtf8( |
613 """<p>Could not read the file <b>{0}</b>.""" |
613 """<p>Could not read the file <b>{0}</b>.""" |
614 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
614 """ Skipping it.</p><p>Reason: {1}</p>""") |
615 .format(fn, str(err)) |
615 .format(fn, str(err)) |
616 ) |
616 ) |
617 progress += 1 |
617 progress += 1 |
618 self.findProgress.setValue(progress) |
618 self.findProgress.setValue(progress) |
619 continue |
619 continue |
620 |
620 |
625 self, |
625 self, |
626 self.trUtf8("Replace in Files"), |
626 self.trUtf8("Replace in Files"), |
627 self.trUtf8( |
627 self.trUtf8( |
628 """<p>The current and the original hash of the""" |
628 """<p>The current and the original hash of the""" |
629 """ file <b>{0}</b> are different. Skipping it.""" |
629 """ file <b>{0}</b> are different. Skipping it.""" |
630 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""")\ |
630 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""") |
631 .format(fn, origHash, hash) |
631 .format(fn, origHash, hash) |
632 ) |
632 ) |
633 progress += 1 |
633 progress += 1 |
634 self.findProgress.setValue(progress) |
634 self.findProgress.setValue(progress) |
635 continue |
635 continue |
636 |
636 |
650 E5MessageBox.critical( |
650 E5MessageBox.critical( |
651 self, |
651 self, |
652 self.trUtf8("Replace in Files"), |
652 self.trUtf8("Replace in Files"), |
653 self.trUtf8( |
653 self.trUtf8( |
654 """<p>Could not save the file <b>{0}</b>.""" |
654 """<p>Could not save the file <b>{0}</b>.""" |
655 """ Skipping it.</p><p>Reason: {1}</p>""")\ |
655 """ Skipping it.</p><p>Reason: {1}</p>""") |
656 .format(fn, str(err)) |
656 .format(fn, str(err)) |
657 ) |
657 ) |
658 |
658 |
659 progress += 1 |
659 progress += 1 |
660 self.findProgress.setValue(progress) |
660 self.findProgress.setValue(progress) |
661 |
661 |