793 def initFileTypes(self): |
793 def initFileTypes(self): |
794 """ |
794 """ |
795 Public method to initialize the file type associations with default |
795 Public method to initialize the file type associations with default |
796 values. |
796 values. |
797 """ |
797 """ |
798 self.__pdata["FILETYPES"] = { |
798 self.__pdata["FILETYPES"] = self.defaultFileTypes( |
|
799 self.__pdata["PROGLANGUAGE"], |
|
800 self.__pdata["MIXEDLANGUAGE"], |
|
801 self.__pdata["PROJECTTYPE"], |
|
802 ) |
|
803 self.setDirty(True) |
|
804 |
|
805 def defaultFileTypes(self, progLanguage, isMixed, projectType): |
|
806 """ |
|
807 Public method to get a dictionary containing the default file type associations. |
|
808 |
|
809 @param progLanguage programming language (main language) |
|
810 @type str |
|
811 @param isMixed flag indicating a project with multiple programming languages |
|
812 @type bool |
|
813 @param projectType type of the project |
|
814 @type str |
|
815 @return dictionary containing the default file type associations |
|
816 @rtype dict |
|
817 """ |
|
818 fileTypesDict = { |
799 "*.txt": "OTHERS", |
819 "*.txt": "OTHERS", |
800 "*.md": "OTHERS", |
820 "*.md": "OTHERS", |
801 "*.rst": "OTHERS", |
821 "*.rst": "OTHERS", |
802 "README": "OTHERS", |
822 "README": "OTHERS", |
803 "README.*": "OTHERS", |
823 "README.*": "OTHERS", |
813 "*.yml": "OTHERS", |
833 "*.yml": "OTHERS", |
814 "*.yaml": "OTHERS", |
834 "*.yaml": "OTHERS", |
815 } |
835 } |
816 |
836 |
817 # Sources |
837 # Sources |
818 sourceKey = ( |
838 sourceKey = "Mixed" if isMixed else progLanguage |
819 "Mixed" if self.__pdata["MIXEDLANGUAGE"] else self.__pdata["PROGLANGUAGE"] |
|
820 ) |
|
821 for ext in self.__sourceExtensions(sourceKey): |
839 for ext in self.__sourceExtensions(sourceKey): |
822 self.__pdata["FILETYPES"]["*{0}".format(ext)] = "SOURCES" |
840 fileTypesDict["*{0}".format(ext)] = "SOURCES" |
823 |
841 |
824 # Forms |
842 # Forms |
825 if self.__pdata["PROJECTTYPE"] in [ |
843 if projectType in [ |
826 "E7Plugin", |
844 "E7Plugin", |
827 "PyQt5", |
845 "PyQt5", |
828 "PyQt6", |
846 "PyQt6", |
829 "PySide2", |
847 "PySide2", |
830 "PySide6", |
848 "PySide6", |
831 ]: |
849 ]: |
832 self.__pdata["FILETYPES"]["*.ui"] = "FORMS" |
850 fileTypesDict["*.ui"] = "FORMS" |
833 |
851 |
834 # Resources |
852 # Resources |
835 if self.__pdata["PROJECTTYPE"] in [ |
853 if projectType in [ |
836 "PyQt5", |
854 "PyQt5", |
837 "PyQt5C", |
855 "PyQt5C", |
838 "PySide2", |
856 "PySide2", |
839 "PySide2C", |
857 "PySide2C", |
840 "PySide6", |
858 "PySide6", |
841 "PySide6C", |
859 "PySide6C", |
842 ]: |
860 ]: |
843 self.__pdata["FILETYPES"]["*.qrc"] = "RESOURCES" |
861 fileTypesDict["*.qrc"] = "RESOURCES" |
844 |
862 |
845 # Translations |
863 # Translations |
846 if self.__pdata["PROJECTTYPE"] in [ |
864 if projectType in [ |
847 "E7Plugin", |
865 "E7Plugin", |
848 "PyQt5", |
866 "PyQt5", |
849 "PyQt5C", |
867 "PyQt5C", |
850 "PyQt6", |
868 "PyQt6", |
851 "PyQt6C", |
869 "PyQt6C", |
852 "PySide2", |
870 "PySide2", |
853 "PySide2C", |
871 "PySide2C", |
854 "PySide6", |
872 "PySide6", |
855 "PySide6C", |
873 "PySide6C", |
856 ]: |
874 ]: |
857 self.__pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS" |
875 fileTypesDict["*.ts"] = "TRANSLATIONS" |
858 self.__pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS" |
876 fileTypesDict["*.qm"] = "TRANSLATIONS" |
859 |
877 |
860 # File categories handled by activated plugin project browsers |
878 # File categories handled by activated plugin project browsers |
861 for fileCategory in [ |
879 for fileCategory in [ |
862 f for f in self.__fileCategoriesRepository.keys() if f not in [ |
880 f for f in self.__fileCategoriesRepository.keys() if f not in [ |
863 "SOURCES", "FORMS", "RESOURCES", "TRANSLATIONS", "OTHERS" |
881 "SOURCES", "FORMS", "RESOURCES", "TRANSLATIONS", "OTHERS" |
864 ] |
882 ] |
865 ]: |
883 ]: |
866 for ext in self.__fileCategoriesRepository[ |
884 for ext in self.__fileCategoriesRepository[ |
867 fileCategory |
885 fileCategory |
868 ].fileCategoryExtensions: |
886 ].fileCategoryExtensions: |
869 self.__pdata["FILETYPES"][ext] = fileCategory |
887 fileTypesDict[ext] = fileCategory |
870 # Project type specific ones |
888 # Project type specific ones |
871 with contextlib.suppress(KeyError): |
889 with contextlib.suppress(KeyError): |
872 if self.__fileTypeCallbacks[self.__pdata["PROJECTTYPE"]] is not None: |
890 if self.__fileTypeCallbacks[projectType] is not None: |
873 ftypes = self.__fileTypeCallbacks[self.__pdata["PROJECTTYPE"]]() |
891 ftypes = self.__fileTypeCallbacks[projectType]() |
874 self.__pdata["FILETYPES"].update(ftypes) |
892 fileTypesDict.update(ftypes) |
875 |
893 |
876 self.setDirty(True) |
894 return fileTypesDict |
877 |
895 |
878 def updateFileTypes(self): |
896 def updateFileTypes(self): |
879 """ |
897 """ |
880 Public method to update the filetype associations with new default |
898 Public method to update the filetype associations with new default |
881 values. |
899 values. |
2901 """ |
2919 """ |
2902 from .PropertiesDialog import PropertiesDialog |
2920 from .PropertiesDialog import PropertiesDialog |
2903 |
2921 |
2904 dlg = PropertiesDialog(self, new=False) |
2922 dlg = PropertiesDialog(self, new=False) |
2905 if dlg.exec() == QDialog.DialogCode.Accepted: |
2923 if dlg.exec() == QDialog.DialogCode.Accepted: |
2906 projectType = self.__pdata["PROJECTTYPE"] |
2924 fileTypesDict = copy.copy(self.__pdata["FILETYPES"]) |
2907 dlg.storeData() |
2925 dlg.storeData() |
2908 self.setDirty(True) |
2926 self.setDirty(True) |
2909 if self.__pdata["MAINSCRIPT"]: |
2927 if self.__pdata["MAINSCRIPT"]: |
2910 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
2928 if not os.path.isabs(self.__pdata["MAINSCRIPT"]): |
2911 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
2929 ms = os.path.join(self.ppath, self.__pdata["MAINSCRIPT"]) |
2934 " be created.<br/>Reason: {1}</p>" |
2952 " be created.<br/>Reason: {1}</p>" |
2935 ).format(mf, str(err)), |
2953 ).format(mf, str(err)), |
2936 ) |
2954 ) |
2937 self.appendFile(mf) |
2955 self.appendFile(mf) |
2938 |
2956 |
2939 if self.__pdata["PROJECTTYPE"] != projectType: |
|
2940 # reinitialize filetype associations |
|
2941 self.initFileTypes() |
|
2942 |
|
2943 if self.translationsRoot: |
2957 if self.translationsRoot: |
2944 tp = os.path.join(self.ppath, self.translationsRoot) |
2958 tp = os.path.join(self.ppath, self.translationsRoot) |
2945 if not self.translationsRoot.endswith(os.sep): |
2959 if not self.translationsRoot.endswith(os.sep): |
2946 tp = os.path.dirname(tp) |
2960 tp = os.path.dirname(tp) |
2947 else: |
2961 else: |
2961 self.pluginGrp.setEnabled(self.__pdata["PROJECTTYPE"] in ["E7Plugin"]) |
2975 self.pluginGrp.setEnabled(self.__pdata["PROJECTTYPE"] in ["E7Plugin"]) |
2962 |
2976 |
2963 self.__model.projectPropertiesChanged() |
2977 self.__model.projectPropertiesChanged() |
2964 self.projectPropertiesChanged.emit() |
2978 self.projectPropertiesChanged.emit() |
2965 |
2979 |
2966 if self.__pdata["PROJECTTYPE"] != projectType: |
2980 if self.__pdata["FILETYPES"] != fileTypesDict: |
2967 self.__reorganizeFiles() |
2981 self.__reorganizeFiles() |
2968 |
2982 |
2969 if self.__pdata["EMBEDDED_VENV"] and not self.__findEmbeddedEnvironment(): |
2983 if self.__pdata["EMBEDDED_VENV"] and not self.__findEmbeddedEnvironment(): |
2970 self.__createEmbeddedEnvironment() |
2984 self.__createEmbeddedEnvironment() |
2971 |
2985 |
3014 """ |
3028 """ |
3015 Private slot to display the filetype association dialog. |
3029 Private slot to display the filetype association dialog. |
3016 """ |
3030 """ |
3017 from .FiletypeAssociationDialog import FiletypeAssociationDialog |
3031 from .FiletypeAssociationDialog import FiletypeAssociationDialog |
3018 |
3032 |
3019 dlg = FiletypeAssociationDialog(self) |
3033 dlg = FiletypeAssociationDialog(self, self.getProjectData(dataKey="FILETYPES")) |
3020 if dlg.exec() == QDialog.DialogCode.Accepted: |
3034 if dlg.exec() == QDialog.DialogCode.Accepted: |
3021 dlg.transferData() |
3035 fileTypes = dlg.getData() |
|
3036 self.setProjectData(fileTypes, dataKey="FILETYPES") |
3022 self.setDirty(True) |
3037 self.setDirty(True) |
3023 self.__reorganizeFiles() |
3038 self.__reorganizeFiles() |
3024 |
3039 |
3025 def getFiletypeAssociations(self, associationType): |
3040 def getFiletypeAssociations(self, associationType): |
3026 """ |
3041 """ |