(meant for this to be posted on the list)<div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Having an unfoldAll() function seems like a reasonable solution. Is there some way I can "officially" request such an addition?</span></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">Jared<br>
</span></font><br><div class="gmail_quote">On Wed, Feb 17, 2010 at 7:22 AM, Phil Thompson <span dir="ltr"><<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Tue, 16 Feb 2010 03:50:22 -0500, Jared Sutton <<a href="mailto:jpsutton@gmail.com">jpsutton@gmail.com</a>><br>
wrote:<br>
<div><div></div><div class="h5">> Hi All,<br>
><br>
> For the last several years (spare time) I've been constructing a simple<br>
> cross-platform code editor called QSciTE using Qt4 version of<br>
Qscintilla2.<br>
> You can find it here, in case you're interested:<br>
><br>
> <a href="http://qscite.googlecode.com/" target="_blank">http://qscite.googlecode.com/</a><br>
><br>
> First off, thanks very much for making this library available to the<br>
public<br>
> under the GPL. It has some wonderful functionality built-in.<br>
><br>
> I've been having some issues with code folding recently, which I believe<br>
to<br>
> have stemmed from at least one bug in Qscintilla. I have a simple menu<br>
> option to enable/disable code folding. Whenever I turn folding off, I<br>
want<br>
> any lines that are currently folded to be unfolded automatically, since<br>
it<br>
> doesn't make a whole lot of sense to have folded code that can't easily<br>
be<br>
> unfolded. Here's my toggleFolding() function which is directly connected<br>
> to<br>
> the menu option:<br>
><br>
> void MainWindow::toggleFolding() {<br>
> QsciteEditor * doc = getCurDoc();<br>
> QsciteEditor::FoldStyle state =<br>
> static_cast<QsciteEditor::FoldStyle>((!doc->folding()) * 5);<br>
><br>
> if (!state) {<br>
> // unfold all code before turning off folding<br>
> doc->foldAll(false);<br>
> }<br>
><br>
> doc->setFolding(state);<br>
> }<br>
><br>
> The QsciteEditor class is a child-class of Qscintilla, because I needed<br>
to<br>
> expose several functions for use with QtScript, and because I needed to<br>
> catch some key-presses that I needed to process specially. As you can<br>
see,<br>
> foldAll() is only getting called just before the folding is about to be<br>
> turned off. The documentation for foldAll() states "If any lines are<br>
> currently folded then they are all unfolded. Otherwise all lines are<br>
> folded." Now, my implementation does not take into account the<br>
possibility<br>
> that no lines were folded between the time that the folding was enabled<br>
and<br>
> disabled (which I'll expand on below), meaning that if foldAll() works as<br>
> documented, I should expect to see all lines get folded before the<br>
folding<br>
> is disabled. However, even when I fold one or more lines and then turn<br>
off<br>
> folding, I find that all lines are getting folded before folding gets<br>
> disabled. This seems like it's a problem with the foldAll()<br>
> implementation.<br>
<br>
</div></div>It depends...<br>
<br>
foldAll() can only deal with what a particular lexer has set in the way of<br>
fold flags. I've found that lexers don't always exhibit consistent<br>
behaviour - some are just wrong.<br>
<br>
Both Scite and QScintilla will call foldAll() (or the Scite equivalent)<br>
when you shift-control-click in the fold margin. I would compare the result<br>
of doing this in Scite with the same lexer set and the same file being<br>
edited. If the result is different then it's probably a QScintilla bug. If<br>
it's not then it's likely to be a Scintilla bug or feature (ie. in the<br>
particular lexer itself).<br>
<div class="im"><br>
> This also brings up a few questions:<br>
> 1. Shouldn't setFolding() automatically unfold all lines that are<br>
currently<br>
> folded before the FoldStyle is set to NoFoldStyle? Does anyone expect to<br>
> have lines folded after they disable folding?<br>
> 2. If the person using QsciScintilla is expected to unfold all lines that<br>
> were folded before turning folding off, how can he know what lines are<br>
> folded? As far as I can tell, that information is private, as are the<br>
> functions/signals/slots that are responsible for changing a line's fold<br>
> state.<br>
><br>
> So, I see these issues in the end:<br>
> 1. There appears to be a bug in the QsciScintilla:foldAll(bool) function.<br>
> It doesn't appear to function as documented.<br>
> 2. In my opinion, QsciScintilla::setFolding() should either unfold<br>
> everything when folding is turned off, or the appropriate member<br>
> variables/functions/signals/slots should be changed from private to<br>
> protected so that developers can deal with the situation without<br>
resorting<br>
> to hacking on Qscintilla directly.<br>
<br>
</div>How about an unfoldAll() method? (It's a shame that foldAll() was so badly<br>
named.) That would allow it to be used separately from setFolding(), and<br>
wouldn't change the behaviour of the latter for existing applications.<br>
<div><div></div><div class="h5"><br>
> For what it's worth, here's my development environment:<br>
> Arch Linux<br>
> KDEmod 4.4.0<br>
> Qscintilla 2.4.2<br>
> Qt 4.6.1<br>
><br>
> Thanks for any insight you may have.<br>
><br>
> Jared Sutton<br>
<br>
</div></div><font color="#888888">Phil<br>
</font></blockquote></div><br></div>