--- a/src/eric7/UI/FindFileWidget.py Sun Dec 04 10:34:43 2022 +0100 +++ b/src/eric7/UI/FindFileWidget.py Sun Dec 04 11:58:37 2022 +0100 @@ -148,22 +148,7 @@ self.__project = project - # populate the file type list - for fileCategory in [ - c - for c in self.__project.getFileCategories() - if c not in ("TRANSLATIONS", "OTHERS") - ]: - itm = QListWidgetItem( - self.__project.getFileCategoryType(fileCategory), self.fileTypeList - ) - itm.setData(Qt.ItemDataRole.UserRole, fileCategory) - itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable) - itm.setCheckState( - Qt.CheckState.Checked - if fileCategory == "SOURCES" - else Qt.CheckState.Unchecked - ) + self.populateFileCategories() # ensure the file type tab is the current one self.fileOptionsWidget.setCurrentWidget(self.fileTypeTab) @@ -187,6 +172,45 @@ self.__replaceMode = True self.__toggleReplaceMode() + def populateFileCategories(self): + """ + Public method to populate the search file categories list. + """ + # step 1: remember checked entries categories + checkedCategories = [] + for row in range(self.fileTypeList.count()): + itm = self.fileTypeList.item(row) + if itm.checkState() == Qt.CheckState.Checked: + checkedCategories.append(itm.data(Qt.ItemDataRole.UserRole)) + + # step 2: clear the list + self.fileTypeList.clear() + + # step 3: populate the file type list + for fileCategory in [ + c + for c in self.__project.getFileCategories() + if c not in ("TRANSLATIONS", "OTHERS") + ]: + itm = QListWidgetItem( + self.__project.getFileCategoryType(fileCategory), self.fileTypeList + ) + itm.setData(Qt.ItemDataRole.UserRole, fileCategory) + itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable) + if bool(checkedCategories): + itm.setCheckState( + Qt.CheckState.Checked + if fileCategory in checkedCategories + else Qt.CheckState.Unchecked + ) + else: + # first time population + itm.setCheckState( + Qt.CheckState.Checked + if fileCategory == "SOURCES" + else Qt.CheckState.Unchecked + ) + def __createItem(self, file, line, text, start, end, replTxt="", md5=""): """ Private method to create an entry in the file list. @@ -247,6 +271,8 @@ (defaults to False) @type bool (optional) """ + self.populateFileCategories() + if self.__project.isOpen(): self.projectButton.setEnabled(True) self.projectButton.setChecked(True) @@ -978,6 +1004,12 @@ self.__buttonBox.accepted.connect(self.accept) self.__buttonBox.rejected.connect(self.reject) + def populateFileCategories(self): + """ + Public method to populate the search file categories list. + """ + self.__findWidget.populateFileCategories() + def activate(self, replaceMode=False, txt="", searchDir="", openFiles=False): """ Public method to activate the dialog with a given mode, a text