diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index ae9d5c1cf..8230da36a 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -56,73 +56,115 @@ class FormattingTags(object): base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Red'), u'start tag': u'{r}', u'start html': u'', - u'end tag': u'{/r}', u'end html': u'', u'protected': True}) + u'end tag': u'{/r}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Black'), u'start tag': u'{b}', u'start html': u'', - u'end tag': u'{/b}', u'end html': u'', u'protected': True}) + u'end tag': u'{/b}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Blue'), u'start tag': u'{bl}', u'start html': u'', - u'end tag': u'{/bl}', u'end html': u'', u'protected': True}) + u'end tag': u'{/bl}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Yellow'), u'start tag': u'{y}', u'start html': u'', - u'end tag': u'{/y}', u'end html': u'', u'protected': True}) + u'end tag': u'{/y}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Green'), u'start tag': u'{g}', u'start html': u'', - u'end tag': u'{/g}', u'end html': u'', u'protected': True}) + u'end tag': u'{/g}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Pink'), u'start tag': u'{pk}', u'start html': u'', - u'end tag': u'{/pk}', u'end html': u'', u'protected': True}) + u'end tag': u'{/pk}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Orange'), u'start tag': u'{o}', u'start html': u'', - u'end tag': u'{/o}', u'end html': u'', u'protected': True}) + u'end tag': u'{/o}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Purple'), u'start tag': u'{pp}', u'start html': u'', - u'end tag': u'{/pp}', u'end html': u'', u'protected': True}) + u'end tag': u'{/pp}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'White'), u'start tag': u'{w}', u'start html': u'', - u'end tag': u'{/w}', u'end html': u'', u'protected': True}) + u'end tag': u'{/w}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({ u'desc': translate('OpenLP.FormattingTags', 'Superscript'), u'start tag': u'{su}', u'start html': u'', - u'end tag': u'{/su}', u'end html': u'', u'protected': True}) + u'end tag': u'{/su}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({ u'desc': translate('OpenLP.FormattingTags', 'Subscript'), u'start tag': u'{sb}', u'start html': u'', - u'end tag': u'{/sb}', u'end html': u'', u'protected': True}) + u'end tag': u'{/sb}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({ u'desc': translate('OpenLP.FormattingTags', 'Paragraph'), u'start tag': u'{p}', u'start html': u'

', u'end tag': u'{/p}', - u'end html': u'

', u'protected': True}) + u'end html': u'

', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Bold'), u'start tag': u'{st}', u'start html': u'', u'end tag': u'{/st}', u'end html': u'', - u'protected': True}) + u'protected': True, u'temporary': False}) base_tags.append({ u'desc': translate('OpenLP.FormattingTags', 'Italics'), u'start tag': u'{it}', u'start html': u'', u'end tag': u'{/it}', - u'end html': u'', u'protected': True}) + u'end html': u'', u'protected': True, u'temporary': False}) base_tags.append({ u'desc': translate('OpenLP.FormattingTags', 'Underline'), u'start tag': u'{u}', u'start html': u'', - u'end tag': u'{/u}', u'end html': u'', u'protected': True}) + u'end tag': u'{/u}', u'end html': u'', u'protected': True, + u'temporary': False}) base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Break'), u'start tag': u'{br}', u'start html': u'
', u'end tag': u'', - u'end html': u'', u'protected': True}) + u'end html': u'', u'protected': True, u'temporary': False}) FormattingTags.add_html_tags(base_tags) @staticmethod def add_html_tags(tags): """ - Add a list of tags to the list + Add a list of tags to the list. + + ``tags`` + The list with tags to add. + + Each **tag** has to be a ``dict`` and should have the following keys: + + * desc + The formatting tag's description, e. g. **Red** + + * start tag + The start tag, e. g. ``{r}`` + + * end tag + The end tag, e. g. ``{/r}`` + + * start html + The start html tag. For instance ```` + + * end html + The end html tag. For example ```` + + * protected + A boolean stating whether this is a build-in tag or not. Should be + ``True`` in most cases. + + * temporary + A temporary tag will not be saved, but is also considered when + displaying text containing the tag. It has to be a ``boolean``. """ FormattingTags.html_expands.extend(tags) diff --git a/openlp/core/ui/formattingtagform.py b/openlp/core/ui/formattingtagform.py index 2a8625b1a..4d4739204 100644 --- a/openlp/core/ui/formattingtagform.py +++ b/openlp/core/ui/formattingtagform.py @@ -132,7 +132,8 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog): u'start html': translate('OpenLP.FormattingTagForm', ''), u'end tag': u'{/n}', u'end html': translate('OpenLP.FormattingTagForm', ''), - u'protected': False + u'protected': False, + u'temporary': False } FormattingTags.add_html_tags([tag]) self._resetTable() @@ -172,6 +173,8 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog): html[u'end html'] = unicode(self.endTagLineEdit.text()) html[u'start tag'] = u'{%s}' % tag html[u'end tag'] = u'{/%s}' % tag + # Keep temporary tags when the user changes one. + html[u'temporary'] = False self.selected = -1 self._resetTable() self._saveTable() @@ -182,7 +185,7 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog): """ tags = [] for tag in FormattingTags.get_html_tags(): - if not tag[u'protected']: + if not tag[u'protected'] and not tag[u'temporary']: tags.append(tag) # Formatting Tags were also known as display tags. QtCore.QSettings().setValue(u'displayTags/html_tags', @@ -198,8 +201,7 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog): self.savePushButton.setEnabled(False) self.deletePushButton.setEnabled(False) for linenumber, html in enumerate(FormattingTags.get_html_tags()): - self.tagTableWidget.setRowCount( - self.tagTableWidget.rowCount() + 1) + self.tagTableWidget.setRowCount(self.tagTableWidget.rowCount() + 1) self.tagTableWidget.setItem(linenumber, 0, QtGui.QTableWidgetItem(html[u'desc'])) self.tagTableWidget.setItem(linenumber, 1, @@ -208,6 +210,9 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog): QtGui.QTableWidgetItem(html[u'start html'])) self.tagTableWidget.setItem(linenumber, 3, QtGui.QTableWidgetItem(html[u'end html'])) + # Tags saved prior to 1.9.7 do not have this key. + if not html.has_key(u'temporary'): + html[u'temporary'] = False self.tagTableWidget.resizeRowsToContents() self.descriptionLineEdit.setText(u'') self.tagLineEdit.setText(u'')