src/eric7/Project/Project.py

branch
eric7
changeset 10256
1b728f26d1ae
parent 10154
d833c6a8c41f
child 10263
f4bb67586615
equal deleted inserted replaced
10255:a25f95af0a51 10256:1b728f26d1ae
710 @return list of known file categories 710 @return list of known file categories
711 @rtype list of str 711 @rtype list of str
712 """ 712 """
713 return list(self.__fileCategoriesRepository.keys()) 713 return list(self.__fileCategoriesRepository.keys())
714 714
715 def getFileCategoryFilters(
716 self, categories=None, withOthers=False, withAll=True
717 ):
718 """
719 Public method to get a list of file selection filters for the given categories.
720
721 @param categories list of file type categories (defaults to None).
722 A value of None means all categories except 'OTHERS'.
723 @type list of str (optional)
724 @param withOthers flag indicating to include the 'OTHERS' category
725 (defaults to False)
726 @type bool (optional)
727 @param withAll flag indicating to include a filter for 'All Files'
728 (defaults to True)
729 @type bool (optional)
730 @return list of file selection filter strings
731 @rtype list of str
732 """
733 if categories is None:
734 categories = [c for c in self.__fileCategoriesRepository if c != "OTHERS"]
735 if withOthers:
736 categories.append("OTHERS")
737
738 patterns = collections.defaultdict(list)
739 for pattern, filetype in self.__pdata["FILETYPES"].items():
740 if filetype in categories and filetype in self.__fileCategoriesRepository:
741 patterns[filetype].append(pattern)
742
743 filters = []
744 for filetype in patterns:
745 filters.append(
746 self.__fileCategoriesRepository[
747 filetype.upper()
748 ].fileCategoryFilterTemplate.format(
749 " ".join(sorted(patterns[filetype]))
750 )
751 )
752 filters = sorted(filters)
753 if withAll:
754 filters.append(self.tr("All Files (*)"))
755
756 return filters
757
715 def getFileCategoryFilterString( 758 def getFileCategoryFilterString(
716 self, categories=None, withOthers=False, withAll=True 759 self, categories=None, withOthers=False, withAll=True
717 ): 760 ):
718 """ 761 """
719 Public method to get a file selection string for the given categories. 762 Public method to get a file selection string for the given categories.
728 (defaults to True) 771 (defaults to True)
729 @type bool (optional) 772 @type bool (optional)
730 @return file selection filter string 773 @return file selection filter string
731 @rtype str 774 @rtype str
732 """ 775 """
733 if categories is None: 776 return ";;".join(
734 categories = [c for c in self.__fileCategoriesRepository if c != "OTHERS"] 777 self.getFileCategoryFilters(
735 if withOthers: 778 categ=categories, withOthers=withOthers, withAll=withAll
736 categories.append("OTHERS") 779 )
737 780 )
738 patterns = collections.defaultdict(list)
739 for pattern, filetype in self.__pdata["FILETYPES"].items():
740 if filetype in categories and filetype in self.__fileCategoriesRepository:
741 patterns[filetype].append(pattern)
742
743 filters = []
744 for filetype in patterns:
745 filters.append(
746 self.__fileCategoriesRepository[
747 filetype.upper()
748 ].fileCategoryFilterTemplate.format(
749 " ".join(sorted(patterns[filetype]))
750 )
751 )
752 filterString = ";;".join(sorted(filters))
753 if withAll:
754 filterString += ";;" + self.tr("All Files (*)")
755
756 return filterString
757 781
758 def getFileCategoryString(self, category): 782 def getFileCategoryString(self, category):
759 """ 783 """
760 Public method to get a user string for the given category. 784 Public method to get a user string for the given category.
761 785
1899 @param startdir start directory for the selection dialog 1923 @param startdir start directory for the selection dialog
1900 @type str 1924 @type str
1901 """ 1925 """
1902 from .AddFileDialog import AddFileDialog 1926 from .AddFileDialog import AddFileDialog
1903 1927
1904 if startdir is None: 1928 if not startdir:
1905 startdir = self.ppath 1929 startdir = self.ppath
1906 1930
1907 dlg = AddFileDialog(self, self.parent(), fileTypeFilter, startdir=startdir) 1931 dlg = AddFileDialog(self, self.parent(), fileTypeFilter, startdir=startdir)
1908 if dlg.exec() == QDialog.DialogCode.Accepted: 1932 if dlg.exec() == QDialog.DialogCode.Accepted:
1909 fnames, target, isSource = dlg.getData() 1933 fnames, target, isSource = dlg.getData()
2077 @param startdir start directory for the selection dialog 2101 @param startdir start directory for the selection dialog
2078 @type str 2102 @type str
2079 """ 2103 """
2080 from .AddDirectoryDialog import AddDirectoryDialog 2104 from .AddDirectoryDialog import AddDirectoryDialog
2081 2105
2082 if startdir is None: 2106 if not startdir:
2083 startdir = self.ppath 2107 startdir = self.ppath
2084 2108
2085 dlg = AddDirectoryDialog(self, fileTypeFilter, self.parent(), startdir=startdir) 2109 dlg = AddDirectoryDialog(self, fileTypeFilter, self.parent(), startdir=startdir)
2086 if dlg.exec() == QDialog.DialogCode.Accepted: 2110 if dlg.exec() == QDialog.DialogCode.Accepted:
2087 filetype, source, target, recursive = dlg.getData() 2111 filetype, source, target, recursive = dlg.getData()

eric ide

mercurial