99 "FindFileDialog/DirectoryHistory")) |
99 "FindFileDialog/DirectoryHistory")) |
100 self.findtextCombo.addItems(self.searchHistory) |
100 self.findtextCombo.addItems(self.searchHistory) |
101 self.replacetextCombo.addItems(self.replaceHistory) |
101 self.replacetextCombo.addItems(self.replaceHistory) |
102 self.dirPicker.addItems(self.dirHistory) |
102 self.dirPicker.addItems(self.dirHistory) |
103 |
103 |
|
104 self.excludeHiddenCheckBox.setChecked(Preferences.toBool( |
|
105 Preferences.Prefs.settings.value( |
|
106 "FindFileDialog/ExcludeHidden", True) |
|
107 )) |
|
108 |
104 self.project = project |
109 self.project = project |
105 |
110 |
106 self.findList.headerItem().setText(self.findList.columnCount(), "") |
111 self.findList.headerItem().setText(self.findList.columnCount(), "") |
107 self.findList.header().setSortIndicator(0, Qt.AscendingOrder) |
112 self.findList.header().setSortIndicator(0, Qt.AscendingOrder) |
108 self.__section0Size = self.findList.header().sectionSize(0) |
113 self.__section0Size = self.findList.header().sectionSize(0) |
142 @param line line number (integer) |
147 @param line line number (integer) |
143 @param text text found (string) |
148 @param text text found (string) |
144 @param start start position of match (integer) |
149 @param start start position of match (integer) |
145 @param end end position of match (integer) |
150 @param end end position of match (integer) |
146 @param replTxt text with replacements applied (string) |
151 @param replTxt text with replacements applied (string) |
147 @keyparam md5 MD5 hash of the file (string) |
152 @param md5 MD5 hash of the file (string) |
148 """ |
153 """ |
149 if self.__lastFileItem is None: |
154 if self.__lastFileItem is None: |
150 # It's a new file |
155 # It's a new file |
151 self.__lastFileItem = QTreeWidgetItem(self.findList, [file]) |
156 self.__lastFileItem = QTreeWidgetItem(self.findList, [file]) |
152 self.__lastFileItem.setFirstColumnSpanned(True) |
157 self.__lastFileItem.setFirstColumnSpanned(True) |
153 self.__lastFileItem.setExpanded(True) |
158 self.__lastFileItem.setExpanded(True) |
154 if self.__replaceMode: |
159 if self.__replaceMode: |
155 self.__lastFileItem.setFlags( |
160 self.__lastFileItem.setFlags( |
156 self.__lastFileItem.flags() | |
161 self.__lastFileItem.flags() | |
157 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) |
162 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) |
158 # Qt bug: |
|
159 # item is not user checkable if setFirstColumnSpanned |
|
160 # is True (< 4.5.0) |
|
161 self.__lastFileItem.setData(0, self.md5Role, md5) |
163 self.__lastFileItem.setData(0, self.md5Role, md5) |
162 |
164 |
163 itm = QTreeWidgetItem(self.__lastFileItem) |
165 itm = QTreeWidgetItem(self.__lastFileItem) |
164 itm.setTextAlignment(0, Qt.AlignRight) |
166 itm.setTextAlignment(0, Qt.AlignRight) |
165 itm.setData(0, Qt.DisplayRole, line) |
167 itm.setData(0, Qt.DisplayRole, line) |
324 ] |
326 ] |
325 filterRe = re.compile("|".join(fileFilterList)) |
327 filterRe = re.compile("|".join(fileFilterList)) |
326 |
328 |
327 if self.projectButton.isChecked(): |
329 if self.projectButton.isChecked(): |
328 if self.filterCheckBox.isChecked(): |
330 if self.filterCheckBox.isChecked(): |
329 files = [self.project.getRelativePath(file) |
331 files = [ |
330 for file in |
332 self.project.getRelativePath(file) |
331 self.__getFileList( |
333 for file in |
332 self.project.getProjectPath(), filterRe)] |
334 self.__getFileList( |
|
335 self.project.getProjectPath(), |
|
336 filterRe, |
|
337 excludeHiddenDirs=self.excludeHiddenCheckBox |
|
338 .isChecked(), |
|
339 ) |
|
340 ] |
333 else: |
341 else: |
334 files = [] |
342 files = [] |
335 if self.sourcesCheckBox.isChecked(): |
343 if self.sourcesCheckBox.isChecked(): |
336 files += self.project.pdata["SOURCES"] |
344 files += self.project.pdata["SOURCES"] |
337 if self.formsCheckBox.isChecked(): |
345 if self.formsCheckBox.isChecked(): |
343 if self.resourcesCheckBox.isChecked(): |
351 if self.resourcesCheckBox.isChecked(): |
344 files += self.project.pdata["RESOURCES"] |
352 files += self.project.pdata["RESOURCES"] |
345 elif self.dirButton.isChecked(): |
353 elif self.dirButton.isChecked(): |
346 if not self.filterCheckBox.isChecked(): |
354 if not self.filterCheckBox.isChecked(): |
347 filters = [] |
355 filters = [] |
348 if self.sourcesCheckBox.isChecked(): |
356 if ( |
349 filters.extend( |
357 self.project.isOpen() and |
350 ["^{0}$".format( |
358 os.path.abspath(self.dirPicker.currentText()).startswith( |
351 assoc.replace(".", r"\.").replace("*", ".*")) |
359 self.project.getProjectPath()) |
352 for assoc in list( |
360 ): |
353 Preferences.getEditorLexerAssocs().keys()) |
361 if self.sourcesCheckBox.isChecked(): |
354 if assoc not in self.formsExt + self.interfacesExt + |
362 filters.extend([ |
355 self.protocolsExt]) |
363 "^{0}$".format( |
356 if self.formsCheckBox.isChecked(): |
364 assoc.replace(".", r"\.").replace("*", ".*") |
357 filters.append(self.filterForms) |
365 ) for assoc in |
358 if self.interfacesCheckBox.isChecked(): |
366 self.project.getFiletypeAssociations("SOURCES") |
359 filters.append(self.filterInterfaces) |
367 ]) |
360 if self.protocolsCheckBox.isChecked(): |
368 if self.formsCheckBox.isChecked(): |
361 filters.append(self.filterProtocols) |
369 filters.extend([ |
362 if self.resourcesCheckBox.isChecked(): |
370 "^{0}$".format( |
363 filters.append(self.filterResources) |
371 assoc.replace(".", r"\.").replace("*", ".*") |
|
372 ) for assoc in |
|
373 self.project.getFiletypeAssociations("FORMS") |
|
374 ]) |
|
375 if self.interfacesCheckBox.isChecked(): |
|
376 filters.extend([ |
|
377 "^{0}$".format( |
|
378 assoc.replace(".", r"\.").replace("*", ".*") |
|
379 ) for assoc in |
|
380 self.project.getFiletypeAssociations("INTERFACES") |
|
381 ]) |
|
382 if self.protocolsCheckBox.isChecked(): |
|
383 filters.extend([ |
|
384 "^{0}$".format( |
|
385 assoc.replace(".", r"\.").replace("*", ".*") |
|
386 ) for assoc in |
|
387 self.project.getFiletypeAssociations("PROTOCOLS") |
|
388 ]) |
|
389 if self.resourcesCheckBox.isChecked(): |
|
390 filters.extend([ |
|
391 "^{0}$".format( |
|
392 assoc.replace(".", r"\.").replace("*", ".*") |
|
393 ) for assoc in |
|
394 self.project.getFiletypeAssociations("RESOURCES") |
|
395 ]) |
|
396 else: |
|
397 if self.sourcesCheckBox.isChecked(): |
|
398 filters.extend([ |
|
399 "^{0}$".format( |
|
400 assoc.replace(".", r"\.").replace("*", ".*")) |
|
401 for assoc in list( |
|
402 Preferences.getEditorLexerAssocs().keys()) |
|
403 if assoc not in |
|
404 self.formsExt + self.interfacesExt + |
|
405 self.protocolsExt + self.resourcesExt |
|
406 ]) |
|
407 if self.formsCheckBox.isChecked(): |
|
408 filters.append(self.filterForms) |
|
409 if self.interfacesCheckBox.isChecked(): |
|
410 filters.append(self.filterInterfaces) |
|
411 if self.protocolsCheckBox.isChecked(): |
|
412 filters.append(self.filterProtocols) |
|
413 if self.resourcesCheckBox.isChecked(): |
|
414 filters.append(self.filterResources) |
364 filterString = "|".join(filters) |
415 filterString = "|".join(filters) |
365 filterRe = re.compile(filterString) |
416 filterRe = re.compile(filterString) |
366 files = self.__getFileList( |
417 files = self.__getFileList( |
367 os.path.abspath(self.dirPicker.currentText()), |
418 os.path.abspath(self.dirPicker.currentText()), |
368 filterRe) |
419 filterRe, |
|
420 excludeHiddenDirs=self.excludeHiddenCheckBox.isChecked(), |
|
421 excludeHiddenFiles=self.excludeHiddenCheckBox.isChecked(), |
|
422 ) |
369 elif self.openFilesButton.isChecked(): |
423 elif self.openFilesButton.isChecked(): |
370 vm = e5App().getObject("ViewManager") |
424 vm = e5App().getObject("ViewManager") |
371 vm.checkAllDirty() |
425 vm.checkAllDirty() |
372 files = vm.getOpenFilenames() |
426 files = vm.getOpenFilenames() |
373 |
427 |
409 self.findtextCombo.clear() |
463 self.findtextCombo.clear() |
410 self.findtextCombo.addItems(self.searchHistory) |
464 self.findtextCombo.addItems(self.searchHistory) |
411 Preferences.Prefs.settings.setValue( |
465 Preferences.Prefs.settings.setValue( |
412 "FindFileDialog/SearchHistory", |
466 "FindFileDialog/SearchHistory", |
413 self.searchHistory[:30]) |
467 self.searchHistory[:30]) |
|
468 Preferences.Prefs.settings.setValue( |
|
469 "FindFileDialog/ExcludeHidden", |
|
470 self.excludeHiddenCheckBox.isChecked()) |
414 |
471 |
415 if self.__replaceMode: |
472 if self.__replaceMode: |
416 replTxt = self.replacetextCombo.currentText() |
473 replTxt = self.replacetextCombo.currentText() |
417 if replTxt in self.replaceHistory: |
474 if replTxt in self.replaceHistory: |
418 self.replaceHistory.remove(replTxt) |
475 self.replaceHistory.remove(replTxt) |
562 if fn.endswith('.ui'): |
619 if fn.endswith('.ui'): |
563 self.designerFile.emit(fn) |
620 self.designerFile.emit(fn) |
564 else: |
621 else: |
565 self.sourceFile.emit(fn, line, "", start, end) |
622 self.sourceFile.emit(fn, line, "", start, end) |
566 |
623 |
567 def __getFileList(self, path, filterRe): |
624 def __getFileList(self, path, filterRe, excludeHiddenDirs=False, |
|
625 excludeHiddenFiles=False): |
568 """ |
626 """ |
569 Private method to get a list of files to search. |
627 Private method to get a list of files to search. |
570 |
628 |
571 @param path the root directory to search in (string) |
629 @param path the root directory to search in |
|
630 @type str |
572 @param filterRe regular expression defining the filter |
631 @param filterRe regular expression defining the filter |
573 criteria (regexp object) |
632 criteria |
574 @return list of files to be processed (list of strings) |
633 @type regexp object |
|
634 @param excludeHiddenDirs flag indicating to exclude hidden directories |
|
635 @type bool |
|
636 @param excludeHiddenFiles flag indicating to exclude hidden files |
|
637 @type bool |
|
638 @return list of files to be processed |
|
639 @rtype list of str |
575 """ |
640 """ |
576 path = os.path.abspath(path) |
641 path = os.path.abspath(path) |
577 files = [] |
642 files = [] |
578 for dirname, _, names in os.walk(path): |
643 for dirname, dirs, filenames in os.walk(path): |
579 files.extend([os.path.join(dirname, f) |
644 files.extend([ |
580 for f in names |
645 os.path.join(dirname, f) for f in filenames |
581 if re.match(filterRe, f)] |
646 if (not (excludeHiddenFiles and f.startswith(".")) and |
582 ) |
647 re.match(filterRe, f)) |
|
648 ]) |
|
649 if excludeHiddenDirs: |
|
650 for d in dirs[:]: |
|
651 if d .startswith("."): |
|
652 dirs.remove(d) |
583 return files |
653 return files |
584 |
654 |
585 def setSearchDirectory(self, searchDir): |
655 def setSearchDirectory(self, searchDir): |
586 """ |
656 """ |
587 Public slot to set the name of the directory to search in. |
657 Public slot to set the name of the directory to search in. |