コード例 #1
0
        void GoLeftBracket(FastColoredTextBox tb, char leftBracket, char rightBracket)
        {
            FastColoredTextBoxNS.Range range = tb.Selection.Clone();//need to clone because we will move caret
            int counter       = 0;
            int maxIterations = maxBracketSearchIterations;

            while (range.GoLeftThroughFolded())//move caret left
            {
                if (range.CharAfterStart == leftBracket)
                {
                    counter++;
                }
                if (range.CharAfterStart == rightBracket)
                {
                    counter--;
                }
                if (counter == 1)
                {
                    //found
                    tb.Selection.Start = range.Start;
                    tb.DoSelectionVisible();
                    break;
                }
                //
                maxIterations--;
                if (maxIterations <= 0)
                {
                    break;
                }
            }
            tb.Invalidate();
        }
コード例 #2
0
 private void HighlightInvisibleChars(FastColoredTextBoxNS.Range range)
 {
     range.ClearStyle(invisibleCharsStyle);
     if (btInvisibleChars.Checked)
     {
         range.SetStyle(invisibleCharsStyle, @".$|.\r\n|\s");
     }
 }
コード例 #3
0
        void tb_MouseMove(object sender, MouseEventArgs e)
        {
            var tb    = sender as FastColoredTextBox;
            var place = tb.PointToPlace(e.Location);
            var r     = new FastColoredTextBoxNS.Range(tb, place, place);

            string text = r.GetFragment("[a-zA-Z]").Text;

            lbWordUnderMouse.Text = text;
        }
コード例 #4
0
        public override void Draw(Graphics gr, Point position, FastColoredTextBoxNS.Range range)
        {
            //get color name
            var parts     = range.Text.Split('.');
            var colorName = parts[parts.Length - 1];
            var color     = Color.FromName(colorName);

            (BackgroundBrush as SolidBrush).Color = color;
            base.Draw(gr, position, range);
        }
コード例 #5
0
        public override string GetTextForReplace()
        {
            //extend range
            FastColoredTextBoxNS.Range r = Parent.Fragment;
            Place end = r.End;

            r.Start = enterPlace;
            r.End   = r.End;
            //insert line break
            return(Environment.NewLine + r.Text);
        }
コード例 #6
0
ファイル: GenericColorLog.cs プロジェクト: zzattack/zektor
        protected void LogRaw(string text, TextStyle style, bool doScroll = true)
        {
            if (Window.InvokeRequired)
            {
                Window.BeginInvoke((Action <string, TextStyle, bool>)LogRaw, text, style, doScroll);
            }
            else if (!Window.IsDisposed && Window.IsHandleCreated)
            {
                // some stuffs for best performance
                Window.BeginUpdate();

                if (Window.LinesCount > MaxLineCount)
                {
                    Window.Clear();
                }
                if (Window.LinesCount > 0 && Window.Lines[Window.LinesCount - 1].Length > 800)
                {
                    Window.AppendText("\r\n");
                }

                if (doScroll)
                {
                    Window.Selection.BeginUpdate();
                }

                FastColoredTextBoxNS.Range oldSelection = null;
                //remember user selection
                if (doScroll && !IsScrolledToEnd)
                {
                    oldSelection = Window.Selection.Clone();
                }

                //add text with predefined style
                Window.AppendText(text, style);

                if (doScroll)
                {
                    if (oldSelection == null)
                    {
                        Window.GoEnd();
                    }
                    else
                    {
                        Window.Selection.Start = oldSelection.Start;
                        Window.Selection.End   = oldSelection.End;
                    }
                    Window.Selection.EndUpdate();
                }

                Window.EndUpdate();
            }
        }
コード例 #7
0
ファイル: RelForm.cs プロジェクト: CyberSys/CodeWalker
        private void SynthAssemblySyntaxHighlight(Range range)
        {
            //clear style of changed range
            range.ClearStyle(GreenStyle, OrangeRedStyle, BlueStyle, MaroonStyle);

            // comments
            range.SetStyle(GreenStyle, @";.*");
            // registers/variables/buffers
            range.SetStyle(MaroonStyle, @"(?<![a-zA-Z_0-9])[RVB][0-9]+");
            // numbers
            range.SetStyle(BlueStyle, @"(?<![a-zA-Z_0-9])[0-9]+(.[0-9]+)*");
            // inputs/outputs separator
            range.SetStyle(OrangeRedStyle, @"=>");
        }
コード例 #8
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            var desc = GetDesc(lastPlace);

            if (desc != null && !string.IsNullOrEmpty(desc.URL))
            {
                var r = new FastColoredTextBoxNS.Range(this, desc.Start, desc.End);
                r.ClearStyle(linkStyle);
                r.SetStyle(visitedLinkStyle);
                BeginInvoke(new MethodInvoker(() => Process.Start(desc.URL)));
            }

            base.OnMouseDown(e);
        }
コード例 #9
0
ファイル: MetaForm.cs プロジェクト: smallo92/CodeWalker
 private void HTMLSyntaxHighlight(Range range)
 {
     //clear style of changed range
     range.ClearStyle(BlueStyle, MaroonStyle, RedStyle);
     //tag brackets highlighting
     range.SetStyle(BlueStyle, @"<|/>|</|>");
     //tag name
     range.SetStyle(MaroonStyle, @"<(?<range>[!\w]+)");
     //end of tag
     range.SetStyle(MaroonStyle, @"</(?<range>\w+)>");
     //attributes
     range.SetStyle(RedStyle, @"(?<range>\S+?)='[^']*'|(?<range>\S+)=""[^""]*""|(?<range>\S+)=\S+");
     //attribute values
     range.SetStyle(BlueStyle, @"\S+?=(?<range>'[^']*')|\S+=(?<range>""[^""]*"")|\S+=(?<range>\S+)");
 }
コード例 #10
0
        private void HighlightVisibleRange()
        {
            //expand visible range (+- margin)
            var startLine = Math.Max(0, fctb.VisibleRange.Start.iLine - margin);
            var endLine   = Math.Min(fctb.LinesCount - 1, fctb.VisibleRange.End.iLine + margin);
            var range     = new FastColoredTextBoxNS.Range(fctb, 0, startLine, 0, endLine);

            //clear folding markers
            range.ClearFoldingMarkers();
            //set markers for folding
            range.SetFoldingMarkers(@"N\d\d00", @"N\d\d99");
            //
            range.ClearStyle(StyleIndex.All);
            range.SetStyle(fctb.SyntaxHighlighter.BlueStyle, @"N\d+");
            range.SetStyle(fctb.SyntaxHighlighter.RedStyle, @"[+\-]?[\d\.]+\d+");
        }
コード例 #11
0
ファイル: Main.cs プロジェクト: 5l1v3r1/GithubLeaker
 private void lvSearchResult_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lvSearchResult.SelectedItems.Count > 0)
     {
         var text_matches = (List <QuickType.TextMatch>)lvSearchResult.SelectedItems[0].Tag;
         tbLog.Text = "";
         foreach (var text_match in text_matches)
         {
             var startLine = tbLog.Text.Split('\n').Length;
             tbLog.AppendText(text_match.fragment + "\r\n");
             foreach (var match in text_match.matches)
             {
                 var range = new FastColoredTextBoxNS.Range(tbLog, new Place(match.indices[0], startLine - 1), new Place(match.indices[1], startLine - 1));
                 range.SetStyle(tbLog.Styles[hightLightStyleIndex]);
             }
         }
     }
 }
コード例 #12
0
 private void fctb_SelectionChangedDelayed(object sender, EventArgs e)
 {
     //here we draw shortcut for selection area
     FastColoredTextBoxNS.Range selection = fctb.Selection;
     //clear previous shortcuts
     fctb.VisibleRange.ClearStyle(shortCutStyle);
     //create shortcuts
     if (!selection.IsEmpty)//user selected one or more chars?
     {
         //find last char
         var r = selection.Clone();
         r.Normalize();
         r.Start = r.End; //go to last char
         r.GoLeft(true);  //select last char
         //apply ShortCutStyle
         r.SetStyle(shortCutStyle);
     }
 }
コード例 #13
0
 public override void Draw(Graphics gr, Point position, FastColoredTextBoxNS.Range range)
 {
     foreach (Place p in range)
     {
         int time   = (int)(DateTime.Now.TimeOfDay.TotalMilliseconds / 2);
         int angle  = (int)(time % 360L);
         int angle2 = (int)((time - (p.iChar - range.Start.iChar) * 20) % 360L) * 2;
         int x      = position.X + (p.iChar - range.Start.iChar) * range.tb.CharWidth;
         FastColoredTextBoxNS.Range r = range.tb.GetRange(p, new Place(p.iChar + 1, p.iLine));
         Point point = new Point(x, position.Y + (int)(5 + 5 * Math.Sin(Math.PI * angle2 / 180)));
         gr.ResetTransform();
         gr.TranslateTransform(point.X + range.tb.CharWidth / 2, point.Y + range.tb.CharHeight / 2);
         gr.RotateTransform(angle);
         gr.ScaleTransform(0.8f, 0.8f);
         gr.TranslateTransform(-range.tb.CharWidth / 2, -range.tb.CharHeight / 2);
         base.Draw(gr, new Point(0, 0), r);
     }
     gr.ResetTransform();
 }
コード例 #14
0
        public override void Highlight(FastColoredTextBoxNS.Range range)
        {
            range.ClearStyle(StyleIndex.All);
            if (m_DelimiterRegex != null)
            {
                range.SetStyle(BlueStyle, m_DelimiterRegex);
            }

            if (m_QuoteRegex != null)
            {
                range.SetStyle(MagentaStyle, m_QuoteRegex);
            }

            if (m_CommentRegex != null)
            {
                range.SetStyle(GrayStyle, m_CommentRegex);
            }

            range.SetStyle(m_Space, m_SpaceRegex);
            range.SetStyle(m_Tab, m_TabRegex);
        }
コード例 #15
0
            public override void Draw(Graphics gr, Point position, FastColoredTextBoxNS.Range range)
            {
                //get size of rectangle
                var size = GetSizeOfRange(range);
                var rect = new Rectangle(position, size);

                rect.Inflate(-1, -1);
                gr.FillRectangle(m_BackGround, rect);

                var sizeChar = size.Width / (range.End.iChar - range.Start.iChar);
                var height   = size.Height;

                for (var pos = range.Start.iChar; pos < range.End.iChar; pos++)
                {
                    var rect2 = new Rectangle(position, new Size(sizeChar, height));

                    // draw an arrow
                    var point2 = new Point((rect2.X + sizeChar) - 2, rect2.Y + (height / 2) - 1);

                    gr.DrawLine(m_ForeGround, new Point(rect2.X + 1, point2.Y), point2);
                    gr.DrawLine(m_ForeGround, new Point(rect2.X + (sizeChar / 2), rect2.Y + (height / 4)), point2);
                    gr.DrawLine(m_ForeGround, new Point(rect2.X + (sizeChar / 2), rect2.Y + ((rect2.Height * 3) / 4)), point2);

                    // double line in case its larger
                    if (height > 6)
                    {
                        gr.DrawLine(m_ForeGround, rect2.X + 1, point2.Y + 1, point2.X, point2.Y + 1);
                    }

                    if (sizeChar > 6)
                    {
                        gr.DrawLine(m_ForeGround, rect2.X + (sizeChar / 2) + 1, rect2.Y + (height / 4), point2.X + 1, point2.Y);
                        gr.DrawLine(m_ForeGround, rect2.X + (sizeChar / 2) + 1, rect2.Y + ((rect2.Height * 3) / 4), point2.X + 1,
                                    point2.Y);
                    }

                    position.X += sizeChar;
                }
            }
コード例 #16
0
        public override void Draw(Graphics gr, Point position, FastColoredTextBoxNS.Range range)
        {
            //create font
            IntPtr HDC        = gr.GetHdc();
            var    fontHandle = CreateFontIndirect(font);
            var    f          = SelectObject(HDC, fontHandle);

            //set foreground and background colors
            SetTextColor(HDC, ColorTranslator.ToWin32(range.tb.ForeColor));
            SetBkColor(HDC, ColorTranslator.ToWin32(range.tb.BackColor));


            //draw background
            if (BackgroundBrush != null)
            {
                gr.FillRectangle(BackgroundBrush, position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth, range.tb.CharHeight);
            }

            //coordinates
            var y  = position.Y + range.tb.LineInterval / 2;
            var x  = position.X;
            int dx = range.tb.CharWidth;

            //draw chars
            try
            {
                var s = range.Text;
                foreach (var c in s)
                {
                    TextOut(HDC, x, y, c.ToString(), 1);
                    x += dx;
                }
            }
            finally
            {
                DeleteObject(SelectObject(HDC, f));
                gr.ReleaseHdc(HDC);
            }
        }
コード例 #17
0
 private void tbFind_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == '\r' && CurrentTB != null)
     {
         FastColoredTextBoxNS.Range r = tbFindChanged?CurrentTB.Range.Clone():CurrentTB.Selection.Clone();
         tbFindChanged = false;
         r.End         = new Place(CurrentTB[CurrentTB.LinesCount - 1].Count, CurrentTB.LinesCount - 1);
         var pattern = Regex.Escape(tbFind.Text);
         foreach (var found in r.GetRanges(pattern))
         {
             found.Inverse();
             CurrentTB.Selection = found;
             CurrentTB.DoSelectionVisible();
             return;
         }
         MessageBox.Show("Not found.");
     }
     else
     {
         tbFindChanged = true;
     }
 }
コード例 #18
0
        private void ToolTipIsNeeded(object sender, ToolTipNeededEventArgs e)
        {
            if (String.IsNullOrEmpty(e.HoveredWord))
            {
                return;
            }

            var library = LibraryLookup.GetLibrary(game);

            var    range       = new FastColoredTextBoxNS.Range(sender as FastColoredTextBox, e.Place, e.Place);
            string hoveredWord = range.GetFragment("[^ ( \n \r ]").Text;

            e.ToolTipTitle = hoveredWord;

            for (int i = 0; i < library.FlowScriptModules.Count; i++)
            {
                for (int j = 0; j < library.FlowScriptModules[i].Functions.Count; j++)
                {
                    e.ToolTipText = ToolTip(hoveredWord, library) + "'";
                }
            }
        }
コード例 #19
0
            public override void Draw(Graphics gr, Point position, FastColoredTextBoxNS.Range range)
            {
                //get size of rectangle
                var size = GetSizeOfRange(range);
                var rect = new Rectangle(position, size);

                // background
                rect.Inflate(-1, -1);
                gr.FillRectangle(m_BackGround, rect);

                var sizeChar = size.Width / (range.End.iChar - range.Start.iChar);
                var dotSize  = new Size(Math.Min(Math.Max(sizeChar, 8), 3), Math.Min(Math.Max(size.Height, 8), 3));

                var posDot = new Point((position.X + (sizeChar / 2)) - (dotSize.Width / 2),
                                       (position.Y + (size.Height / 2)) - (dotSize.Height / 2));

                for (var pos = range.Start.iChar; pos < range.End.iChar; pos++)
                {
                    // draw a dot
                    gr.FillEllipse(m_ForeGround, new Rectangle(posDot, dotSize));
                    posDot.X += sizeChar;
                }
            }
コード例 #20
0
        public override void Draw(Graphics gr, Point position, FastColoredTextBoxNS.Range range)
        {
            string text  = range.Text;
            int    iChar = range.Start.iChar;

            while (text != "")
            {
                bool replaced = false;
                foreach (var pair in ImagesByText)
                {
                    if (text.StartsWith(pair.Key))
                    {
                        float k = (float)(pair.Key.Length * range.tb.CharWidth) / pair.Value.Width;
                        if (k > 1)
                        {
                            k = 1f;
                        }
                        //
                        text = text.Substring(pair.Key.Length);
                        RectangleF rect = new RectangleF(position.X + range.tb.CharWidth * pair.Key.Length / 2 - pair.Value.Width * k / 2, position.Y, pair.Value.Width * k, pair.Value.Height * k);
                        gr.DrawImage(pair.Value, rect);
                        position.Offset(range.tb.CharWidth * pair.Key.Length, 0);
                        replaced = true;
                        iChar   += pair.Key.Length;
                        break;
                    }
                }
                if (!replaced && text.Length > 0)
                {
                    FastColoredTextBoxNS.Range r = new FastColoredTextBoxNS.Range(range.tb, iChar, range.Start.iLine, iChar + 1, range.Start.iLine);
                    base.Draw(gr, position, r);
                    position.Offset(range.tb.CharWidth, 0);
                    text = text.Substring(1);
                }
            }
        }
コード例 #21
0
        private void HTMLSyntaxHighlight(Range range)
        {
            try
            {
                Style BlueStyle   = new TextStyle(Brushes.Blue, null, FontStyle.Regular);
                Style RedStyle    = new TextStyle(Brushes.Red, null, FontStyle.Regular);
                Style MaroonStyle = new TextStyle(Brushes.Maroon, null, FontStyle.Regular);

                //clear style of changed range
                range.ClearStyle(BlueStyle, MaroonStyle, RedStyle);
                //tag brackets highlighting
                range.SetStyle(BlueStyle, @"<|/>|</|>");
                //tag name
                range.SetStyle(MaroonStyle, @"<(?<range>[!\w]+)");
                //end of tag
                range.SetStyle(MaroonStyle, @"</(?<range>\w+)>");
                //attributes
                range.SetStyle(RedStyle, @"(?<range>\S+?)='[^']*'|(?<range>\S+)=""[^""]*""|(?<range>\S+)=\S+");
                //attribute values
                range.SetStyle(BlueStyle, @"\S+?=(?<range>'[^']*')|\S+=(?<range>""[^""]*"")|\S+=(?<range>\S+)");
            }
            catch
            { }
        }
コード例 #22
0
        public override void Draw(Graphics gr, Point position, FastColoredTextBoxNS.Range range)
        {
            var tb = range.tb;

            using (Brush brush = new SolidBrush(pen.Color))
                foreach (var place in range)
                {
                    switch (tb[place].c)
                    {
                    case ' ':
                        var point = tb.PlaceToPoint(place);
                        point.Offset(tb.CharWidth / 2, tb.CharHeight / 2);
                        gr.DrawLine(pen, point.X, point.Y, point.X + 1, point.Y);
                        break;
                    }

                    if (tb[place.iLine].Count - 1 == place.iChar)
                    {
                        var point = tb.PlaceToPoint(place);
                        point.Offset(tb.CharWidth, 0);
                        gr.DrawString("¶", tb.Font, brush, point);
                    }
                }
        }
コード例 #23
0
        public FCTBRangeTextReader(FastColoredTextBoxNS.Range range)
        {
            m_range = range;
            var tb = range.tb;

            /*
             * m_currentPosition = range.Start;
             * int c = range.End.iLine - range.Start.iLine + 1;
             * m_startIndices = new int[c+1];
             * int current = 0 - range.Start.iChar;
             * int iLine = m_range.Start.iLine;
             * var tb = m_range.tb;
             * for (int i = 0; i < c; i++)
             * {
             *  m_startIndices[i] = current;
             *  if (iLine < tb.LinesCount - 1)
             *  {
             *      current += range.tb[iLine++].Count + 2; // Characters + newline
             *  }
             * }
             * m_startIndices[m_startIndices.Length - 1] = Int32.MaxValue;
             */
            m_from = range.Start;
            m_to   = range.End;
            if (m_from.iLine > m_to.iLine || (m_from.iLine == m_to.iLine && m_from.iChar > m_to.iChar))
            {
                m_from = range.End;
                m_to   = range.Start;
            }

            m_size = 0;
            if (m_from.iLine >= 0)
            {
                int i       = 0;
                int current = 0 - m_from.iChar;
                m_startIndices = new int[(m_to.iLine - m_from.iLine) + 2];
                for (int y = m_from.iLine; y <= m_to.iLine; y++)
                {
                    m_startIndices[i++] = current;
                    int fX       = y == m_from.iLine ? m_from.iChar : 0;
                    int tX       = y == m_to.iLine ? Math.Min(tb[y].Count - 1, m_to.iChar - 1) : tb[y].Count - 1;
                    var lineSize = tX - fX + 1;

                    if (y != m_to.iLine && m_from.iLine != m_to.iLine)
                    {
                        lineSize += Environment.NewLine.Length;
                    }
                    m_size  += lineSize;
                    current += lineSize;
                }
                m_startIndices[i] = Int32.MaxValue;
                if (m_size != range.Length)
                {
                    throw new Exception("Error in calculation");
                }
            }
            else
            {
                m_startIndices = new int[0];
            }
        }
コード例 #24
0
ファイル: Style.cs プロジェクト: cbeach47/equella-emu
 /// <summary>
 /// Renders given range of text
 /// </summary>
 /// <param name="gr">Graphics object</param>
 /// <param name="position">Position of the range in absolute control coordinates</param>
 /// <param name="range">Rendering range of text</param>
 public abstract void Draw(Graphics gr, Point position, Range range);
コード例 #25
0
ファイル: Style.cs プロジェクト: cbeach47/equella-emu
 public static Size GetSizeOfRange(Range range)
 {
     return(new Size((range.End.iChar - range.Start.iChar) * range.tb.CharWidth, range.tb.CharHeight));
 }
コード例 #26
0
 public FCTBRangeStream(FastColoredTextBoxNS.Range range)
 {
     m_range           = range;
     m_currentPosition = range.Start;
 }
コード例 #27
0
 public TextDeletedEventArgs(Range DeleteRange)
 {
     this.DeletedRange = DeleteRange;
 }
コード例 #28
0
        private void tmrCommandTooltip_Tick(object sender, EventArgs e)
        {
            tmrCommandTooltip.Stop();

            Place place = txtCodeEditor.PointToPlace(lastMouseCoordinate);
            Point distance = txtCodeEditor.PlaceToPoint(place);

            if (Math.Abs(distance.X - lastMouseCoordinate.X) > txtCodeEditor.CharWidth * 2 |
                Math.Abs(distance.Y - lastMouseCoordinate.Y) > txtCodeEditor.CharHeight * 2)
                return;

            FastColoredTextBoxNS.Range range = new FastColoredTextBoxNS.Range(txtCodeEditor, place, place);

            string hoverWord = range.GetFragment(@"[a-zA-Z]").Text;

            if (hoverWord == "")
            {
                return;
            }

            RpgCodeExpress.RpgCode.Command foundCommand = rpgCodeReference.FindCommand(hoverWord);

            if (foundCommand != null)
            {
                Tooltip.ToolTipTitle = foundCommand.Tooltip;
                Tooltip.SetToolTip(txtCodeEditor, foundCommand.Description);
                Tooltip.Show(foundCommand.Description, txtCodeEditor, new Point(lastMouseCoordinate.X,
                        lastMouseCoordinate.Y + txtCodeEditor.CharHeight));
            }
        }
コード例 #29
0
 public RangeInfo(Range r)
 {
     Start = r.Start;
     End   = r.End;
 }
コード例 #30
0
        public string GetHtml(Range r)
        {
            tb = r.tb;
            var styles         = new Dictionary <StyleIndex, object>();
            var sb             = new StringBuilder();
            var tempSB         = new StringBuilder();
            var currentStyleId = StyleIndex.None;

            r.Normalize();
            var currentLine = r.Start.iLine;

            styles[currentStyleId] = null;
            //
            if (UseOriginalFont)
            {
                sb.AppendFormat("<font style=\"font-family: {0}, monospace; font-size: {1}pt; line-height: {2}px;\">",
                                r.tb.Font.Name, r.tb.Font.SizeInPoints, r.tb.CharHeight);
            }

            //
            if (IncludeLineNumbers)
            {
                tempSB.AppendFormat("<span class=lineNumber>{0}</span>  ", currentLine + 1);
            }
            //
            var hasNonSpace = false;

            foreach (var p in r)
            {
                var c = r.tb[p.iLine][p.iChar];
                if (c.style != currentStyleId)
                {
                    Flush(sb, tempSB, currentStyleId);
                    currentStyleId         = c.style;
                    styles[currentStyleId] = null;
                }

                if (p.iLine != currentLine)
                {
                    for (var i = currentLine; i < p.iLine; i++)
                    {
                        tempSB.Append(UseBr ? "<br>" : "\r\n");
                        if (IncludeLineNumbers)
                        {
                            tempSB.AppendFormat("<span class=lineNumber>{0}</span>  ", i + 2);
                        }
                    }
                    currentLine = p.iLine;
                    hasNonSpace = false;
                }
                switch (c.c)
                {
                case ' ':
                    if ((hasNonSpace || !UseForwardNbsp) && !UseNbsp)
                    {
                        goto default;
                    }

                    tempSB.Append("&nbsp;");
                    break;

                case '<':
                    tempSB.Append("&lt;");
                    break;

                case '>':
                    tempSB.Append("&gt;");
                    break;

                case '&':
                    tempSB.Append("&amp;");
                    break;

                default:
                    hasNonSpace = true;
                    tempSB.Append(c.c);
                    break;
                }
            }
            Flush(sb, tempSB, currentStyleId);

            if (UseOriginalFont)
            {
                sb.Append("</font>");
            }

            //build styles
            if (UseStyleTag)
            {
                tempSB.Length = 0;
                tempSB.Append("<style type=\"text/css\">");
                foreach (var styleId in styles.Keys)
                {
                    tempSB.AppendFormat(".fctb{0}{{ {1} }}\r\n", GetStyleName(styleId), GetCss(styleId));
                }
                tempSB.Append("</style>");

                sb.Insert(0, tempSB.ToString());
            }

            if (IncludeLineNumbers)
            {
                sb.Insert(0, LineNumbersCSS);
            }

            return(sb.ToString());
        }
コード例 #31
0
        public override void HighlightSyntax(Language Language, FastColoredTextBoxNS.Range ChangedRange)
        {
            if (_Parser.Settings.BASICDialect == null)
            {
                _Dialect = C64Models.BASIC.Dialect.BASICV2;
                _Parser.Settings.BASICDialect = _Dialect;
            }
            // get full lines in covered range
            int firstLine = ChangedRange.Start.iLine;
            int lastLine  = ChangedRange.End.iLine;

            if (firstLine > lastLine)
            {
                int dummy = firstLine;
                firstLine = lastLine;
                lastLine  = dummy;
            }

            for (int i = firstLine; i <= lastLine; ++i)
            {
                int lastLineNo = i;
                var line       = ChangedRange.tb.Lines[i];
                if (line.Length == 0)
                {
                    continue;
                }

                var info = _Parser.PureTokenizeLine(line);

                /*
                 * int dummyLine = -1;
                 * var info = _Parser.TokenizeLine( line, -1, ref dummyLine );*/

                var lineRange = ChangedRange.tb.GetLine(i);
                lineRange.ClearStyle(StyleIndex.All);

                bool hadREM = false;

                foreach (var token in info.Tokens)
                {
                    var subRange = new FastColoredTextBoxNS.Range(ChangedRange.tb, token.StartIndex, i, token.StartIndex + token.Content.Length, i);
                    if (hadREM)
                    {
                        subRange.SetStyle(StyleIndex.Style3);
                        continue;
                    }
                    switch (token.TokenType)
                    {
                    case Parser.BasicFileParser.Token.Type.BASIC_TOKEN:
                        subRange.SetStyle(StyleIndex.Style8);
                        if (_Parser.IsComment(token))
                        {
                            hadREM = true;
                        }
                        break;

                    case Parser.BasicFileParser.Token.Type.DIRECT_TOKEN:
                        subRange.SetStyle(StyleIndex.Style6);
                        break;

                    case Parser.BasicFileParser.Token.Type.EX_BASIC_TOKEN:
                        subRange.SetStyle(StyleIndex.Style2);
                        break;

                    case Parser.BasicFileParser.Token.Type.LINE_NUMBER:
                        subRange.SetStyle(StyleIndex.Style5);
                        break;

                    case Parser.BasicFileParser.Token.Type.NUMERIC_LITERAL:
                        subRange.SetStyle(StyleIndex.Style5);
                        break;

                    case Parser.BasicFileParser.Token.Type.STRING_LITERAL:
                        subRange.SetStyle(StyleIndex.Style4);
                        break;

                    case Parser.BasicFileParser.Token.Type.COMMENT:
                    case Parser.BasicFileParser.Token.Type.HARD_COMMENT:
                        subRange.SetStyle(StyleIndex.Style3);
                        break;

                    case Parser.BasicFileParser.Token.Type.MACRO:
                        subRange.SetStyle(StyleIndex.Style7);
                        break;

                    case Parser.BasicFileParser.Token.Type.VARIABLE:
                        subRange.SetStyle(StyleIndex.Style9);
                        break;
                    }
                }
            }
            _Parser.Clear();
        }