Folding in the view menu

Aug 27, 2008 at 2:12 PM

 

 

Currently folding in the view menu is not working.

I would propose to only have 3 entries, namely fold all, unfold all, fold level and use the following code. 
Fold, unfold all are obvious. Fold level fold base on the current line.

        private void foldLevel(uint level)
        {
            if (ActiveDocument != null)
            {
                ActiveDocument.Scintilla.NativeInterface.Colourise(0, -1);
                foreach (Line l in ActiveDocument.Scintilla.Lines)
                    if (level >= l.FoldLevel != l.FoldExpanded)
                        ActiveDocument.Scintilla.NativeInterface.ToggleFold(l.Number);
            }
        }

        private void foldLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                foldLevel((uint)ActiveDocument.Scintilla.Lines.Current.FoldLevel);
        }

        private void foldAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foldLevel(Constants.SC_FOLDLEVELBASE);
        }

        private void unfoldAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foldLevel(uint.MaxValue);
        }

 

 

 

Aug 29, 2008 at 11:03 AM

Ok it is not that easy the folding should be done only at a fold point.
Sorry about the prvious code.

        private void foldLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
            {
                unfoldAllToolStripMenuItem_Click(sender, e);
                Line currentLine = ActiveDocument.Scintilla.Lines.Current;
                ActiveDocument.Scintilla.NativeInterface.Colourise(0, -1);
                foreach (Line l in ActiveDocument.Scintilla.Lines)
                    if (currentLine.FoldLevel == l.FoldLevel && l.IsFoldPoint && l.FoldExpanded)
                        ActiveDocument.Scintilla.NativeInterface.ToggleFold(l.Number);
            }
        }

        private void foldAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
            {
                ActiveDocument.Scintilla.NativeInterface.Colourise(0, -1);
                foreach (Line l in ActiveDocument.Scintilla.Lines)
                    if (l.IsFoldPoint && l.FoldExpanded)
                        ActiveDocument.Scintilla.NativeInterface.ToggleFold(l.Number);
            }
        }

        private void unfoldAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
            {
                ActiveDocument.Scintilla.NativeInterface.Colourise(0, -1);
                foreach (Line l in ActiveDocument.Scintilla.Lines)
                    if (l.IsFoldPoint && !l.FoldExpanded)
                        ActiveDocument.Scintilla.NativeInterface.ToggleFold(l.Number);
            }
        }

Nov 23, 2009 at 10:45 PM

thanks, <flagging thread>.