private void UpdateFilter()
        {
            toSourceIndex.Clear();

            var count = base.lines.Count;
            var regex = new Regex(LineFilterRegex);

            for (int i = 0; i < count; i++)
            {
                if (regex.IsMatch(lines[i].Text))
                {
                    toSourceIndex.Add(i);
                }
            }

            CurrentTB.NeedRecalc(true);
            CurrentTB.Invalidate();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load styledText - recalculate line width, repaint control, update scrollbars, recolor text.
        /// </summary>
        /// <param name="styledText">Class which stores text data along with styles for each character.</param>
        public void Load(StyledText styledText, bool refreshSizeOnly = false)
        {
            //
            // Calculates line width based on FCTB component size (line widht is same for all lines)
            //

            int indent          = SystemInformation.VerticalScrollBarWidth + 5;
            int prev_linesCount = linesCount;

            charsCountInLine   = (CurrentTB.Width - indent) / CurrentTB.CharWidth - 1;
            linesCount         = styledText.Length / charsCountInLine + 1;
            linesCountInWindow = Math.Min(linesCount, CurrentTB.Height / CurrentTB.CharHeight);

            if (CurrentTB.ShowLineNumbers)
            {
                indent             = linesCount.ToString().Length *CurrentTB.CharWidth + 30;
                charsCountInLine   = (CurrentTB.Width - indent) / CurrentTB.CharWidth - 1;
                linesCount         = styledText.Length / charsCountInLine + 1;
                linesCountInWindow = Math.Min(linesCount, CurrentTB.Height / CurrentTB.CharHeight);
            }

            if (refreshSizeOnly && linesCount == prev_linesCount)
            {
                // here we exit, since we dont need to reload data - we have same linesCount
                //Debug.WriteLine("DynamicTextSource.Load skipped");
                return;
            }



            StyledText = styledText;
            loadedLines.Clear();

            //
            // Copy styles from "StyledText" to our class 'DynamicTextSource'
            //
            for (int i = 0; i < Styles.Length; i++)
            {
                Styles[i] = (i < styledText.Styles.Count)
                    ? styledText.Styles[i]
                    : null;
            }


            //
            // Recreate lines
            //

            UnloadUnusedLines(true); // clear all defined items in base.lines
            if (prev_linesCount > linesCount)
            {
                // remove items
                base.lines.RemoveRange(linesCount, prev_linesCount - linesCount);
                //Debug.WriteLine("Removed  " + (prev_linesCount - linesCount));
            }
            else
            {
                //add items
                base.lines.AddRange(new Line[linesCount - prev_linesCount]);
                //Debug.WriteLine("Added  " + (linesCount - prev_linesCount));
            }


            //
            // Load first visible lines
            //

            for (int i = 0; i < linesCountInWindow; i++)
            {
                LoadLineFromSourceString(i);
            }


            //
            // Recalculate scrollbars and other data for rendering controll
            //

            if (CurrentTB is DNAFastColoredTextBox)
            {
                // call custom method which is speed optimized
                (CurrentTB as DNAFastColoredTextBox).RecalcMy();
            }
            else
            {
                CurrentTB.LineInfos.Clear();
                CurrentTB.LineInfos.AddRange(new LineInfo[linesCount]);
                NeedRecalc(new TextChangedEventArgs(0, linesCount - 1));
                if (CurrentTB.WordWrap)
                {
                    OnRecalcWordWrap(new TextChangedEventArgs(0, linesCount - 1));
                }
                CurrentTB.NeedRecalc(true, false);
            }
        }