10 import datetime |
10 import datetime |
11 import os |
11 import os |
12 import pathlib |
12 import pathlib |
13 import re |
13 import re |
14 |
14 |
15 from PyQt6.QtCore import QCoreApplication, QFile, QIODevice, Qt, pyqtSlot |
15 from PyQt6.QtCore import QCoreApplication, Qt, pyqtSlot |
16 from PyQt6.QtWidgets import QApplication, QDialog, QMenu, QTreeWidget, QTreeWidgetItem |
16 from PyQt6.QtWidgets import QApplication, QDialog, QMenu, QTreeWidget, QTreeWidgetItem |
17 |
17 |
18 from eric7 import Globals, Preferences |
18 from eric7 import Globals, Preferences |
19 from eric7.EricGui import EricPixmapCache |
19 from eric7.EricGui import EricPixmapCache |
20 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
20 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
21 from eric7.EricWidgets.EricApplication import ericApp |
21 from eric7.EricWidgets.EricApplication import ericApp |
22 from eric7.EricXML.TemplatesReader import TemplatesReader |
|
23 |
22 |
24 from .TemplatePropertiesDialog import TemplatePropertiesDialog |
23 from .TemplatePropertiesDialog import TemplatePropertiesDialog |
25 from .TemplatesFile import TemplatesFile |
24 from .TemplatesFile import TemplatesFile |
26 |
25 |
27 |
26 |
602 """ |
601 """ |
603 fn = EricFileDialog.getOpenFileName( |
602 fn = EricFileDialog.getOpenFileName( |
604 self, |
603 self, |
605 self.tr("Import Templates"), |
604 self.tr("Import Templates"), |
606 "", |
605 "", |
607 self.tr( |
606 self.tr("Templates Files (*.ecj);;All Files (*)"), |
608 "Templates Files (*.ecj);;" |
|
609 "XML Templates Files (*.e4c);;" |
|
610 "All Files (*)" |
|
611 ), |
|
612 ) |
607 ) |
613 |
608 |
614 if fn: |
609 if fn: |
615 self.readTemplates(fn) |
610 self.readTemplates(fn) |
616 self.__dirty = True |
611 self.__dirty = True |
1043 |
1038 |
1044 return self.__templatesFile.writeFile(filename) |
1039 return self.__templatesFile.writeFile(filename) |
1045 |
1040 |
1046 def readTemplates(self, filename=None): |
1041 def readTemplates(self, filename=None): |
1047 """ |
1042 """ |
1048 Public method to read in the templates file (.e4c). |
1043 Public method to read in the templates file (.ecj). |
1049 |
1044 |
1050 @param filename name of a templates file to read |
1045 @param filename name of a templates file to read |
1051 @type str |
1046 @type str |
1052 """ |
1047 """ |
1053 if filename is None: |
1048 if filename is None: |
1054 # new JSON based file first |
|
1055 filename = os.path.join(Globals.getConfigDir(), "eric7templates.ecj") |
1049 filename = os.path.join(Globals.getConfigDir(), "eric7templates.ecj") |
1056 if not os.path.exists(filename): |
1050 if not os.path.exists(filename): |
1057 # old XML based file second |
1051 return |
1058 filename = os.path.join(Globals.getConfigDir(), "eric7templates.e4c") |
1052 |
1059 if not os.path.exists(filename): |
1053 self.__templatesFile.readFile(filename) |
1060 return |
|
1061 |
|
1062 if filename.endswith(".ecj"): |
|
1063 self.__templatesFile.readFile(filename) |
|
1064 else: |
|
1065 f = QFile(filename) |
|
1066 if f.open(QIODevice.OpenModeFlag.ReadOnly): |
|
1067 reader = TemplatesReader(f, viewer=self) |
|
1068 reader.readXML() |
|
1069 f.close() |
|
1070 else: |
|
1071 EricMessageBox.critical( |
|
1072 self, |
|
1073 self.tr("Read Templates"), |
|
1074 self.tr( |
|
1075 "<p>The templates file <b>{0}</b> could not be read.</p>" |
|
1076 ).format(filename), |
|
1077 ) |
|
1078 |
1054 |
1079 def __configure(self): |
1055 def __configure(self): |
1080 """ |
1056 """ |
1081 Private method to open the configuration dialog. |
1057 Private method to open the configuration dialog. |
1082 """ |
1058 """ |