src/eric7/Project/Project.py

branch
eric7
changeset 9516
0f023e61a9b5
parent 9515
275334bc9607
child 9517
d73c3a1e432b
diff -r 275334bc9607 -r 0f023e61a9b5 src/eric7/Project/Project.py
--- a/src/eric7/Project/Project.py	Wed Nov 16 11:04:18 2022 +0100
+++ b/src/eric7/Project/Project.py	Wed Nov 16 18:11:52 2022 +0100
@@ -7,6 +7,7 @@
 Module implementing the project management functionality.
 """
 
+import collections
 import contextlib
 import copy
 import fnmatch
@@ -547,6 +548,7 @@
             "LICENSE": "",
             "EMBEDDED_VENV": False,
         }
+        # TODO: Move these to a file categories repository
         self.__knownFileCategories = [
             "FORMS",
             "OTHERS",
@@ -556,6 +558,33 @@
             "INTERFACES",
             "PROTOCOLS",
         ]
+        self.__fileCategoryFilterTemplates = {
+            "FORMS": self.tr("Form Files ({0})"),
+            "OTHERS": self.tr("Other Files ({0})"),
+            "RESOURCES": self.tr("Resource Files ({0})"),
+            "SOURCES": self.tr("Source Files ({0})"),
+            "TRANSLATIONS": self.tr("Translation Files ({0})"),
+            "INTERFACES": self.tr("Interface Files ({0})"),
+            "PROTOCOLS": self.tr("Protocol Files ({0})"),
+        }
+        self.__fileCategoryUserStrings = {
+            "FORMS": self.tr("Form Files"),
+            "OTHERS": self.tr("Other Files"),
+            "RESOURCES": self.tr("Resource Files"),
+            "SOURCES": self.tr("Source Files"),
+            "TRANSLATIONS": self.tr("Translation Files"),
+            "INTERFACES": self.tr("Interface Files"),
+            "PROTOCOLS": self.tr("Protocol Files"),
+        }
+        self.__fileCategoryTyeStrings = {
+            "FORMS": self.tr("Forms"),
+            "OTHERS": self.tr("Others"),
+            "RESOURCES": self.tr("Resources"),
+            "SOURCES": self.tr("Sources"),
+            "TRANSLATIONS": self.tr("Translations"),
+            "INTERFACES": self.tr("Interfaces"),
+            "PROTOCOLS": self.tr("Protocols"),
+        }
 
         self.__initDebugProperties()
 
@@ -591,7 +620,7 @@
         except KeyError:
             return default
 
-    def setProjectData(self, data, dataKey=None):
+    def setProjectData(self, data, dataKey=None, setDirty=True):
         """
         Public method to set data associated with the given data key in the project
         dictionary
@@ -603,11 +632,14 @@
         @type Any
         @param dataKey key of the data to set (defaults to None)
         @type str (optional)
+        @param setDirty flag indicating to set the dirty flag if the data is different
+            from the current one (defaults to True)
+        @type bool (optional)
         """
         if dataKey is None:
             self.__pdata.update(data)
         else:
-            if self.__pdata[dataKey] == data:
+            if self.__pdata[dataKey] != data and setDirty:
                 self.setDirty(True)
             self.__pdata[dataKey] = data
 
@@ -686,6 +718,69 @@
         """
         return self.__knownFileCategories[:]
 
+    def getFileCategoryFilterString(
+        self, categories=None, withOthers=False, withAll=True
+    ):
+        """
+        Public method to get a file selection string for the given categories.
+
+        @param categories list of file type categories (defaults to None).
+            A value of None means all categories except 'OTHERS'.
+        @type list of str (optional)
+        @param withOthers flag indicating to include the 'OTHERS' category
+            (defaults to False)
+        @type bool (optional)
+        @param withAll flag indicating to include a filter for 'All Files'
+            (defaults to True)
+        @type bool (optional)
+        @return file selection filter string
+        @rtype str
+        """
+        if categories is None:
+            categories = [c for c in self.__knownFileCategories if c != "OTHERS"]
+            if withOthers:
+                categories.append("OTHERS")
+
+        patterns = collections.defaultdict(list)
+        for pattern, filetype in self.__pdata["FILETYPES"].items():
+            if filetype in categories and filetype in self.__knownFileCategories:
+                patterns[filetype].append(pattern)
+
+        filters = []
+        for filetype in patterns:
+            filters.append(
+                self.__fileCategoryFilterTemplates[filetype].format(
+                    " ".join(sorted(patterns[filetype]))
+                )
+            )
+        filterString = ";;".join(sorted(filters))
+        if withAll:
+            filterString += ";;" + self.tr("All Files (*)")
+
+        return filterString
+
+    def getFileCategoryString(self, category):
+        """
+        Public method to get a user string for the given category.
+
+        @param category file type category
+        @type str
+        @return user string for the category
+        @rtype str
+        """
+        return self.__fileCategoryUserStrings[category]
+
+    def getFileCategoryType(self, category):
+        """
+        Public method to get a user type string for the given category.
+
+        @param category file type category
+        @type str
+        @return user type string for the category
+        @rtype str
+        """
+        return self.__fileCategoryTyeStrings[category]
+
     def initFileTypes(self):
         """
         Public method to initialize the filetype associations with default
@@ -2026,82 +2121,82 @@
             if os.path.isdir(fn) and fn not in self.otherssubdirs:
                 self.otherssubdirs.append(fn)
 
-    def addSourceFiles(self):
-        """
-        Public slot to add source files to the current project.
-        """
-        self.addFiles("source")
-
-    def addUiFiles(self):
-        """
-        Public slot to add forms to the current project.
-        """
-        self.addFiles("form")
-
-    def addIdlFiles(self):
-        """
-        Public slot to add IDL interfaces to the current project.
-        """
-        self.addFiles("interface")
-
-    def addProtoFiles(self):
-        """
-        Public slot to add protocol files to the current project.
-        """
-        self.addFiles("protocol")
-
-    def addResourceFiles(self):
-        """
-        Public slot to add Qt resources to the current project.
-        """
-        self.addFiles("resource")
-
-    def addOthersFiles(self):
-        """
-        Public slot to add files to the OTHERS project data.
-        """
-        self.addFiles("others")
-
-    def addSourceDir(self):
-        """
-        Public slot to add all source files of a directory to the current
-        project.
-        """
-        self.addDirectory("source")
-
-    def addUiDir(self):
-        """
-        Public slot to add all forms of a directory to the current project.
-        """
-        self.addDirectory("form")
-
-    def addIdlDir(self):
-        """
-        Public slot to add all IDL interfaces of a directory to the current
-        project.
-        """
-        self.addDirectory("interface")
-
-    def addProtoDir(self):
-        """
-        Public slot to add all protocol files of a directory to the current
-        project.
-        """
-        self.addDirectory("protocol")
-
-    def addResourceDir(self):
-        """
-        Public slot to add all Qt resource files of a directory to the current
-        project.
-        """
-        self.addDirectory("resource")
-
-    def addOthersDir(self):
-        """
-        Public slot to add a directory to the OTHERS project data.
-        """
-        self.addDirectory("others")
-
+    ##def addSourceFiles(self):
+        ##"""
+        ##Public slot to add source files to the current project.
+        ##"""
+        ##self.addFiles("source")
+##
+    ##def addUiFiles(self):
+        ##"""
+        ##Public slot to add forms to the current project.
+        ##"""
+        ##self.addFiles("form")
+##
+    ##def addIdlFiles(self):
+        ##"""
+        ##Public slot to add IDL interfaces to the current project.
+        ##"""
+        ##self.addFiles("interface")
+##
+    ##def addProtoFiles(self):
+        ##"""
+        ##Public slot to add protocol files to the current project.
+        ##"""
+        ##self.addFiles("protocol")
+##
+    ##def addResourceFiles(self):
+        ##"""
+        ##Public slot to add Qt resources to the current project.
+        ##"""
+        ##self.addFiles("resource")
+##
+    ##def addOthersFiles(self):
+        ##"""
+        ##Public slot to add files to the OTHERS project data.
+        ##"""
+        ##self.addFiles("others")
+##
+    ##def addSourceDir(self):
+        ##"""
+        ##Public slot to add all source files of a directory to the current
+        ##project.
+        ##"""
+        ##self.addDirectory("source")
+##
+    ##def addUiDir(self):
+        ##"""
+        ##Public slot to add all forms of a directory to the current project.
+        ##"""
+        ##self.addDirectory("form")
+##
+    ##def addIdlDir(self):
+        ##"""
+        ##Public slot to add all IDL interfaces of a directory to the current
+        ##project.
+        ##"""
+        ##self.addDirectory("interface")
+##
+    ##def addProtoDir(self):
+        ##"""
+        ##Public slot to add all protocol files of a directory to the current
+        ##project.
+        ##"""
+        ##self.addDirectory("protocol")
+##
+    ##def addResourceDir(self):
+        ##"""
+        ##Public slot to add all Qt resource files of a directory to the current
+        ##project.
+        ##"""
+        ##self.addDirectory("resource")
+##
+    ##def addOthersDir(self):
+        ##"""
+        ##Public slot to add a directory to the OTHERS project data.
+        ##"""
+        ##self.addDirectory("others")
+##
     def renameMainScript(self, oldfn, newfn):
         """
         Public method to rename the main script.
@@ -3106,9 +3201,8 @@
         Public method to get the list of file type associations for
         the given association type.
 
-        @param associationType type of the association (one of FORMS,
-            INTERFACES, OTHERS, PROTOCOLS, RESOURCES, SOURCES,
-            TRANSLATIONS or __IGNORE__)
+        @param associationType type of the association (one of the known file categories
+            or __IGNORE__)
         @type str
         @return list of file patterns for the given type
         @rtype list of str
@@ -3670,8 +3764,7 @@
         """
         Public method to get the file entries of the given type.
 
-        @param fileType project file type (one of SOURCES, FORMS, RESOURCES,
-            INTERFACES, PROTOCOLS, OTHERS, TRANSLATIONS)
+        @param fileType project file type (one of the known file categories)
         @type str
         @param normalized flag indicating normalized file names are wanted
         @type boolean
@@ -4167,7 +4260,7 @@
 
         return False
 
-    # TODO: change the following methods to a more generic logix using fileCategories
+    # TODO: change the following methods to a more generic logic using fileCategories
     def isProjectSource(self, fn):
         """
         Public method used to check, if the passed in filename belongs to the

eric ide

mercurial