コード例 #1
0
        public MultiLineTextManager(MultiLineTextBox owner, SpecialCharacterFlags flags)
        {
            Owner      = owner;
            Font       = Owner.Font;
            Flags      = flags;
            LineHeight = (int)Font.LineHeight;

            m_Paragraphs = new ParagraphList(LineHeight, BreakWidth);

            Paragraph para = new Paragraph(0, BreakWidth, String.Empty, Font, Flags);

            Paragraphs.AddLast(para);
        }
コード例 #2
0
        public void LoadTextAsync(string value, float breakWidth)
        {
            BreakWidth = breakWidth;
            if (value == null)
            {
                value = String.Empty;
            }

            Task.Factory.StartNew(() => {
                Stopwatch sw = Stopwatch.StartNew();

                int index = 0;
                Paragraphs.Clear();
                ParagraphList paragraphs = new ParagraphList(LineHeight, BreakWidth);
                char splitChar           = AutoDetectLineBreakChar(value);

                if (!GroupParagraphs)
                {
                    Strings.Split(value, splitChar).ForEach(line =>
                                                            paragraphs.AddLast(new Paragraph(index++, BreakWidth, line, Font, Flags))
                                                            );
                }
                else
                {
                    const string splitStr = "\r\n\r\n";
                    Strings.Split(value, splitStr).ForEach(line => {
                        paragraphs.AddLast(new Paragraph(index++, BreakWidth, line.Replace("\n", " ") + "\n", Font, Flags));
                        paragraphs.AddLast(new Paragraph(index++, BreakWidth, "\n", Font, Flags));
                    });
                }

                paragraphs.OnUpdate();
                Concurrency.LockFreeUpdate(ref m_Paragraphs, paragraphs);

                this.LogVerbose("{0} characters of text in {1} paragraphs loaded into the editor in {2} ms.", value.Length.ToString("n0"), Paragraphs.Count.ToString("n0"), sw.ElapsedMilliseconds.ToString("n0"));
            }).ContinueWith((t) => {
                if (t.Status == TaskStatus.RanToCompletion)
                {
                    if (Paragraphs.BreakWidth != BreakWidth)
                    {
                        Paragraphs.OnUpdateBreakWidthAsync(BreakWidth);
                    }
                }
            }).ContinueWith((t) => {
                Owner.UndoRedoManager.Clear();
                if (LoadingCompleted != null)
                {
                    LoadingCompleted(this, EventArgs.Empty);
                }
            });
        }