947 tmpl = self.groups[groupName].getEntry(name) |
955 tmpl = self.groups[groupName].getEntry(name) |
948 tmpl.setDescription(description) |
956 tmpl.setDescription(description) |
949 tmpl.setTemplateText(template) |
957 tmpl.setTemplateText(template) |
950 self.__resort() |
958 self.__resort() |
951 |
959 |
952 # TODO: do the JSON templates |
|
953 def writeTemplates(self, filename=None): |
960 def writeTemplates(self, filename=None): |
954 """ |
961 """ |
955 Public method to write the templates data to an XML file (.e4c). |
962 Public method to write the templates data to a JSON file (.ecj). |
956 |
963 |
957 @param filename name of a templates file to read (string) |
964 @param filename name of a templates file to write |
958 @return flag indicating success (boolean) |
965 @type str |
|
966 @return flag indicating success |
|
967 @rtype bool |
959 """ |
968 """ |
960 if filename is None: |
969 if filename is None: |
961 filename = os.path.join( |
970 filename = os.path.join( |
962 Utilities.getConfigDir(), "eric6templates.e4c") |
971 Utilities.getConfigDir(), "eric6templates.ecj") |
963 f = QFile(filename) |
972 if filename.endswith(".ecj"): |
964 ok = f.open(QIODevice.WriteOnly) |
973 # new JSON based file |
965 if not ok: |
974 res = self.__templatesFile.writeFile(filename) |
966 E5MessageBox.critical( |
975 else: |
967 self, |
976 # old XML based file |
968 self.tr("Save templates"), |
977 f = QFile(filename) |
969 self.tr( |
978 ok = f.open(QIODevice.WriteOnly) |
970 "<p>The templates file <b>{0}</b> could not be" |
979 if not ok: |
971 " written.</p>") |
980 E5MessageBox.critical( |
972 .format(filename)) |
981 self, |
973 return False |
982 self.tr("Save Templates"), |
974 |
983 self.tr( |
975 from E5XML.TemplatesWriter import TemplatesWriter |
984 "<p>The templates file <b>{0}</b> could not be" |
976 TemplatesWriter(f, self).writeXML() |
985 " written.</p>") |
977 f.close() |
986 .format(filename)) |
978 |
987 res = False |
979 return True |
988 else: |
980 |
989 from E5XML.TemplatesWriter import TemplatesWriter |
981 # TODO: do the JSON templates |
990 TemplatesWriter(f, self).writeXML() |
|
991 f.close() |
|
992 res = True |
|
993 |
|
994 return res |
|
995 |
982 def readTemplates(self, filename=None): |
996 def readTemplates(self, filename=None): |
983 """ |
997 """ |
984 Public method to read in the templates file (.e4c). |
998 Public method to read in the templates file (.e4c). |
985 |
999 |
986 @param filename name of a templates file to read (string) |
1000 @param filename name of a templates file to read |
|
1001 @type str |
987 """ |
1002 """ |
988 if filename is None: |
1003 if filename is None: |
|
1004 # new JSON based file first |
989 filename = os.path.join( |
1005 filename = os.path.join( |
990 Utilities.getConfigDir(), "eric6templates.e4c") |
1006 Utilities.getConfigDir(), "eric6templates.ecj") |
991 if not os.path.exists(filename): |
1007 if not os.path.exists(filename): |
992 return |
1008 # old XML based file second |
993 |
1009 filename = os.path.join( |
994 f = QFile(filename) |
1010 Utilities.getConfigDir(), "eric6templates.e4c") |
995 if f.open(QIODevice.ReadOnly): |
1011 if not os.path.exists(filename): |
996 from E5XML.TemplatesReader import TemplatesReader |
1012 return |
997 reader = TemplatesReader(f, viewer=self) |
1013 |
998 reader.readXML() |
1014 if filename.endswith(".ecj"): |
999 f.close() |
1015 self.__templatesFile.readFile(filename) |
1000 else: |
1016 else: |
1001 E5MessageBox.critical( |
1017 f = QFile(filename) |
1002 self, |
1018 if f.open(QIODevice.ReadOnly): |
1003 self.tr("Read templates"), |
1019 from E5XML.TemplatesReader import TemplatesReader |
1004 self.tr( |
1020 reader = TemplatesReader(f, viewer=self) |
1005 "<p>The templates file <b>{0}</b> could not be read.</p>") |
1021 reader.readXML() |
1006 .format(filename)) |
1022 f.close() |
|
1023 else: |
|
1024 E5MessageBox.critical( |
|
1025 self, |
|
1026 self.tr("Read Templates"), |
|
1027 self.tr( |
|
1028 "<p>The templates file <b>{0}</b> could not be read." |
|
1029 "</p>") |
|
1030 .format(filename)) |
1007 |
1031 |
1008 def __configure(self): |
1032 def __configure(self): |
1009 """ |
1033 """ |
1010 Private method to open the configuration dialog. |
1034 Private method to open the configuration dialog. |
1011 """ |
1035 """ |