QScintilla/MarkupProviders/RestructuredTextProvider.py

changeset 5411
a163fbbf2bea
parent 5407
f833f89571b8
child 5412
db5a520f69d3
--- a/QScintilla/MarkupProviders/RestructuredTextProvider.py	Tue Jan 10 15:35:08 2017 +0100
+++ b/QScintilla/MarkupProviders/RestructuredTextProvider.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
 
@@ -344,3 +345,90 @@
             cline, cindex = editor.getCursorPosition()
             editor.setCursorPosition(cline + lines, 0)
             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, False)
+    
+    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, True)
+    
+    def __makeList(self, editor, numberedList):
+        """
+        Private method to generate the desired list markup.
+        
+        @param editor reference to the editor to work on
+        @type Editor
+        @param numberedList flag indicating the generation of a numbered list
+        @type bool
+        """
+        if editor is None:
+            return
+        
+        if numberedList:
+            markup = "  #. "
+        else:
+            markup = "  * "
+        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(markup, line, 0)
+            editor.setCursorPosition(endLine + 1, 0)
+        else:
+            listElements, ok = QInputDialog.getInt(
+                None,
+                QCoreApplication.translate(
+                    "RestructuredTextProvider", "Create List"),
+                QCoreApplication.translate(
+                    "RestructuredTextProvider",
+                    "Enter desired number of list elements:"),
+                0, 0, 99, 1)
+            if ok:
+                if listElements == 0:
+                    listElements = 1
+                cline, cindex = editor.getCursorPosition()
+                listBody = \
+                    listElements * "{1}{0}".format(lineSeparator, markup)
+                if cindex == 0:
+                    editor.insertAt(listBody, cline, cindex)
+                    editor.setCursorPosition(cline, len(markup))
+                else:
+                    if cline == editor.lines() - 1:
+                        editor.insertAt(lineSeparator, cline, 1000)
+                    editor.insertAt(listBody, cline + 1, 0)
+                    editor.setCursorPosition(cline + 1, len(markup))
+        editor.endUndoAction()

eric ide

mercurial