14 from PyQt6.QtCore import QFile, QFileInfo, QIODevice, Qt, QCoreApplication |
14 from PyQt6.QtCore import QFile, QFileInfo, QIODevice, Qt, QCoreApplication |
15 from PyQt6.QtWidgets import ( |
15 from PyQt6.QtWidgets import ( |
16 QTreeWidget, QDialog, QApplication, QMenu, QTreeWidgetItem |
16 QTreeWidget, QDialog, QApplication, QMenu, QTreeWidgetItem |
17 ) |
17 ) |
18 |
18 |
19 from E5Gui.E5Application import e5App |
19 from E5Gui.EricApplication import ericApp |
20 from E5Gui import E5MessageBox, E5FileDialog |
20 from E5Gui import EricMessageBox, EricFileDialog |
21 |
21 |
22 import Preferences |
22 import Preferences |
23 |
23 |
24 import UI.PixmapCache |
24 import UI.PixmapCache |
25 import Utilities |
25 import Utilities |
92 @param template template text of the entry (string) |
92 @param template template text of the entry (string) |
93 @param quiet flag indicating quiet operation (boolean) |
93 @param quiet flag indicating quiet operation (boolean) |
94 """ |
94 """ |
95 if name in self.entries: |
95 if name in self.entries: |
96 if not quiet: |
96 if not quiet: |
97 E5MessageBox.critical( |
97 EricMessageBox.critical( |
98 None, |
98 None, |
99 QCoreApplication.translate("TemplateGroup", |
99 QCoreApplication.translate("TemplateGroup", |
100 "Add Template"), |
100 "Add Template"), |
101 QCoreApplication.translate( |
101 QCoreApplication.translate( |
102 "TemplateGroup", |
102 "TemplateGroup", |
533 def __remove(self): |
533 def __remove(self): |
534 """ |
534 """ |
535 Private slot to handle the Remove context menu action. |
535 Private slot to handle the Remove context menu action. |
536 """ |
536 """ |
537 itm = self.currentItem() |
537 itm = self.currentItem() |
538 res = E5MessageBox.yesNo( |
538 res = EricMessageBox.yesNo( |
539 self, |
539 self, |
540 self.tr("Remove Template"), |
540 self.tr("Remove Template"), |
541 self.tr("""<p>Do you really want to remove <b>{0}</b>?</p>""") |
541 self.tr("""<p>Do you really want to remove <b>{0}</b>?</p>""") |
542 .format(itm.getName())) |
542 .format(itm.getName())) |
543 if not res: |
543 if not res: |
560 |
560 |
561 def __import(self): |
561 def __import(self): |
562 """ |
562 """ |
563 Private slot to handle the Import context menu action. |
563 Private slot to handle the Import context menu action. |
564 """ |
564 """ |
565 fn = E5FileDialog.getOpenFileName( |
565 fn = EricFileDialog.getOpenFileName( |
566 self, |
566 self, |
567 self.tr("Import Templates"), |
567 self.tr("Import Templates"), |
568 "", |
568 "", |
569 self.tr("Templates Files (*.ecj);;" |
569 self.tr("Templates Files (*.ecj);;" |
570 "XML Templates Files (*.e4c);;" |
570 "XML Templates Files (*.e4c);;" |
576 |
576 |
577 def __export(self): |
577 def __export(self): |
578 """ |
578 """ |
579 Private slot to handle the Export context menu action. |
579 Private slot to handle the Export context menu action. |
580 """ |
580 """ |
581 fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
581 fn, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
582 self, |
582 self, |
583 self.tr("Export Templates"), |
583 self.tr("Export Templates"), |
584 "", |
584 "", |
585 self.tr("Templates Files (*.ecj)" |
585 self.tr("Templates Files (*.ecj)" |
586 "All Files (*)"), |
586 "All Files (*)"), |
587 "", |
587 "", |
588 E5FileDialog.DontConfirmOverwrite) |
588 EricFileDialog.DontConfirmOverwrite) |
589 |
589 |
590 if fn: |
590 if fn: |
591 ext = QFileInfo(fn).suffix() |
591 ext = QFileInfo(fn).suffix() |
592 if not ext: |
592 if not ext: |
593 ex = selectedFilter.split("(*")[1].split(")")[0] |
593 ex = selectedFilter.split("(*")[1].split(")")[0] |
594 if ex: |
594 if ex: |
595 fn += ex |
595 fn += ex |
596 if os.path.exists(fn): |
596 if os.path.exists(fn): |
597 ok = E5MessageBox.yesNo( |
597 ok = EricMessageBox.yesNo( |
598 self, |
598 self, |
599 self.tr("Export Templates"), |
599 self.tr("Export Templates"), |
600 self.tr("""<p>The templates file <b>{0}</b> exists""" |
600 self.tr("""<p>The templates file <b>{0}</b> exists""" |
601 """ already. Overwrite it?</p>""").format(fn)) |
601 """ already. Overwrite it?</p>""").format(fn)) |
602 else: |
602 else: |
608 def __reload(self): |
608 def __reload(self): |
609 """ |
609 """ |
610 Private slot to reload the templates. |
610 Private slot to reload the templates. |
611 """ |
611 """ |
612 if self.__dirty: |
612 if self.__dirty: |
613 res = E5MessageBox.yesNo( |
613 res = EricMessageBox.yesNo( |
614 self, |
614 self, |
615 self.tr("Reload Templates"), |
615 self.tr("Reload Templates"), |
616 self.tr( |
616 self.tr( |
617 """The templates contain unsaved changes. Shall these""" |
617 """The templates contain unsaved changes. Shall these""" |
618 """ changes be discarded?"""), |
618 """ changes be discarded?"""), |
619 icon=E5MessageBox.Warning) |
619 icon=EricMessageBox.Warning) |
620 if not res: |
620 if not res: |
621 return |
621 return |
622 |
622 |
623 self.clear() |
623 self.clear() |
624 self.groups = {} |
624 self.groups = {} |
627 |
627 |
628 def __showHelp(self): |
628 def __showHelp(self): |
629 """ |
629 """ |
630 Private method to show some help. |
630 Private method to show some help. |
631 """ |
631 """ |
632 E5MessageBox.information( |
632 EricMessageBox.information( |
633 self, |
633 self, |
634 self.tr("Template Help"), |
634 self.tr("Template Help"), |
635 self.tr( |
635 self.tr( |
636 """<p><b>Template groups</b> are a means of grouping""" |
636 """<p><b>Template groups</b> are a means of grouping""" |
637 """ individual templates. Groups have an attribute that""" |
637 """ individual templates. Groups have an attribute that""" |
647 """ |
647 """ |
648 Private method to return predefined variables. |
648 Private method to return predefined variables. |
649 |
649 |
650 @return dictionary of predefined variables and their values |
650 @return dictionary of predefined variables and their values |
651 """ |
651 """ |
652 project = e5App().getObject("Project") |
652 project = ericApp().getObject("Project") |
653 editor = self.viewmanager.activeWindow() |
653 editor = self.viewmanager.activeWindow() |
654 now = datetime.datetime.now() |
654 now = datetime.datetime.now() |
655 sepchar = Preferences.getTemplates("SeparatorChar") |
655 sepchar = Preferences.getTemplates("SeparatorChar") |
656 keyfmt = sepchar + "{0}" + sepchar |
656 keyfmt = sepchar + "{0}" + sepchar |
657 varValues = { |
657 varValues = { |
882 @param newname new name of the group (string) |
882 @param newname new name of the group (string) |
883 @param language programming language for the group (string) |
883 @param language programming language for the group (string) |
884 """ |
884 """ |
885 if oldname != newname: |
885 if oldname != newname: |
886 if newname in self.groups: |
886 if newname in self.groups: |
887 E5MessageBox.warning( |
887 EricMessageBox.warning( |
888 self, |
888 self, |
889 self.tr("Edit Template Group"), |
889 self.tr("Edit Template Group"), |
890 self.tr("""<p>A template group with the name""" |
890 self.tr("""<p>A template group with the name""" |
891 """ <b>{0}</b> already exists.</p>""") |
891 """ <b>{0}</b> already exists.</p>""") |
892 .format(newname)) |
892 .format(newname)) |
1006 from EricXML.TemplatesReader import TemplatesReader |
1006 from EricXML.TemplatesReader import TemplatesReader |
1007 reader = TemplatesReader(f, viewer=self) |
1007 reader = TemplatesReader(f, viewer=self) |
1008 reader.readXML() |
1008 reader.readXML() |
1009 f.close() |
1009 f.close() |
1010 else: |
1010 else: |
1011 E5MessageBox.critical( |
1011 EricMessageBox.critical( |
1012 self, |
1012 self, |
1013 self.tr("Read Templates"), |
1013 self.tr("Read Templates"), |
1014 self.tr( |
1014 self.tr( |
1015 "<p>The templates file <b>{0}</b> could not be read." |
1015 "<p>The templates file <b>{0}</b> could not be read." |
1016 "</p>") |
1016 "</p>") |
1018 |
1018 |
1019 def __configure(self): |
1019 def __configure(self): |
1020 """ |
1020 """ |
1021 Private method to open the configuration dialog. |
1021 Private method to open the configuration dialog. |
1022 """ |
1022 """ |
1023 e5App().getObject("UserInterface").showPreferences("templatesPage") |
1023 ericApp().getObject("UserInterface").showPreferences("templatesPage") |
1024 |
1024 |
1025 def hasTemplate(self, entryName, groupName=None): |
1025 def hasTemplate(self, entryName, groupName=None): |
1026 """ |
1026 """ |
1027 Public method to check, if an entry of the given name exists. |
1027 Public method to check, if an entry of the given name exists. |
1028 |
1028 |