143 Preferences.toBool( |
144 Preferences.toBool( |
144 Preferences.getSettings().value("FindFileWidget/ExcludeHidden", True) |
145 Preferences.getSettings().value("FindFileWidget/ExcludeHidden", True) |
145 ) |
146 ) |
146 ) |
147 ) |
147 |
148 |
|
149 self.__project = project |
|
150 |
|
151 # populate the file type list |
|
152 for fileCategory in [ |
|
153 c |
|
154 for c in self.__project.getFileCategories() |
|
155 if c not in ("TRANSLATIONS", "OTHERS") |
|
156 ]: |
|
157 itm = QListWidgetItem( |
|
158 self.__project.getFileCategoryType(fileCategory), self.fileTypeList |
|
159 ) |
|
160 itm.setData(Qt.ItemDataRole.UserRole, fileCategory) |
|
161 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable) |
|
162 itm.setCheckState( |
|
163 Qt.CheckState.Checked |
|
164 if fileCategory == "SOURCES" |
|
165 else Qt.CheckState.Unchecked |
|
166 ) |
|
167 |
148 # ensure the file type tab is the current one |
168 # ensure the file type tab is the current one |
149 self.fileOptionsWidget.setCurrentWidget(self.fileTypeTab) |
169 self.fileOptionsWidget.setCurrentWidget(self.fileTypeTab) |
150 |
170 |
151 self.project = project |
171 self.__project.projectOpened.connect(self.__projectOpened) |
152 self.project.projectOpened.connect(self.__projectOpened) |
172 self.__project.projectClosed.connect(self.__projectClosed) |
153 self.project.projectClosed.connect(self.__projectClosed) |
|
154 |
173 |
155 self.__standardListFont = self.findList.font() |
174 self.__standardListFont = self.findList.font() |
156 self.findList.headerItem().setText(self.findList.columnCount(), "") |
175 self.findList.headerItem().setText(self.findList.columnCount(), "") |
157 self.findList.header().setSortIndicator(0, Qt.SortOrder.AscendingOrder) |
176 self.findList.header().setSortIndicator(0, Qt.SortOrder.AscendingOrder) |
158 self.__section0Size = self.findList.header().sectionSize(0) |
177 self.__section0Size = self.findList.header().sectionSize(0) |
159 self.findList.setExpandsOnDoubleClick(False) |
178 self.findList.setExpandsOnDoubleClick(False) |
160 |
|
161 # TODO: move these to a project browser file category repository |
|
162 # Qt Designer form files |
|
163 self.filterForms = r".*\.ui$" |
|
164 self.formsExt = ["*.ui"] |
|
165 |
|
166 # Corba interface files |
|
167 self.filterInterfaces = r".*\.idl$" |
|
168 self.interfacesExt = ["*.idl"] |
|
169 |
|
170 # Protobuf protocol files |
|
171 self.filterProtocols = r".*\.proto$" |
|
172 self.protocolsExt = ["*.proto"] |
|
173 |
|
174 # Qt resources files |
|
175 self.filterResources = r".*\.qrc$" |
|
176 self.resourcesExt = ["*.qrc"] |
|
177 |
179 |
178 self.__cancelSearch = False |
180 self.__cancelSearch = False |
179 self.__lastFileItem = None |
181 self.__lastFileItem = None |
180 self.__populating = False |
182 self.__populating = False |
181 |
183 |
440 filterRe = re.compile("|".join(fileFilterList)) |
442 filterRe = re.compile("|".join(fileFilterList)) |
441 |
443 |
442 if self.projectButton.isChecked(): |
444 if self.projectButton.isChecked(): |
443 if self.filterCheckBox.isChecked(): |
445 if self.filterCheckBox.isChecked(): |
444 files = [ |
446 files = [ |
445 self.project.getRelativePath(file) |
447 self.__project.getRelativePath(file) |
446 for file in self.__getFileList( |
448 for file in self.__getFileList( |
447 self.project.getProjectPath(), |
449 self.__project.getProjectPath(), |
448 filterRe, |
450 filterRe, |
449 excludeHiddenDirs=self.excludeHiddenCheckBox.isChecked(), |
451 excludeHiddenDirs=self.excludeHiddenCheckBox.isChecked(), |
450 ) |
452 ) |
451 ] |
453 ] |
452 else: |
454 else: |
453 files = [] |
455 files = [] |
454 # TODO: make this more generic (using fileCategory) |
456 for row in range(self.fileTypeList.count()): |
455 if self.sourcesCheckBox.isChecked(): |
457 itm = self.fileTypeList.item(row) |
456 files += self.project.getProjectData(dataKey="SOURCES") |
458 if itm.checkState() == Qt.CheckState.Checked: |
457 if self.formsCheckBox.isChecked(): |
459 files += self.__project.getProjectData( |
458 files += self.project.getProjectData("FORMS") |
460 dataKey=itm.data(Qt.ItemDataRole.UserRole) |
459 if self.interfacesCheckBox.isChecked(): |
461 ) |
460 files += self.project.getProjectData("INTERFACES") |
|
461 if self.protocolsCheckBox.isChecked(): |
|
462 files += self.project.getProjectData("PROTOCOLS") |
|
463 if self.resourcesCheckBox.isChecked(): |
|
464 files += self.project.getProjectData("RESOURCES") |
|
465 elif self.dirButton.isChecked(): |
462 elif self.dirButton.isChecked(): |
466 if not self.filterCheckBox.isChecked(): |
463 if not self.filterCheckBox.isChecked(): |
467 filters = [] |
464 filters = [] |
468 if self.project.isOpen() and os.path.abspath( |
465 if self.__project.isOpen() and os.path.abspath( |
469 self.dirPicker.currentText() |
466 self.dirPicker.currentText() |
470 ).startswith(self.project.getProjectPath()): |
467 ).startswith(self.__project.getProjectPath()): |
471 if self.sourcesCheckBox.isChecked(): |
468 for row in range(self.fileTypeList.count()): |
472 filters.extend( |
469 itm = self.fileTypeList.item(row) |
473 [ |
470 if itm.checkState() == Qt.CheckState.Checked: |
474 "^{0}$".format( |
471 filters.extend( |
475 assoc.replace(".", r"\.").replace("*", ".*") |
472 [ |
|
473 "^{0}$".format( |
|
474 assoc.replace(".", r"\.").replace("*", ".*") |
|
475 ) |
|
476 for assoc in self.__project.getFiletypeAssociations( |
|
477 itm.data(Qt.ItemDataRole.UserRole) |
|
478 ) |
|
479 ] |
|
480 ) |
|
481 else: |
|
482 for row in range(self.fileTypeList.count()): |
|
483 itm = self.fileTypeList.item(row) |
|
484 if itm.checkState() == Qt.CheckState.Checked: |
|
485 fileType = itm.data(Qt.ItemDataRole.UserRole) |
|
486 if fileType == "SOURCES": |
|
487 filters.extend( |
|
488 [ |
|
489 "^{0}$".format( |
|
490 assoc.replace(".", r"\.").replace("*", ".*") |
|
491 ) |
|
492 for assoc in list( |
|
493 Preferences.getEditorLexerAssocs().keys() |
|
494 ) |
|
495 if assoc |
|
496 not in self.__project.getFileCategoryExtension( |
|
497 fileType, reverse=True |
|
498 ) |
|
499 ] |
476 ) |
500 ) |
477 for assoc in self.project.getFiletypeAssociations( |
501 else: |
478 "SOURCES" |
502 filters.extend( |
|
503 [ |
|
504 "^{0}$".format( |
|
505 ext.replace(".", r"\.").replace("*", ".*") |
|
506 ) |
|
507 for ext in self.__project.getFileCategoryExtension( |
|
508 # __IGNORE_WARNING__ |
|
509 fileType |
|
510 ) |
|
511 ] |
479 ) |
512 ) |
480 ] |
|
481 ) |
|
482 if self.formsCheckBox.isChecked(): |
|
483 filters.extend( |
|
484 [ |
|
485 "^{0}$".format( |
|
486 assoc.replace(".", r"\.").replace("*", ".*") |
|
487 ) |
|
488 for assoc in self.project.getFiletypeAssociations( |
|
489 "FORMS" |
|
490 ) |
|
491 ] |
|
492 ) |
|
493 if self.interfacesCheckBox.isChecked(): |
|
494 filters.extend( |
|
495 [ |
|
496 "^{0}$".format( |
|
497 assoc.replace(".", r"\.").replace("*", ".*") |
|
498 ) |
|
499 for assoc in self.project.getFiletypeAssociations( |
|
500 "INTERFACES" |
|
501 ) |
|
502 ] |
|
503 ) |
|
504 if self.protocolsCheckBox.isChecked(): |
|
505 filters.extend( |
|
506 [ |
|
507 "^{0}$".format( |
|
508 assoc.replace(".", r"\.").replace("*", ".*") |
|
509 ) |
|
510 for assoc in self.project.getFiletypeAssociations( |
|
511 "PROTOCOLS" |
|
512 ) |
|
513 ] |
|
514 ) |
|
515 if self.resourcesCheckBox.isChecked(): |
|
516 filters.extend( |
|
517 [ |
|
518 "^{0}$".format( |
|
519 assoc.replace(".", r"\.").replace("*", ".*") |
|
520 ) |
|
521 for assoc in self.project.getFiletypeAssociations( |
|
522 "RESOURCES" |
|
523 ) |
|
524 ] |
|
525 ) |
|
526 else: |
|
527 # TODO: make this more generic (use project browser type repository |
|
528 if self.sourcesCheckBox.isChecked(): |
|
529 filters.extend( |
|
530 [ |
|
531 "^{0}$".format( |
|
532 assoc.replace(".", r"\.").replace("*", ".*") |
|
533 ) |
|
534 for assoc in list( |
|
535 Preferences.getEditorLexerAssocs().keys() |
|
536 ) |
|
537 if assoc |
|
538 not in self.formsExt |
|
539 + self.interfacesExt |
|
540 + self.protocolsExt |
|
541 + self.resourcesExt |
|
542 ] |
|
543 ) |
|
544 if self.formsCheckBox.isChecked(): |
|
545 filters.append(self.filterForms) |
|
546 if self.interfacesCheckBox.isChecked(): |
|
547 filters.append(self.filterInterfaces) |
|
548 if self.protocolsCheckBox.isChecked(): |
|
549 filters.append(self.filterProtocols) |
|
550 if self.resourcesCheckBox.isChecked(): |
|
551 filters.append(self.filterResources) |
|
552 filterString = "|".join(filters) |
513 filterString = "|".join(filters) |
553 filterRe = re.compile(filterString) |
514 filterRe = re.compile(filterString) |
554 files = self.__getFileList( |
515 files = self.__getFileList( |
555 os.path.abspath(self.dirPicker.currentText()), |
516 os.path.abspath(self.dirPicker.currentText()), |
556 filterRe, |
517 filterRe, |