Templates/TemplateViewer.py

changeset 3039
8dd0165d805d
parent 3034
7ce719013078
child 3060
5883ce99ee12
child 3160
209a07d7e401
equal deleted inserted replaced
3038:7fe9a53280bd 3039:8dd0165d805d
96 QApplication.translate("TemplateGroup", "Add Template"), 96 QApplication.translate("TemplateGroup", "Add Template"),
97 QApplication.translate( 97 QApplication.translate(
98 "TemplateGroup", 98 "TemplateGroup",
99 """<p>The group <b>{0}</b> already contains a""" 99 """<p>The group <b>{0}</b> already contains a"""
100 """ template named <b>{1}</b>.</p>""") 100 """ template named <b>{1}</b>.</p>""")
101 .format(self.name, name)) 101 .format(self.name, name))
102 return 102 return
103 103
104 self.entries[name] = TemplateEntry(self, name, description, template) 104 self.entries[name] = TemplateEntry(self, name, description, template)
105 105
106 if Preferences.getTemplates("AutoOpenGroups") and \ 106 if Preferences.getTemplates("AutoOpenGroups") and \
523 itm = self.currentItem() 523 itm = self.currentItem()
524 res = E5MessageBox.yesNo( 524 res = E5MessageBox.yesNo(
525 self, 525 self,
526 self.trUtf8("Remove Template"), 526 self.trUtf8("Remove Template"),
527 self.trUtf8("""<p>Do you really want to remove <b>{0}</b>?</p>""") 527 self.trUtf8("""<p>Do you really want to remove <b>{0}</b>?</p>""")
528 .format(itm.getName())) 528 .format(itm.getName()))
529 if not res: 529 if not res:
530 return 530 return
531 531
532 if isinstance(itm, TemplateGroup): 532 if isinstance(itm, TemplateGroup):
533 self.removeGroup(itm) 533 self.removeGroup(itm)
641 dir_name, file_name = os.path.split(path_name) 641 dir_name, file_name = os.path.split(path_name)
642 base_name, ext = os.path.splitext(file_name) 642 base_name, ext = os.path.splitext(file_name)
643 if ext: 643 if ext:
644 ext = ext[1:] 644 ext = ext[1:]
645 varValues.update({ 645 varValues.update({
646 keyfmt.format('path_name'): path_name, 646 keyfmt.format('path_name'): path_name,
647 keyfmt.format('dir_name'): dir_name, 647 keyfmt.format('dir_name'): dir_name,
648 keyfmt.format('file_name'): file_name, 648 keyfmt.format('file_name'): file_name,
649 keyfmt.format('base_name'): base_name, 649 keyfmt.format('base_name'): base_name,
650 keyfmt.format('ext'): ext 650 keyfmt.format('ext'): ext
651 }) 651 })
652 652
653 varValues[keyfmt.format('clipboard:ml')] = \ 653 varValues[keyfmt.format('clipboard:ml')] = \
654 QApplication.clipboard().text() 654 QApplication.clipboard().text()
655 varValues[keyfmt.format('clipboard')] = \ 655 varValues[keyfmt.format('clipboard')] = \
711 else: 711 else:
712 ok = True 712 ok = True
713 713
714 if ok: 714 if ok:
715 line = editor.text(editor.getCursorPosition()[0])\ 715 line = editor.text(editor.getCursorPosition()[0])\
716 .replace(os.linesep, "") 716 .replace(os.linesep, "")
717 indent = line.replace(line.lstrip(), "") 717 indent = line.replace(line.lstrip(), "")
718 txt, lines, count = itm.getExpandedText(varValues, indent) 718 txt, lines, count = itm.getExpandedText(varValues, indent)
719 # It should be done in this way to allow undo 719 # It should be done in this way to allow undo
720 editor.beginUndoAction() 720 editor.beginUndoAction()
721 if editor.hasSelectedText(): 721 if editor.hasSelectedText():
849 E5MessageBox.warning( 849 E5MessageBox.warning(
850 self, 850 self,
851 self.trUtf8("Edit Template Group"), 851 self.trUtf8("Edit Template Group"),
852 self.trUtf8("""<p>A template group with the name""" 852 self.trUtf8("""<p>A template group with the name"""
853 """ <b>{0}</b> already exists.</p>""") 853 """ <b>{0}</b> already exists.</p>""")
854 .format(newname)) 854 .format(newname))
855 return 855 return
856 856
857 self.groups[newname] = self.groups[oldname] 857 self.groups[newname] = self.groups[oldname]
858 del self.groups[oldname] 858 del self.groups[oldname]
859 self.groups[newname].setName(newname) 859 self.groups[newname].setName(newname)
944 self, 944 self,
945 self.trUtf8("Save templates"), 945 self.trUtf8("Save templates"),
946 self.trUtf8( 946 self.trUtf8(
947 "<p>The templates file <b>{0}</b> could not be" 947 "<p>The templates file <b>{0}</b> could not be"
948 " written.</p>") 948 " written.</p>")
949 .format(filename)) 949 .format(filename))
950 return False 950 return False
951 951
952 from E5XML.TemplatesWriter import TemplatesWriter 952 from E5XML.TemplatesWriter import TemplatesWriter
953 TemplatesWriter(f, self).writeXML() 953 TemplatesWriter(f, self).writeXML()
954 f.close() 954 f.close()
977 E5MessageBox.critical( 977 E5MessageBox.critical(
978 self, 978 self,
979 self.trUtf8("Read templates"), 979 self.trUtf8("Read templates"),
980 self.trUtf8( 980 self.trUtf8(
981 "<p>The templates file <b>{0}</b> could not be read.</p>") 981 "<p>The templates file <b>{0}</b> could not be read.</p>")
982 .format(filename)) 982 .format(filename))
983 983
984 def __configure(self): 984 def __configure(self):
985 """ 985 """
986 Private method to open the configuration dialog. 986 Private method to open the configuration dialog.
987 """ 987 """

eric ide

mercurial