src/eric7/UI/FindFileWidget.py

branch
eric7
changeset 11052
316be9cd43bc
parent 11006
a671918232f3
child 11090
f5f5f5803935
equal deleted inserted replaced
11051:e8a7be10b76c 11052:316be9cd43bc
91 self.caseToolButton.setIcon(EricPixmapCache.getIcon("caseSensitive")) 91 self.caseToolButton.setIcon(EricPixmapCache.getIcon("caseSensitive"))
92 self.wordToolButton.setIcon(EricPixmapCache.getIcon("wholeWord")) 92 self.wordToolButton.setIcon(EricPixmapCache.getIcon("wholeWord"))
93 self.escapeToolButton.setIcon(EricPixmapCache.getIcon("esc-code")) 93 self.escapeToolButton.setIcon(EricPixmapCache.getIcon("esc-code"))
94 self.regexpToolButton.setIcon(EricPixmapCache.getIcon("regexp")) 94 self.regexpToolButton.setIcon(EricPixmapCache.getIcon("regexp"))
95 self.filtersConfigButton.setIcon(EricPixmapCache.getIcon("edit")) 95 self.filtersConfigButton.setIcon(EricPixmapCache.getIcon("edit"))
96 self.excludeFiltersConfigButton.setIcon(EricPixmapCache.getIcon("edit"))
96 97
97 self.dirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) 98 self.dirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE)
98 self.dirPicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) 99 self.dirPicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop)
99 self.dirPicker.setSizeAdjustPolicy( 100 self.dirPicker.setSizeAdjustPolicy(
100 QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon 101 QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon
150 EricUtilities.toBool( 151 EricUtilities.toBool(
151 Preferences.getSettings().value("FindFileWidget/ExcludeHidden", True) 152 Preferences.getSettings().value("FindFileWidget/ExcludeHidden", True)
152 ) 153 )
153 ) 154 )
154 155
155 self.__populateFiltersSelector() 156 self.__populateFilterSelectors()
156 self.populateFileCategories() 157 self.populateFileCategories()
158
159 self.excludeFilterCheckBox.setChecked(
160 EricUtilities.toBool(
161 Preferences.getSettings().value("FindFileWidget/ExcludeFilter", False)
162 )
163 )
164 self.excludeFilterComboBox.setCurrentText(
165 Preferences.getSettings().value("FindFileWidget/ExcludeFilterName", "")
166 )
157 167
158 # ensure the file type tab is the current one 168 # ensure the file type tab is the current one
159 self.fileOptionsWidget.setCurrentWidget(self.fileTypeTab) 169 self.fileOptionsWidget.setCurrentWidget(self.fileTypeTab)
160 170
161 self.__project.projectOpened.connect(self.__projectOpened) 171 self.__project.projectOpened.connect(self.__projectOpened)
175 self.customContextMenuRequested.connect(self.__contextMenuRequested) 185 self.customContextMenuRequested.connect(self.__contextMenuRequested)
176 186
177 self.__replaceMode = True 187 self.__replaceMode = True
178 self.__toggleReplaceMode() 188 self.__toggleReplaceMode()
179 189
180 def __populateFiltersSelector(self): 190 def __populateFilterSelectors(self):
181 """ 191 """
182 Private method to (re-)populate the file filters selector. 192 Private method to (re-)populate the file filters selector.
183 """ 193 """
184 currentFilter = self.filterComboBox.currentText() 194 currentFilter = self.filterComboBox.currentText()
185 self.filterComboBox.clear() 195 self.filterComboBox.clear()
196
197 currentExcludeFilter = self.excludeFilterComboBox.currentText()
198 self.excludeFilterComboBox.clear()
186 199
187 # add standard entries 200 # add standard entries
188 self.filterComboBox.addItem("") 201 self.filterComboBox.addItem("")
189 self.filterComboBox.addItem(self.tr("All Files"), ["*"]) 202 self.filterComboBox.addItem(self.tr("All Files"), ["*"])
203
204 self.excludeFilterComboBox.addItem("")
190 205
191 # add configured entries 206 # add configured entries
192 # FileFilters is a dictionary with the filter name as key and 207 # FileFilters is a dictionary with the filter name as key and
193 # a list of file name patterns as value 208 # a list of file name patterns as value
194 self.__filters = json.loads( 209 self.__filters = json.loads(
200 self.tr("{0} ({1})").format( 215 self.tr("{0} ({1})").format(
201 fileFilter, " ".join(self.__filters[fileFilter]) 216 fileFilter, " ".join(self.__filters[fileFilter])
202 ), 217 ),
203 self.__filters[fileFilter], 218 self.__filters[fileFilter],
204 ) 219 )
220 # ExcludeFileFilters is a dictionary with the filter name as key and
221 # a list of file name patterns as value
222 self.__excludeFilters = json.loads(
223 Preferences.getSettings().value("FindFileWidget/ExcludeFileFilters", "{}")
224 # noqa: M613
225 )
226 for fileFilter in sorted(self.__excludeFilters):
227 self.excludeFilterComboBox.addItem(
228 self.tr("{0} ({1})").format(
229 fileFilter, " ".join(self.__excludeFilters[fileFilter])
230 ),
231 self.__excludeFilters[fileFilter],
232 )
205 233
206 # reselect the current entry 234 # reselect the current entry
207 index = self.filterComboBox.findText(currentFilter) 235 index = self.filterComboBox.findText(currentFilter)
208 if index == -1: 236 if index == -1:
209 index = 0 237 index = 0
210 self.filterComboBox.setCurrentIndex(index) 238 self.filterComboBox.setCurrentIndex(index)
239
240 index = self.excludeFilterComboBox.findText(currentExcludeFilter)
241 if index == -1:
242 index = 0
243 self.excludeFilterComboBox.setCurrentIndex(index)
211 244
212 def populateFileCategories(self): 245 def populateFileCategories(self):
213 """ 246 """
214 Public method to populate the search file categories list. 247 Public method to populate the search file categories list.
215 """ 248 """
416 if dlg.exec() == QDialog.DialogCode.Accepted: 449 if dlg.exec() == QDialog.DialogCode.Accepted:
417 filters = dlg.getFilters() 450 filters = dlg.getFilters()
418 Preferences.getSettings().setValue( 451 Preferences.getSettings().setValue(
419 "FindFileWidget/FileFilters", json.dumps(filters) 452 "FindFileWidget/FileFilters", json.dumps(filters)
420 ) 453 )
421 self.__populateFiltersSelector() 454 self.__populateFilterSelectors()
455
456 @pyqtSlot()
457 def on_excludeFiltersConfigButton_clicked(self):
458 """
459 Private slot to edit the list of defined exclude file filter entries.
460 """
461 from .FindFileFiltersEditDialog import FindFileFiltersEditDialog
462
463 dlg = FindFileFiltersEditDialog(self.__excludeFilters, parent=self)
464 if dlg.exec() == QDialog.DialogCode.Accepted:
465 filters = dlg.getFilters()
466 Preferences.getSettings().setValue(
467 "FindFileWidget/ExcludeFileFilters", json.dumps(filters)
468 )
469 self.__populateFilterSelectors()
422 470
423 @pyqtSlot(str) 471 @pyqtSlot(str)
424 def on_findtextCombo_editTextChanged(self, text): 472 def on_findtextCombo_editTextChanged(self, text):
425 """ 473 """
426 Private slot to handle the editTextChanged signal of the find 474 Private slot to handle the editTextChanged signal of the find
483 531
484 @pyqtSlot(int) 532 @pyqtSlot(int)
485 def on_filterComboBox_currentIndexChanged(self, index): 533 def on_filterComboBox_currentIndexChanged(self, index):
486 """ 534 """
487 Private slot to handle the selection of a file filter. 535 Private slot to handle the selection of a file filter.
536
537 @param index index of the selected entry
538 @type int
539 """
540 self.__enableFindButton()
541
542 @pyqtSlot()
543 def on_excludeFilterCheckBox_clicked(self):
544 """
545 Private slot to handle the selection of the exclude file filter check box.
546 """
547 self.__enableFindButton()
548
549 @pyqtSlot(int)
550 def on_excludeFilterComboBox_currentIndexChanged(self, index):
551 """
552 Private slot to handle the selection of an exclude file filter.
488 553
489 @param index index of the selected entry 554 @param index index of the selected entry
490 @type int 555 @type int
491 """ 556 """
492 self.__enableFindButton() 557 self.__enableFindButton()
508 or ( 573 or (
509 self.filterCheckBox.isChecked() 574 self.filterCheckBox.isChecked()
510 and self.filterComboBox.currentText() == "" 575 and self.filterComboBox.currentText() == ""
511 ) 576 )
512 or (self.projectButton.isChecked() and not self.__project.isOpen()) 577 or (self.projectButton.isChecked() and not self.__project.isOpen())
578 or (
579 self.excludeFilterCheckBox.isChecked()
580 and self.excludeFilterComboBox.currentText() == ""
581 )
513 ): 582 ):
514 self.findButton.setEnabled(False) 583 self.findButton.setEnabled(False)
515 else: 584 else:
516 self.findButton.setEnabled(True) 585 self.findButton.setEnabled(True)
517 586
557 and not ericApp().getObject("ViewManager").checkAllDirty() 626 and not ericApp().getObject("ViewManager").checkAllDirty()
558 ): 627 ):
559 return 628 return
560 629
561 self.__cancelSearch = False 630 self.__cancelSearch = False
631 filterRe = None
632 excludeFilterRe = None
562 633
563 if self.filterCheckBox.isChecked(): 634 if self.filterCheckBox.isChecked():
564 fileFilter = self.filterComboBox.currentData() 635 fileFilter = self.filterComboBox.currentData()
565 fileFilterPattern = "|".join( 636 fileFilterPattern = "|".join(
566 self.__buildReFileFilter(filter) for filter in fileFilter 637 self.__buildReFileFilter(filter) for filter in fileFilter
567 ) 638 )
568 filterRe = re.compile(fileFilterPattern) 639 filterRe = re.compile(fileFilterPattern)
640
641 if self.excludeFilterCheckBox.isChecked():
642 excludeFileFilter = self.excludeFilterComboBox.currentData()
643 excludeFileFilterPattern = "|".join(
644 self.__buildReFileFilter(filter) for filter in excludeFileFilter
645 )
646 excludeFilterRe = re.compile(excludeFileFilterPattern)
569 647
570 if self.projectButton.isChecked(): 648 if self.projectButton.isChecked():
571 if self.filterCheckBox.isChecked(): 649 if self.filterCheckBox.isChecked():
572 files = [ 650 files = [
573 self.__project.getRelativePath(file) 651 self.__project.getRelativePath(file)
631 filterString = "|".join(filters) 709 filterString = "|".join(filters)
632 filterRe = re.compile(filterString) 710 filterRe = re.compile(filterString)
633 files = self.__getFileList( 711 files = self.__getFileList(
634 os.path.abspath(self.dirPicker.currentText()), 712 os.path.abspath(self.dirPicker.currentText()),
635 filterRe, 713 filterRe,
714 None,
636 excludeHiddenDirs=self.excludeHiddenCheckBox.isChecked(), 715 excludeHiddenDirs=self.excludeHiddenCheckBox.isChecked(),
637 excludeHiddenFiles=self.excludeHiddenCheckBox.isChecked(), 716 excludeHiddenFiles=self.excludeHiddenCheckBox.isChecked(),
638 ) 717 )
639 elif self.openFilesButton.isChecked(): 718 elif self.openFilesButton.isChecked():
640 vm = ericApp().getObject("ViewManager") 719 vm = ericApp().getObject("ViewManager")
641 vm.checkAllDirty() 720 vm.checkAllDirty()
642 files = vm.getOpenFilenames() 721 files = vm.getOpenFilenames()
722
723 if excludeFilterRe:
724 files = [f for f in files if not excludeFilterRe.match(os.path.basename(f))]
643 725
644 self.findList.clear() 726 self.findList.clear()
645 self.findProgressLabel.setPath("") 727 self.findProgressLabel.setPath("")
646 self.findProgress.setValue(0) 728 self.findProgress.setValue(0)
647 self.findProgress.setMaximum(len(files)) 729 self.findProgress.setMaximum(len(files))
683 Preferences.getSettings().setValue( 765 Preferences.getSettings().setValue(
684 "FindFileWidget/SearchHistory", self.searchHistory[:30] 766 "FindFileWidget/SearchHistory", self.searchHistory[:30]
685 ) 767 )
686 Preferences.getSettings().setValue( 768 Preferences.getSettings().setValue(
687 "FindFileWidget/ExcludeHidden", self.excludeHiddenCheckBox.isChecked() 769 "FindFileWidget/ExcludeHidden", self.excludeHiddenCheckBox.isChecked()
770 )
771 Preferences.getSettings().setValue(
772 "FindFileWidget/ExcludeFilter", self.excludeFilterCheckBox.isChecked()
773 )
774 Preferences.getSettings().setValue(
775 "FindFileWidget/ExcludeFilterName", self.excludeFilterComboBox.currentText()
688 ) 776 )
689 777
690 if self.__replaceMode: 778 if self.__replaceMode:
691 replTxt = self.replacetextCombo.currentText() 779 replTxt = self.replacetextCombo.currentText()
692 if replTxt in self.replaceHistory: 780 if replTxt in self.replaceHistory:
893 [ 981 [
894 os.path.join(dirname, f) 982 os.path.join(dirname, f)
895 for f in filenames 983 for f in filenames
896 if ( 984 if (
897 not (excludeHiddenFiles and f.startswith(".")) 985 not (excludeHiddenFiles and f.startswith("."))
898 and re.match(filterRe, f) 986 and (filterRe and filterRe.match(f))
899 ) 987 )
900 ] 988 ]
901 ) 989 )
902 if excludeHiddenDirs: 990 if excludeHiddenDirs:
903 for d in dirs[:]: 991 for d in dirs[:]:

eric ide

mercurial