Templates/TemplateViewer.py

branch
Py2 comp.
changeset 3058
0a02c433f52d
parent 3057
10516539f238
parent 3020
542e97d4ecb3
child 3060
5883ce99ee12
equal deleted inserted replaced
3057:10516539f238 3058:0a02c433f52d
91 @param template template text of the entry (string) 91 @param template template text of the entry (string)
92 @param quiet flag indicating quiet operation (boolean) 92 @param quiet flag indicating quiet operation (boolean)
93 """ 93 """
94 if name in self.entries: 94 if name in self.entries:
95 if not quiet: 95 if not quiet:
96 E5MessageBox.critical(None, 96 E5MessageBox.critical(
97 None,
97 QApplication.translate("TemplateGroup", "Add Template"), 98 QApplication.translate("TemplateGroup", "Add Template"),
98 QApplication.translate( 99 QApplication.translate(
99 "TemplateGroup", 100 "TemplateGroup",
100 """<p>The group <b>{0}</b> already contains a""" 101 """<p>The group <b>{0}</b> already contains a"""
101 """ template named <b>{1}</b>.</p>""") 102 """ template named <b>{1}</b>.</p>""")
520 def __remove(self): 521 def __remove(self):
521 """ 522 """
522 Private slot to handle the Remove context menu action. 523 Private slot to handle the Remove context menu action.
523 """ 524 """
524 itm = self.currentItem() 525 itm = self.currentItem()
525 res = E5MessageBox.yesNo(self, 526 res = E5MessageBox.yesNo(
527 self,
526 self.trUtf8("Remove Template"), 528 self.trUtf8("Remove Template"),
527 self.trUtf8("""<p>Do you really want to remove <b>{0}</b>?</p>""")\ 529 self.trUtf8("""<p>Do you really want to remove <b>{0}</b>?</p>""")\
528 .format(itm.getName())) 530 .format(itm.getName()))
529 if not res: 531 if not res:
530 return 532 return
581 def __reload(self): 583 def __reload(self):
582 """ 584 """
583 Private slot to reload the templates. 585 Private slot to reload the templates.
584 """ 586 """
585 if self.__dirty: 587 if self.__dirty:
586 res = E5MessageBox.yesNo(self, 588 res = E5MessageBox.yesNo(
589 self,
587 self.trUtf8("Reload Templates"), 590 self.trUtf8("Reload Templates"),
588 self.trUtf8( 591 self.trUtf8(
589 """The templates contain unsaved changes. Shall these""" 592 """The templates contain unsaved changes. Shall these"""
590 """ changes be discarded?"""), 593 """ changes be discarded?"""),
591 icon=E5MessageBox.Warning) 594 icon=E5MessageBox.Warning)
599 602
600 def __showHelp(self): 603 def __showHelp(self):
601 """ 604 """
602 Private method to show some help. 605 Private method to show some help.
603 """ 606 """
604 E5MessageBox.information(self, 607 E5MessageBox.information(
608 self,
605 self.trUtf8("Template Help"), 609 self.trUtf8("Template Help"),
606 self.trUtf8( 610 self.trUtf8(
607 """<p><b>Template groups</b> are a means of grouping""" 611 """<p><b>Template groups</b> are a means of grouping"""
608 """ individual templates. Groups have an attribute that""" 612 """ individual templates. Groups have an attribute that"""
609 """ specifies, which programming language they apply for.""" 613 """ specifies, which programming language they apply for."""
842 @param newname new name of the group (string) 846 @param newname new name of the group (string)
843 @param language programming language for the group (string) 847 @param language programming language for the group (string)
844 """ 848 """
845 if oldname != newname: 849 if oldname != newname:
846 if newname in self.groups: 850 if newname in self.groups:
847 E5MessageBox.warning(self, 851 E5MessageBox.warning(
852 self,
848 self.trUtf8("Edit Template Group"), 853 self.trUtf8("Edit Template Group"),
849 self.trUtf8("""<p>A template group with the name""" 854 self.trUtf8("""<p>A template group with the name"""
850 """ <b>{0}</b> already exists.</p>""")\ 855 """ <b>{0}</b> already exists.</p>""")\
851 .format(newname)) 856 .format(newname))
852 return 857 return
935 filename = os.path.join( 940 filename = os.path.join(
936 Utilities.getConfigDir(), "eric5templates.e4c") 941 Utilities.getConfigDir(), "eric5templates.e4c")
937 f = QFile(filename) 942 f = QFile(filename)
938 ok = f.open(QIODevice.WriteOnly) 943 ok = f.open(QIODevice.WriteOnly)
939 if not ok: 944 if not ok:
940 E5MessageBox.critical(self, 945 E5MessageBox.critical(
946 self,
941 self.trUtf8("Save templates"), 947 self.trUtf8("Save templates"),
942 self.trUtf8( 948 self.trUtf8(
943 "<p>The templates file <b>{0}</b> could not be" 949 "<p>The templates file <b>{0}</b> could not be"
944 " written.</p>") 950 " written.</p>")
945 .format(filename)) 951 .format(filename))
968 from E5XML.TemplatesReader import TemplatesReader 974 from E5XML.TemplatesReader import TemplatesReader
969 reader = TemplatesReader(f, viewer=self) 975 reader = TemplatesReader(f, viewer=self)
970 reader.readXML() 976 reader.readXML()
971 f.close() 977 f.close()
972 else: 978 else:
973 E5MessageBox.critical(self, 979 E5MessageBox.critical(
980 self,
974 self.trUtf8("Read templates"), 981 self.trUtf8("Read templates"),
975 self.trUtf8( 982 self.trUtf8(
976 "<p>The templates file <b>{0}</b> could not be read.</p>") 983 "<p>The templates file <b>{0}</b> could not be read.</p>")
977 .format(filename)) 984 .format(filename))
978 985

eric ide

mercurial