QScintilla/MarkupProviders/RestructuredTextProvider.py

changeset 5398
1f4509cf8f35
parent 5397
fee5485e67f4
child 5402
ce21a78a5fcf
--- a/QScintilla/MarkupProviders/RestructuredTextProvider.py	Mon Jan 02 12:49:28 2017 +0100
+++ b/QScintilla/MarkupProviders/RestructuredTextProvider.py	Mon Jan 02 20:13:40 2017 +0100
@@ -21,6 +21,17 @@
         Constructor
         """
         super(RestructuredTextProvider, self).__init__()
+        
+        self.__headerChars = ["=", "-", "~", "+", "#", "^"]
+    
+    def kind(self):
+        """
+        Public method to get the markup kind.
+        
+        @return string with markup kind
+        @rtype str
+        """
+        return "rest"
     
     def hasBold(self):
         """
@@ -40,6 +51,15 @@
         """
         return True
     
+    def headerLevels(self):
+        """
+        Public method to determine the available header levels.
+        
+        @return supported header levels
+        @rtype int
+        """
+        return len(self.__headerChars)
+    
     def bold(self, editor):
         """
         Public method to generate bold text.
@@ -58,6 +78,30 @@
         """
         self.__insertMarkup("*", editor)
     
+    def header(self, editor, level):
+        """
+        Public method to generate a header.
+        
+        @param editor reference to the editor to work on
+        @type Editor
+        @param level header level
+        @type int
+        """
+        if editor is None or level > self.headerLevels():
+            return
+        
+        editor.beginUndoAction()
+        cline, cindex = editor.getCursorPosition()
+        lineSeparator = editor.getLineSeparator()
+        if not editor.text(cline).endswith(lineSeparator):
+            editor.insertAt(lineSeparator, cline, len(editor.text(cline)))
+        lineLength = len(editor.text(cline)) - len(lineSeparator)
+        editor.insertAt(
+            lineLength * self.__headerChars[level - 1] + lineSeparator,
+            cline + 1, 0)
+        editor.setCursorPosition(cline + 2, 0)
+        editor.endUndoAction()
+    
     def __insertMarkup(self, markup, editor):
         """
         Private method to insert the specified markup.

eric ide

mercurial