723 editor.setCursorPosition(line + lines - 1, count) |
723 editor.setCursorPosition(line + lines - 1, count) |
724 |
724 |
725 editor.endUndoAction() |
725 editor.endUndoAction() |
726 editor.setFocus() |
726 editor.setFocus() |
727 |
727 |
728 def applyNamedTemplate(self, templateName): |
728 def applyNamedTemplate(self, templateName, groupName=None): |
729 """ |
729 """ |
730 Public method to apply a template given a template name. |
730 Public method to apply a template given a template name. |
731 |
731 |
732 @param templateName name of the template item to apply (string) |
732 @param templateName name of the template item to apply (string) |
733 """ |
733 @param groupName name of the group to get the entry from (string). |
734 for group in list(self.groups.values()): |
734 None or empty means to apply the first template found with the |
|
735 given name. |
|
736 """ |
|
737 if groupName: |
|
738 if self.hasGroup(groupName): |
|
739 groups = [self.groups[groupName]] |
|
740 else: |
|
741 return |
|
742 else: |
|
743 groups = list(self.groups.values()) |
|
744 for group in groups: |
735 template = group.getEntry(templateName) |
745 template = group.getEntry(templateName) |
736 if template is not None: |
746 if template is not None: |
737 self.applyTemplate(template) |
747 self.applyTemplate(template) |
738 break |
748 break |
739 |
749 |
747 @param template template text of the entry (string) |
757 @param template template text of the entry (string) |
748 @param quiet flag indicating quiet operation (boolean) |
758 @param quiet flag indicating quiet operation (boolean) |
749 """ |
759 """ |
750 self.groups[groupName].addEntry(name, description, template, quiet=quiet) |
760 self.groups[groupName].addEntry(name, description, template, quiet=quiet) |
751 self.__resort() |
761 self.__resort() |
752 |
762 |
|
763 def hasGroup(self, name): |
|
764 """ |
|
765 Public method to check, if a group with the given name exists. |
|
766 |
|
767 @param name name of the group to be checked for (string) |
|
768 @return flag indicating an existing group (boolean) |
|
769 """ |
|
770 return name in self.groups |
|
771 |
753 def addGroup(self, name, language="All"): |
772 def addGroup(self, name, language="All"): |
754 """ |
773 """ |
755 Public method to add a group. |
774 Public method to add a group. |
756 |
775 |
757 @param name name of the group to be added (string) |
776 @param name name of the group to be added (string) |
897 """ |
916 """ |
898 Private method to open the configuration dialog. |
917 Private method to open the configuration dialog. |
899 """ |
918 """ |
900 e5App().getObject("UserInterface").showPreferences("templatesPage") |
919 e5App().getObject("UserInterface").showPreferences("templatesPage") |
901 |
920 |
902 def hasTemplate(self, entryName): |
921 def hasTemplate(self, entryName, groupName=None): |
903 """ |
922 """ |
904 Public method to check, if an entry of the given name exists. |
923 Public method to check, if an entry of the given name exists. |
905 |
924 |
906 @param entryName name of the entry to check for (string) |
925 @param entryName name of the entry to check for (string) |
|
926 @param groupName name of the group to check for the entry (string). |
|
927 None or empty means to check all groups. |
907 @return flag indicating the existence (boolean) |
928 @return flag indicating the existence (boolean) |
908 """ |
929 """ |
909 for group in list(self.groups.values()): |
930 if groupName: |
|
931 if self.hasGroup(groupName): |
|
932 groups = [self.groups[groupName]] |
|
933 else: |
|
934 groups = [] |
|
935 else: |
|
936 groups = list(self.groups.values()) |
|
937 for group in groups: |
910 if group.hasEntry(entryName): |
938 if group.hasEntry(entryName): |
911 return True |
939 return True |
912 |
940 |
913 return False |
941 return False |
914 |
942 |
915 def getTemplateNames(self, start): |
943 def getTemplateNames(self, start, groupName=None): |
916 """ |
944 """ |
917 Public method to get the names of templates starting with the given string. |
945 Public method to get the names of templates starting with the given string. |
918 |
946 |
919 @param start start string of the name (string) |
947 @param start start string of the name (string) |
|
948 @param groupName name of the group to get the entry from (string). |
|
949 None or empty means to look in all groups. |
920 @return sorted list of matching template names (list of strings) |
950 @return sorted list of matching template names (list of strings) |
921 """ |
951 """ |
922 names = [] |
952 names = [] |
923 for group in list(self.groups.values()): |
953 if groupName: |
|
954 if self.hasGroup(groupName): |
|
955 groups = [self.groups[groupName]] |
|
956 else: |
|
957 groups = [] |
|
958 else: |
|
959 groups = list(self.groups.values()) |
|
960 for group in groups: |
924 names.extend(group.getEntryNames(start)) |
961 names.extend(group.getEntryNames(start)) |
925 return sorted(names) |
962 return sorted(names) |