Adjusted code to use the QScintilla contractedFolds() and setContractedFolds() methods (as of QScintilla 2.5).

Thu, 10 Mar 2011 14:50:53 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 10 Mar 2011 14:50:53 +0100
changeset 938
f421f2138c0f
parent 937
336c8f1ee7bb
child 939
10d3a201cd27

Adjusted code to use the QScintilla contractedFolds() and setContractedFolds() methods (as of QScintilla 2.5).

APIs/Python3/eric5.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.QScintilla.Editor.html file | annotate | diff | comparison | revisions
Documentation/Source/eric5.QScintilla.QsciScintillaCompat.html file | annotate | diff | comparison | revisions
E5XML/SessionReader.py file | annotate | diff | comparison | revisions
E5XML/SessionWriter.py file | annotate | diff | comparison | revisions
QScintilla/Editor.py file | annotate | diff | comparison | revisions
QScintilla/QsciScintillaCompat.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric5.api	Thu Mar 10 14:00:34 2011 +0100
+++ b/APIs/Python3/eric5.api	Thu Mar 10 14:50:53 2011 +0100
@@ -5056,7 +5056,6 @@
 eric5.QScintilla.Editor.Editor.getFileType?4()
 eric5.QScintilla.Editor.Editor.getFileTypeByFlag?4()
 eric5.QScintilla.Editor.Editor.getFlakesWarnings?4()
-eric5.QScintilla.Editor.Editor.getFolds?4()
 eric5.QScintilla.Editor.Editor.getHighlightPosition?4()
 eric5.QScintilla.Editor.Editor.getLanguage?4(normalized = True)
 eric5.QScintilla.Editor.Editor.getLexer?4()
@@ -5463,6 +5462,7 @@
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.clearIndicatorRange?4(indicator, spos, length)
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.clearKeys?4()
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.clearStyles?4()
+eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.contractedFolds?4()
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.currentPosition?4()
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.currentStyle?4()
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.delete?4()
@@ -5513,6 +5513,7 @@
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.positionFromPoint?4(point)
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.replaceTarget?4(replaceStr)
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.scrollVertical?4(lines)
+eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.setContractedFolds?4(folds)
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.setCurrentIndicator?4(indicator)
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.setCursorFlashTime?4(time)
 eric5.QScintilla.QsciScintillaCompat.QsciScintillaCompat.setEolModeByEolString?4(eolStr)
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Thu Mar 10 14:00:34 2011 +0100
+++ b/Documentation/Help/source.qhp	Thu Mar 10 14:50:53 2011 +0100
@@ -5532,6 +5532,7 @@
       <keyword name="QsciScintillaCompat.clearIndicatorRange" id="QsciScintillaCompat.clearIndicatorRange" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.clearIndicatorRange" />
       <keyword name="QsciScintillaCompat.clearKeys" id="QsciScintillaCompat.clearKeys" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.clearKeys" />
       <keyword name="QsciScintillaCompat.clearStyles" id="QsciScintillaCompat.clearStyles" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.clearStyles" />
+      <keyword name="QsciScintillaCompat.contractedFolds" id="QsciScintillaCompat.contractedFolds" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.contractedFolds" />
       <keyword name="QsciScintillaCompat.currentPosition" id="QsciScintillaCompat.currentPosition" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.currentPosition" />
       <keyword name="QsciScintillaCompat.currentStyle" id="QsciScintillaCompat.currentStyle" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.currentStyle" />
       <keyword name="QsciScintillaCompat.delete" id="QsciScintillaCompat.delete" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.delete" />
@@ -5582,6 +5583,7 @@
       <keyword name="QsciScintillaCompat.positionFromPoint" id="QsciScintillaCompat.positionFromPoint" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.positionFromPoint" />
       <keyword name="QsciScintillaCompat.replaceTarget" id="QsciScintillaCompat.replaceTarget" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.replaceTarget" />
       <keyword name="QsciScintillaCompat.scrollVertical" id="QsciScintillaCompat.scrollVertical" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.scrollVertical" />
+      <keyword name="QsciScintillaCompat.setContractedFolds" id="QsciScintillaCompat.setContractedFolds" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.setContractedFolds" />
       <keyword name="QsciScintillaCompat.setCurrentIndicator" id="QsciScintillaCompat.setCurrentIndicator" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.setCurrentIndicator" />
       <keyword name="QsciScintillaCompat.setCursorFlashTime" id="QsciScintillaCompat.setCursorFlashTime" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.setCursorFlashTime" />
       <keyword name="QsciScintillaCompat.setEolModeByEolString" id="QsciScintillaCompat.setEolModeByEolString" ref="eric5.QScintilla.QsciScintillaCompat.html#QsciScintillaCompat.setEolModeByEolString" />
@@ -5936,7 +5938,6 @@
       <keyword name="Editor.getFileType" id="Editor.getFileType" ref="eric5.QScintilla.Editor.html#Editor.getFileType" />
       <keyword name="Editor.getFileTypeByFlag" id="Editor.getFileTypeByFlag" ref="eric5.QScintilla.Editor.html#Editor.getFileTypeByFlag" />
       <keyword name="Editor.getFlakesWarnings" id="Editor.getFlakesWarnings" ref="eric5.QScintilla.Editor.html#Editor.getFlakesWarnings" />
-      <keyword name="Editor.getFolds" id="Editor.getFolds" ref="eric5.QScintilla.Editor.html#Editor.getFolds" />
       <keyword name="Editor.getHighlightPosition" id="Editor.getHighlightPosition" ref="eric5.QScintilla.Editor.html#Editor.getHighlightPosition" />
       <keyword name="Editor.getLanguage" id="Editor.getLanguage" ref="eric5.QScintilla.Editor.html#Editor.getLanguage" />
       <keyword name="Editor.getLexer" id="Editor.getLexer" ref="eric5.QScintilla.Editor.html#Editor.getLexer" />
--- a/Documentation/Source/eric5.QScintilla.Editor.html	Thu Mar 10 14:00:34 2011 +0100
+++ b/Documentation/Source/eric5.QScintilla.Editor.html	Thu Mar 10 14:50:53 2011 +0100
@@ -661,9 +661,6 @@
 <td><a href="#Editor.getFlakesWarnings">getFlakesWarnings</a></td>
 <td>Public method to retrieve the flakes warning markers.</td>
 </tr><tr>
-<td><a href="#Editor.getFolds">getFolds</a></td>
-<td>Public method to get a list line numbers of collapsed folds.</td>
-</tr><tr>
 <td><a href="#Editor.getHighlightPosition">getHighlightPosition</a></td>
 <td>Public method to return the position of the highlight bar.</td>
 </tr><tr>
@@ -2405,16 +2402,6 @@
 sorted list of all lines containing a flakes warning
             (list of integer)
 </dd>
-</dl><a NAME="Editor.getFolds" ID="Editor.getFolds"></a>
-<h4>Editor.getFolds</h4>
-<b>getFolds</b>(<i></i>)
-<p>
-        Public method to get a list line numbers of collapsed folds.
-</p><dl>
-<dt>Returns:</dt>
-<dd>
-list of line numbers of folded lines (list of integer)
-</dd>
 </dl><a NAME="Editor.getHighlightPosition" ID="Editor.getHighlightPosition"></a>
 <h4>Editor.getHighlightPosition</h4>
 <b>getHighlightPosition</b>(<i></i>)
--- a/Documentation/Source/eric5.QScintilla.QsciScintillaCompat.html	Thu Mar 10 14:00:34 2011 +0100
+++ b/Documentation/Source/eric5.QScintilla.QsciScintillaCompat.html	Thu Mar 10 14:50:53 2011 +0100
@@ -97,6 +97,9 @@
 <td><a href="#QsciScintillaCompat.clearStyles">clearStyles</a></td>
 <td>Public method to set the styles according the selected Qt style.</td>
 </tr><tr>
+<td><a href="#QsciScintillaCompat.contractedFolds">contractedFolds</a></td>
+<td>Public method to get a list of line numbers of collapsed folds.</td>
+</tr><tr>
 <td><a href="#QsciScintillaCompat.currentPosition">currentPosition</a></td>
 <td>Public method to get the current position.</td>
 </tr><tr>
@@ -247,6 +250,9 @@
 <td><a href="#QsciScintillaCompat.scrollVertical">scrollVertical</a></td>
 <td>Public method to scroll the text area.</td>
 </tr><tr>
+<td><a href="#QsciScintillaCompat.setContractedFolds">setContractedFolds</a></td>
+<td>Public method to set a list of line numbers of collapsed folds.</td>
+</tr><tr>
 <td><a href="#QsciScintillaCompat.setCurrentIndicator">setCurrentIndicator</a></td>
 <td>Public method to set the current indicator.</td>
 </tr><tr>
@@ -357,7 +363,8 @@
 <h4>QsciScintillaCompat.byteAt</h4>
 <b>byteAt</b>(<i>pos</i>)
 <p>
-        Public method to get the raw character (bytes) at a position in the text.
+        Public method to get the raw character (bytes) at a position in the
+        text.
 </p><dl>
 <dt><i>pos</i></dt>
 <dd>
@@ -366,8 +373,8 @@
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
-raw character at the requested position or empty bytes, if the position
-            is negative or past the end of the document (bytes)
+raw character at the requested position or empty bytes, if the
+            position is negative or past the end of the document (bytes)
 </dd>
 </dl><a NAME="QsciScintillaCompat.charAt" ID="QsciScintillaCompat.charAt"></a>
 <h4>QsciScintillaCompat.charAt</h4>
@@ -383,8 +390,8 @@
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
-character at the requested position or empty string, if the position
-            is negative or past the end of the document (string)
+character at the requested position or empty string, if the
+            position is negative or past the end of the document (string)
 </dd>
 </dl><a NAME="QsciScintillaCompat.clearAllIndicators" ID="QsciScintillaCompat.clearAllIndicators"></a>
 <h4>QsciScintillaCompat.clearAllIndicators</h4>
@@ -452,7 +459,17 @@
 <b>clearStyles</b>(<i></i>)
 <p>
         Public method to set the styles according the selected Qt style.
-</p><a NAME="QsciScintillaCompat.currentPosition" ID="QsciScintillaCompat.currentPosition"></a>
+</p><a NAME="QsciScintillaCompat.contractedFolds" ID="QsciScintillaCompat.contractedFolds"></a>
+<h4>QsciScintillaCompat.contractedFolds</h4>
+<b>contractedFolds</b>(<i></i>)
+<p>
+            Public method to get a list of line numbers of collapsed folds.
+</p><dl>
+<dt>Returns:</dt>
+<dd>
+list of line numbers of folded lines (list of integer)
+</dd>
+</dl><a NAME="QsciScintillaCompat.currentPosition" ID="QsciScintillaCompat.currentPosition"></a>
 <h4>QsciScintillaCompat.currentPosition</h4>
 <b>currentPosition</b>(<i></i>)
 <p>
@@ -655,7 +672,8 @@
 <h4>QsciScintillaCompat.foldHeaderAt</h4>
 <b>foldHeaderAt</b>(<i>line</i>)
 <p>
-        Public method to determine, if a line of the document is a fold header line.
+        Public method to determine, if a line of the document is a fold header
+        line.
 </p><dl>
 <dt><i>line</i></dt>
 <dd>
@@ -685,10 +703,11 @@
 <h4>QsciScintillaCompat.getCursorFlashTime</h4>
 <b>getCursorFlashTime</b>(<i></i>)
 <p>
-        Public method to get the flash (blink) time of the cursor in milliseconds.
+        Public method to get the flash (blink) time of the cursor in
+        milliseconds.
 </p><p>
         The flash time is the time required to display, invert and restore the 
-        caret display. Usually the text cursor is displayed for half the cursor 
+        caret display. Usually the text cursor is displayed for half the cursor
         flash time, then hidden for the same amount of time.
 </p><dl>
 <dt>Returns:</dt>
@@ -793,11 +812,11 @@
             QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
 </dd><dt><i>style</i></dt>
 <dd>
-style to be used for the indicator (QsciScintilla.INDIC_PLAIN,
-            QsciScintilla.INDIC_SQUIGGLE, QsciScintilla.INDIC_TT,
-            QsciScintilla.INDIC_DIAGONAL, QsciScintilla.INDIC_STRIKE,
-            QsciScintilla.INDIC_HIDDEN, QsciScintilla.INDIC_BOX,
-            QsciScintilla.INDIC_ROUNDBOX)
+style to be used for the indicator
+            (QsciScintilla.INDIC_PLAIN, QsciScintilla.INDIC_SQUIGGLE,
+            QsciScintilla.INDIC_TT, QsciScintilla.INDIC_DIAGONAL,
+            QsciScintilla.INDIC_STRIKE, QsciScintilla.INDIC_HIDDEN,
+            QsciScintilla.INDIC_BOX, QsciScintilla.INDIC_ROUNDBOX)
 </dd><dt><i>color</i></dt>
 <dd>
 color to be used by the indicator (QColor)
@@ -839,13 +858,14 @@
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
-position of the line end disregarding line end characters (integer)
+position of the line end disregarding line end characters
+            (integer)
 </dd>
 </dl><a NAME="QsciScintillaCompat.lineIndexFromPosition" ID="QsciScintillaCompat.lineIndexFromPosition"></a>
 <h4>QsciScintillaCompat.lineIndexFromPosition</h4>
 <b>lineIndexFromPosition</b>(<i>pos</i>)
 <p>
-        Public method to convert an absolute position to line and index.
+            Public method to convert an absolute position to line and index.
 </p><dl>
 <dt><i>pos</i></dt>
 <dd>
@@ -910,8 +930,8 @@
 <h4>QsciScintillaCompat.positionAfter</h4>
 <b>positionAfter</b>(<i>pos</i>)
 <p>
-        Public method to get the position after the given position taking into account
-        multibyte characters.
+        Public method to get the position after the given position taking into
+        account multibyte characters.
 </p><dl>
 <dt><i>pos</i></dt>
 <dd>
@@ -926,8 +946,8 @@
 <h4>QsciScintillaCompat.positionBefore</h4>
 <b>positionBefore</b>(<i>pos</i>)
 <p>
-        Public method to get the position before the given position taking into account
-        multibyte characters.
+        Public method to get the position before the given position taking into
+        account multibyte characters.
 </p><dl>
 <dt><i>pos</i></dt>
 <dd>
@@ -942,7 +962,7 @@
 <h4>QsciScintillaCompat.positionFromLineIndex</h4>
 <b>positionFromLineIndex</b>(<i>line, index</i>)
 <p>
-        Public method to convert line and index to an absolute position.
+            Public method to convert line and index to an absolute position.
 </p><dl>
 <dt><i>line</i></dt>
 <dd>
@@ -960,7 +980,8 @@
 <h4>QsciScintillaCompat.positionFromPoint</h4>
 <b>positionFromPoint</b>(<i>point</i>)
 <p>
-        Public method to calculate the scintilla position from a point in the window.
+        Public method to calculate the scintilla position from a point in the
+        window.
 </p><dl>
 <dt><i>point</i></dt>
 <dd>
@@ -969,8 +990,8 @@
 </dl><dl>
 <dt>Returns:</dt>
 <dd>
-scintilla position (integer) or -1 to indicate, that the point is not
-            near any character
+scintilla position (integer) or -1 to indicate, that the point
+            is not near any character
 </dd>
 </dl><a NAME="QsciScintillaCompat.replaceTarget" ID="QsciScintillaCompat.replaceTarget"></a>
 <h4>QsciScintillaCompat.replaceTarget</h4>
@@ -993,6 +1014,16 @@
 number of lines to scroll (negative scrolls up,
             positive scrolls down) (integer)
 </dd>
+</dl><a NAME="QsciScintillaCompat.setContractedFolds" ID="QsciScintillaCompat.setContractedFolds"></a>
+<h4>QsciScintillaCompat.setContractedFolds</h4>
+<b>setContractedFolds</b>(<i>folds</i>)
+<p>
+        Public method to set a list of line numbers of collapsed folds.
+</p><dl>
+<dt><i>folds</i></dt>
+<dd>
+list of line numbers of folded lines (list of integer)
+</dd>
 </dl><a NAME="QsciScintillaCompat.setCurrentIndicator" ID="QsciScintillaCompat.setCurrentIndicator"></a>
 <h4>QsciScintillaCompat.setCurrentIndicator</h4>
 <b>setCurrentIndicator</b>(<i>indicator</i>)
@@ -1013,10 +1044,11 @@
 <h4>QsciScintillaCompat.setCursorFlashTime</h4>
 <b>setCursorFlashTime</b>(<i>time</i>)
 <p>
-        Public method to get the flash (blink) time of the cursor in milliseconds.
+        Public method to get the flash (blink) time of the cursor in
+        milliseconds.
 </p><p>
         The flash time is the time required to display, invert and restore the 
-        caret display. Usually the text cursor is displayed for half the cursor 
+        caret display. Usually the text cursor is displayed for half the cursor
         flash time, then hidden for the same amount of time.
 </p><dl>
 <dt><i>time</i></dt>
--- a/E5XML/SessionReader.py	Thu Mar 10 14:00:34 2011 +0100
+++ b/E5XML/SessionReader.py	Thu Mar 10 14:50:53 2011 +0100
@@ -105,7 +105,7 @@
                     cindex = int(self.attribute("cindex", "0"))
                     folds = self.attribute("folds")
                     if folds:
-                        folds = [int(f) for f in folds.split(',')]
+                        folds = [int(f) - 1 for f in folds.split(',')]
                     else:
                         folds = []
                     zoom = int(self.attribute("zoom", "-9999"))
@@ -118,8 +118,7 @@
                             ed.zoomTo(zoom)
                         if folds:
                             ed.recolor()
-                            for line in folds:
-                                ed.foldLine(line - 1)
+                            ed.setContractedFolds(folds)
                         ed.setCursorPosition(cline, cindex)
                         ed.ensureCursorVisible()
                 else:
--- a/E5XML/SessionWriter.py	Thu Mar 10 14:00:34 2011 +0100
+++ b/E5XML/SessionWriter.py	Thu Mar 10 14:50:53 2011 +0100
@@ -75,7 +75,8 @@
                 ed = self.vm.getOpenEditor(of)
                 if ed is not None:
                     line, index = ed.getCursorPosition()
-                    folds = ','.join([str(i + 1) for i in ed.getFolds()])
+                    folds = ','.join(
+                        [str(i + 1) for i in ed.contractedFolds()])
                     zoom = ed.getZoom()
                 else:
                     line, index = 0, 0
--- a/QScintilla/Editor.py	Thu Mar 10 14:00:34 2011 +0100
+++ b/QScintilla/Editor.py	Thu Mar 10 14:50:53 2011 +0100
@@ -1584,21 +1584,6 @@
         """
         return self.encoding
         
-    def getFolds(self):
-        """
-        Public method to get a list line numbers of collapsed folds.
-        
-        @return list of line numbers of folded lines (list of integer)
-        """
-        line = 0
-        folds = []
-        maxline = self.lines()
-        while line < maxline:
-            if self.foldHeaderAt(line) and not self.foldExpandedAt(line):
-                folds.append(line)
-            line += 1
-        return folds
-        
     def isPy2File(self):
         """
         Public method to return a flag indicating a Python file.
--- a/QScintilla/QsciScintillaCompat.py	Thu Mar 10 14:00:34 2011 +0100
+++ b/QScintilla/QsciScintillaCompat.py	Thu Mar 10 14:50:53 2011 +0100
@@ -1086,6 +1086,32 @@
             
             return lin, indx
     
+    if "contractedFolds" not in QsciScintilla.__dict__:
+        def contractedFolds(self):
+            """
+            Public method to get a list of line numbers of collapsed folds.
+            
+            @return list of line numbers of folded lines (list of integer)
+            """
+            line = 0
+            folds = []
+            maxline = self.lines()
+            while line < maxline:
+                if self.foldHeaderAt(line) and not self.foldExpandedAt(line):
+                    folds.append(line)
+                line += 1
+            return folds
+    
+##    if "setContractedFolds" not in QsciScintilla.__dict__:
+    def setContractedFolds(self, folds):
+        """
+        Public method to set a list of line numbers of collapsed folds.
+        
+        @param folds list of line numbers of folded lines (list of integer)
+        """
+        for line in folds:
+            self.foldLine(line)
+    
 ##    #########################################################################
 ##    # methods below have been added to QScintilla starting with version 2.x
 ##    #########################################################################

eric ide

mercurial