--- a/QScintilla/MarkupProviders/HtmlProvider.py Tue Jan 10 15:35:08 2017 +0100 +++ b/QScintilla/MarkupProviders/HtmlProvider.py Tue Jan 10 19:15:17 2017 +0100 @@ -9,7 +9,8 @@ from __future__ import unicode_literals -from PyQt5.QtWidgets import QDialog +from PyQt5.QtCore import QCoreApplication +from PyQt5.QtWidgets import QDialog, QInputDialog from .MarkupBase import MarkupBase @@ -316,3 +317,94 @@ cline, cindex = editor.getCursorPosition() editor.setCursorPosition(cline, cindex + len(markup)) editor.endUndoAction() + + def hasBulletedList(self): + """ + Public method to indicate the availability of bulleted list markup. + + @return flag indicating the availability of bulleted list markup + @rtype bool + """ + return True + + def bulletedList(self, editor): + """ + Public method to generate bulleted list text. + + @param editor reference to the editor to work on + @type Editor + """ + self.__makeList(editor, "ul") + + def hasNumberedList(self): + """ + Public method to indicate the availability of numbered list markup. + + @return flag indicating the availability of numbered list markup + @rtype bool + """ + return True + + def numberedList(self, editor): + """ + Public method to generate numbered list text. + + @param editor reference to the editor to work on + @type Editor + """ + self.__makeList(editor, "ol") + + def __makeList(self, editor, listType): + """ + Private method to generate the desired list markup. + + @param editor reference to the editor to work on + @type Editor + @param listType type of the desired list (should be ul or ol) + @type str + """ + if editor is None: + return + + lineSeparator = editor.getLineSeparator() + editor.beginUndoAction() + if editor.hasSelectedText(): + startLine, startIndex, endLine, endIndex = \ + editor.getSelection() + if endIndex == 0: + endLine -= 1 + for line in range(startLine, endLine + 1): + editor.insertAt("</li>", line, len(editor.text(line).rstrip())) + editor.insertAt(" <li>", line, 0) + if line == editor.lines() - 1: + editor.insertAt(lineSeparator, line, 1000) + editor.insertAt("</{1}>{0}".format(lineSeparator, listType), + endLine + 1, 0) + editor.insertAt("<{1}>{0}".format(lineSeparator, listType), + startLine, 0) + editor.setCursorPosition(endLine + 3, 0) + else: + listElements, ok = QInputDialog.getInt( + None, + QCoreApplication.translate( + "HtmlProvider", "Create List"), + QCoreApplication.translate( + "HtmlProvider", "Enter desired number of list elements:"), + 0, 0, 99, 1) + if ok: + if listElements == 0: + listElements = 1 + cline, cindex = editor.getCursorPosition() + listBody = \ + listElements * " <li></li>{0}".format(lineSeparator) + markup = "<{1}>{0}{2}</{1}>{0}".format( + lineSeparator, listType, listBody) + if cindex == 0: + editor.insertAt(markup, cline, cindex) + editor.setCursorPosition(cline + 1, 6) + else: + if cline == editor.lines() - 1: + editor.insertAt(lineSeparator, cline, 1000) + editor.insertAt(markup, cline + 1, 0) + editor.setCursorPosition(cline + 2, 6) + editor.endUndoAction()