src/eric7/Project/Project.py

branch
eric7
changeset 9610
b45bccbdf331
parent 9608
8dcfd48355df
child 9612
93b496cc3c88
diff -r c2f9c10c47cc -r b45bccbdf331 src/eric7/Project/Project.py
--- a/src/eric7/Project/Project.py	Sun Dec 11 15:49:39 2022 +0100
+++ b/src/eric7/Project/Project.py	Sun Dec 11 17:33:46 2022 +0100
@@ -795,7 +795,27 @@
         Public method to initialize the file type associations with default
         values.
         """
-        self.__pdata["FILETYPES"] = {
+        self.__pdata["FILETYPES"] = self.defaultFileTypes(
+            self.__pdata["PROGLANGUAGE"],
+            self.__pdata["MIXEDLANGUAGE"],
+            self.__pdata["PROJECTTYPE"],
+        )
+        self.setDirty(True)
+
+    def defaultFileTypes(self, progLanguage, isMixed, projectType):
+        """
+        Public method to get a dictionary containing the default file type associations.
+
+        @param progLanguage programming language (main language)
+        @type str
+        @param isMixed flag indicating a project with multiple programming languages
+        @type bool
+        @param projectType type of the project
+        @type str
+        @return dictionary containing the default file type associations
+        @rtype dict
+        """
+        fileTypesDict = {
             "*.txt": "OTHERS",
             "*.md": "OTHERS",
             "*.rst": "OTHERS",
@@ -815,24 +835,22 @@
         }
 
         # Sources
-        sourceKey = (
-            "Mixed" if self.__pdata["MIXEDLANGUAGE"] else self.__pdata["PROGLANGUAGE"]
-        )
+        sourceKey = "Mixed" if isMixed else progLanguage
         for ext in self.__sourceExtensions(sourceKey):
-            self.__pdata["FILETYPES"]["*{0}".format(ext)] = "SOURCES"
+            fileTypesDict["*{0}".format(ext)] = "SOURCES"
 
         # Forms
-        if self.__pdata["PROJECTTYPE"] in [
+        if projectType in [
             "E7Plugin",
             "PyQt5",
             "PyQt6",
             "PySide2",
             "PySide6",
         ]:
-            self.__pdata["FILETYPES"]["*.ui"] = "FORMS"
+            fileTypesDict["*.ui"] = "FORMS"
 
         # Resources
-        if self.__pdata["PROJECTTYPE"] in [
+        if projectType in [
             "PyQt5",
             "PyQt5C",
             "PySide2",
@@ -840,10 +858,10 @@
             "PySide6",
             "PySide6C",
         ]:
-            self.__pdata["FILETYPES"]["*.qrc"] = "RESOURCES"
+            fileTypesDict["*.qrc"] = "RESOURCES"
 
         # Translations
-        if self.__pdata["PROJECTTYPE"] in [
+        if projectType in [
             "E7Plugin",
             "PyQt5",
             "PyQt5C",
@@ -854,8 +872,8 @@
             "PySide6",
             "PySide6C",
         ]:
-            self.__pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS"
-            self.__pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS"
+            fileTypesDict["*.ts"] = "TRANSLATIONS"
+            fileTypesDict["*.qm"] = "TRANSLATIONS"
 
         # File categories handled by activated plugin project browsers
         for fileCategory in [
@@ -866,14 +884,14 @@
             for ext in self.__fileCategoriesRepository[
                 fileCategory
             ].fileCategoryExtensions:
-                self.__pdata["FILETYPES"][ext] = fileCategory
+                fileTypesDict[ext] = fileCategory
         # Project type specific ones
         with contextlib.suppress(KeyError):
-            if self.__fileTypeCallbacks[self.__pdata["PROJECTTYPE"]] is not None:
-                ftypes = self.__fileTypeCallbacks[self.__pdata["PROJECTTYPE"]]()
-                self.__pdata["FILETYPES"].update(ftypes)
-
-        self.setDirty(True)
+            if self.__fileTypeCallbacks[projectType] is not None:
+                ftypes = self.__fileTypeCallbacks[projectType]()
+                fileTypesDict.update(ftypes)
+
+        return fileTypesDict
 
     def updateFileTypes(self):
         """
@@ -2903,7 +2921,7 @@
 
         dlg = PropertiesDialog(self, new=False)
         if dlg.exec() == QDialog.DialogCode.Accepted:
-            projectType = self.__pdata["PROJECTTYPE"]
+            fileTypesDict = copy.copy(self.__pdata["FILETYPES"])
             dlg.storeData()
             self.setDirty(True)
             if self.__pdata["MAINSCRIPT"]:
@@ -2936,10 +2954,6 @@
                         )
                 self.appendFile(mf)
 
-            if self.__pdata["PROJECTTYPE"] != projectType:
-                # reinitialize filetype associations
-                self.initFileTypes()
-
             if self.translationsRoot:
                 tp = os.path.join(self.ppath, self.translationsRoot)
                 if not self.translationsRoot.endswith(os.sep):
@@ -2963,7 +2977,7 @@
             self.__model.projectPropertiesChanged()
             self.projectPropertiesChanged.emit()
 
-            if self.__pdata["PROJECTTYPE"] != projectType:
+            if self.__pdata["FILETYPES"] != fileTypesDict:
                 self.__reorganizeFiles()
 
             if self.__pdata["EMBEDDED_VENV"] and not self.__findEmbeddedEnvironment():
@@ -3016,9 +3030,10 @@
         """
         from .FiletypeAssociationDialog import FiletypeAssociationDialog
 
-        dlg = FiletypeAssociationDialog(self)
+        dlg = FiletypeAssociationDialog(self, self.getProjectData(dataKey="FILETYPES"))
         if dlg.exec() == QDialog.DialogCode.Accepted:
-            dlg.transferData()
+            fileTypes = dlg.getData()
+            self.setProjectData(fileTypes, dataKey="FILETYPES")
             self.setDirty(True)
             self.__reorganizeFiles()
 

eric ide

mercurial