17 |
17 |
18 from eric7 import Preferences, Utilities |
18 from eric7 import Preferences, Utilities |
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 |
22 from eric7.EricXML.TemplatesReader import TemplatesReader |
|
23 |
|
24 from .TemplatePropertiesDialog import TemplatePropertiesDialog |
23 from .TemplatesFile import TemplatesFile |
25 from .TemplatesFile import TemplatesFile |
24 |
26 |
25 |
27 |
26 class TemplateGroup(QTreeWidgetItem): |
28 class TemplateGroup(QTreeWidgetItem): |
27 """ |
29 """ |
483 itm = self.currentItem() |
485 itm = self.currentItem() |
484 groupName = ( |
486 groupName = ( |
485 itm.getName() if isinstance(itm, TemplateGroup) else itm.getGroupName() |
487 itm.getName() if isinstance(itm, TemplateGroup) else itm.getGroupName() |
486 ) |
488 ) |
487 |
489 |
488 from .TemplatePropertiesDialog import TemplatePropertiesDialog |
|
489 |
|
490 dlg = TemplatePropertiesDialog(self) |
490 dlg = TemplatePropertiesDialog(self) |
491 dlg.setSelectedGroup(groupName) |
491 dlg.setSelectedGroup(groupName) |
492 if dlg.exec() == QDialog.DialogCode.Accepted: |
492 if dlg.exec() == QDialog.DialogCode.Accepted: |
493 name, description, groupName, template = dlg.getData() |
493 name, description, groupName, template = dlg.getData() |
494 self.addEntry(groupName, name, description, template) |
494 self.addEntry(groupName, name, description, template) |
496 |
496 |
497 def __addGroup(self): |
497 def __addGroup(self): |
498 """ |
498 """ |
499 Private slot to handle the Add Group context menu action. |
499 Private slot to handle the Add Group context menu action. |
500 """ |
500 """ |
501 from .TemplatePropertiesDialog import TemplatePropertiesDialog |
|
502 |
|
503 dlg = TemplatePropertiesDialog(self, True) |
501 dlg = TemplatePropertiesDialog(self, True) |
504 if dlg.exec() == QDialog.DialogCode.Accepted: |
502 if dlg.exec() == QDialog.DialogCode.Accepted: |
505 name, language = dlg.getData() |
503 name, language = dlg.getData() |
506 self.addGroup(name, language) |
504 self.addGroup(name, language) |
507 self.__dirty = True |
505 self.__dirty = True |
510 """ |
508 """ |
511 Private slot to handle the Edit context menu action. |
509 Private slot to handle the Edit context menu action. |
512 """ |
510 """ |
513 itm = self.currentItem() |
511 itm = self.currentItem() |
514 editGroup = not isinstance(itm, TemplateEntry) |
512 editGroup = not isinstance(itm, TemplateEntry) |
515 |
|
516 from .TemplatePropertiesDialog import TemplatePropertiesDialog |
|
517 |
513 |
518 dlg = TemplatePropertiesDialog(self, editGroup, itm) |
514 dlg = TemplatePropertiesDialog(self, editGroup, itm) |
519 if dlg.exec() == QDialog.DialogCode.Accepted: |
515 if dlg.exec() == QDialog.DialogCode.Accepted: |
520 if editGroup: |
516 if editGroup: |
521 name, language = dlg.getData() |
517 name, language = dlg.getData() |
730 if v in variables: |
729 if v in variables: |
731 variables.remove(v) |
730 variables.remove(v) |
732 |
731 |
733 if variables: |
732 if variables: |
734 if Preferences.getTemplates("SingleDialog"): |
733 if Preferences.getTemplates("SingleDialog"): |
735 from .TemplateMultipleVariablesDialog import ( |
|
736 TemplateMultipleVariablesDialog, |
|
737 ) |
|
738 |
734 |
739 dlg = TemplateMultipleVariablesDialog(variables, self) |
735 dlg = TemplateMultipleVariablesDialog(variables, self) |
740 if dlg.exec() == QDialog.DialogCode.Accepted: |
736 if dlg.exec() == QDialog.DialogCode.Accepted: |
741 varValues.update(dlg.getVariables()) |
737 varValues.update(dlg.getVariables()) |
742 ok = True |
738 ok = True |
743 else: |
739 else: |
744 from .TemplateSingleVariableDialog import TemplateSingleVariableDialog |
|
745 |
|
746 for var in variables: |
740 for var in variables: |
747 dlg = TemplateSingleVariableDialog(var, self) |
741 dlg = TemplateSingleVariableDialog(var, self) |
748 if dlg.exec() == QDialog.DialogCode.Accepted: |
742 if dlg.exec() == QDialog.DialogCode.Accepted: |
749 varValues[var] = dlg.getVariable() |
743 varValues[var] = dlg.getVariable() |
750 else: |
744 else: |
1001 if filename.endswith(".ecj"): |
995 if filename.endswith(".ecj"): |
1002 self.__templatesFile.readFile(filename) |
996 self.__templatesFile.readFile(filename) |
1003 else: |
997 else: |
1004 f = QFile(filename) |
998 f = QFile(filename) |
1005 if f.open(QIODevice.OpenModeFlag.ReadOnly): |
999 if f.open(QIODevice.OpenModeFlag.ReadOnly): |
1006 from eric7.EricXML.TemplatesReader import TemplatesReader |
|
1007 |
|
1008 reader = TemplatesReader(f, viewer=self) |
1000 reader = TemplatesReader(f, viewer=self) |
1009 reader.readXML() |
1001 reader.readXML() |
1010 f.close() |
1002 f.close() |
1011 else: |
1003 else: |
1012 EricMessageBox.critical( |
1004 EricMessageBox.critical( |