XML Code Folding

Mar 27, 2012 at 9:11 PM

I'm unable to get this to work properly.  

In order for it to work, I have to set all parameters in BOTH design time and run time.  Change anything, and the plus/minus boxes do not show up.  Here is my run time code:

scintilla1.Margins.Margin1.Width = 50;
scintilla1.Folding.IsEnabled = true;
scintilla1.Folding.UseCompactFolding = true;
scintilla1.Lexing.Lexer = Lexer.Xml;
scintilla1.Lexing.LexerName = "xml";
scintilla1.ConfigurationManager.Language = "xml";

I have to set these parameters in the designer as well.  If I leave the designer at its default, it doesn't work.  

Is this a bug or am I missing something somewhere?


Mar 29, 2012 at 2:43 PM

There are two problems that I can see.

First, it looks like you're treating Margin1 as a fold margin which it normally isn't by default. Try working with Margin2 instead.

The other issue is one of the idiosyncrasies with Scintilla that we haven't handled very well in ScintillaNET. Folding is actually a property set on each individual lexer. We've broken it out into it's own property but it really is a function of the lexer:

public bool IsEnabled
        return Scintilla.Lexing.GetProperty("fold") == "1";
        string s;
        if (value)
            s = "1";
            s = "0";

        Scintilla.Lexing.SetProperty("fold", s);
        Scintilla.Lexing.SetProperty("fold.html", s);

Your issue pretty much stems from the fact that in the setter, we're setting folding for HTML (i.e. XML) but on the getter that's not the value we're giving back to you. Consequently the IsEnabled property isn't getting serialized at design time (or giving you an accurate value) and you must set it again at runtime. The order of design time serialization is also critical but that's another topic.

For now you can continue to work around your issue by setting the Folding.IsEnabled property early in your form/control load to reset it, however, I would encourage you to create a work item in our Issue Tracker and offer suggestions on a fix.