예제 #1
0
        private void CSharpSyntaxHighlight(TextChangedEventArgs e)
        {
            fctb.LeftBracket = '(';
            fctb.RightBracket = ')';
            fctb.LeftBracket2 = '\x0';
            fctb.RightBracket2 = '\x0';
            //clear style of changed range
            e.ChangedRange.ClearStyle(BlueStyle, BoldStyle, GrayStyle, MagentaStyle, GreenStyle, BrownStyle);

            //string highlighting
            e.ChangedRange.SetStyle(BrownStyle, @"""""|@""""|''|@"".*?""|(?<!@)(?<range>"".*?[^\\]"")|'.*?[^\\]'");
            //comment highlighting
            e.ChangedRange.SetStyle(GreenStyle, @"//.*$", RegexOptions.Multiline);
            e.ChangedRange.SetStyle(GreenStyle, @"(/\*.*?\*/)|(/\*.*)", RegexOptions.Singleline);
            e.ChangedRange.SetStyle(GreenStyle, @"(/\*.*?\*/)|(.*\*/)", RegexOptions.Singleline|RegexOptions.RightToLeft);
            //number highlighting
            e.ChangedRange.SetStyle(MagentaStyle, @"\b\d+[\.]?\d*([eE]\-?\d+)?[lLdDfF]?\b|\b0x[a-fA-F\d]+\b");
            //attribute highlighting
            e.ChangedRange.SetStyle(GrayStyle, @"^\s*(?<range>\[.+?\])\s*$", RegexOptions.Multiline);
            //class name highlighting
            e.ChangedRange.SetStyle(BoldStyle, @"\b(class|struct|enum|interface)\s+(?<range>\w+?)\b");
            //keyword highlighting
            e.ChangedRange.SetStyle(BlueStyle, @"\b(abstract|as|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|do|double|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|goto|if|implicit|in|int|interface|internal|is|lock|long|namespace|new|null|object|operator|out|override|params|private|protected|public|readonly|ref|return|sbyte|sealed|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|virtual|void|volatile|while|add|alias|ascending|descending|dynamic|from|get|global|group|into|join|let|orderby|partial|remove|select|set|value|var|where|yield)\b|#region\b|#endregion\b");

            //clear folding markers
            e.ChangedRange.ClearFoldingMarkers();

            //set folding markers
            e.ChangedRange.SetFoldingMarkers("{", "}");//allow to collapse brackets block
            e.ChangedRange.SetFoldingMarkers(@"#region\b", @"#endregion\b");//allow to collapse #region blocks
            e.ChangedRange.SetFoldingMarkers(@"/\*", @"\*/");//allow to collapse comment block
        }
 private void fctb_TextChanged(object sender, TextChangedEventArgs e)
 {
     //clear folding markers
     e.ChangedRange.ClearFoldingMarkers();
     //set markers for folding
     e.ChangedRange.SetFoldingMarkers("{", "}");
 }
예제 #3
0
        private void FastColoredTextBox1OnTextChanged(object sender, TextChangedEventArgs args)
        {
            if (lastCharIsOpenBracket)
            {
                // remember where the caret is after inserting the {
                this.hasPosition = true;
                caretPosition = this.fastColoredTextBox1.Selection.Start;
            }
            else
            {
                this.hasPosition = false;
                this.caretPosition = Place.Empty;
            }

            if (doCompletionOnEnter)
            {
                doCompletionOnEnter = false;
                var beforeInsertPos = fastColoredTextBox1.Selection.Start;

                int currentLevelIndent = this.fastColoredTextBox1.CalcAutoIndent(beforeInsertPos.iLine);
                string indent = new string(' ', currentLevelIndent);
                fastColoredTextBox1.InsertText("\n}");
                // we need to auto indent the closing bracket

                var afterInsertPos = fastColoredTextBox1.Selection.Start;
                int closeSpaces = this.fastColoredTextBox1.CalcAutoIndent(afterInsertPos.iLine);
                this.fastColoredTextBox1.InsertLinePrefix(new string(' ', closeSpaces));
                fastColoredTextBox1.Selection.Start = beforeInsertPos;
            }

            LogLine("TextChanged " + args.ChangedRange.Text);
            Console.WriteLine("TextChanged " + args.ChangedRange.Text);
        }
 private void fctb_TextChanged(object sender, TextChangedEventArgs e)
 {
     //clear previous highlighting
     e.ChangedRange.ClearStyle(brownStyle);
     //highlight tags
     e.ChangedRange.SetStyle(brownStyle, "<[^>]+>");
 }
        private void fctb_TextChangedDelayed(object sender, TextChangedEventArgs e)
        {
            //delete all markers
            fctb.Range.ClearFoldingMarkers();

            var currentIndent = 0;
            var lastNonEmptyLine = 0;

            for (int i = 0; i < fctb.LinesCount; i++)
            {
                var line = fctb.TextSource[i];
                var spacesCount = line.StartSpacesCount;
                if (spacesCount == line.Count) //empty line
                    continue;

                if (currentIndent < spacesCount)
                    //append start folding marker
                    fctb.TextSource[lastNonEmptyLine].FoldingStartMarker = "m" + currentIndent;
                else
                if (currentIndent > spacesCount)
                    //append end folding marker
                    fctb.TextSource[lastNonEmptyLine].FoldingEndMarker = "m" + spacesCount;

                currentIndent = spacesCount;
                lastNonEmptyLine = i;
            }
        }
 private void fctb_TextChanged(object sender, TextChangedEventArgs e)
 {
     //clear old styles of chars
     e.ChangedRange.ClearStyle(ellipseStyle);
     //append style for word 'Babylon'
     e.ChangedRange.SetStyle(ellipseStyle, @"\bBabylon\b", RegexOptions.IgnoreCase);
 }
 private void fctb_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (style == null) return;
     e.ChangedRange.ClearStyle(StyleIndex.All);
     foreach (var key in style.ImagesByText.Keys)
     {
         string pattern = Regex.Replace(key, RegexSpecSymbolsPattern, "\\$0");
         e.ChangedRange.SetStyle(style, pattern);
     }
 }
 private void fctb_TextChangedDelayed(object sender, TextChangedEventArgs e)
 {
     //clear styles
     fctb.Range.ClearStyle(KeywordsStyle, FunctionNameStyle);
     //highlight keywords of LISP
     fctb.Range.SetStyle(KeywordsStyle, @"\b(and|eval|else|if|lambda|or|set|defun)\b", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     //find function declarations, highlight all of their entry into the code
     foreach (Range found in RangeUtil.GetRanges(fctb, @"\b(defun|DEFUN)\s+(?<range>\w+)\b"))
         fctb.Range.SetStyle(FunctionNameStyle, @"\b" + found.Text + @"\b");
 }
        private void tb_TextChangedDelayed(object sender, TextChangedEventArgs e)
        {
            var tb = (FastColoredTextBox) sender;

            //highlight html
            tb.SyntaxHighlighter.InitStyleSchema(Language.HTML);
            tb.SyntaxHighlighter.HTMLSyntaxHighlight(tb.Range);
            //find PHP fragments
            foreach(var r in RangeUtil.GetRanges(tb, @"<\?php.*?\?>", RegexOptions.Singleline))
            {
                //remove HTML highlighting from this fragment
                r.ClearStyle(StyleIndex.All);
                //do PHP highlighting
                tb.SyntaxHighlighter.InitStyleSchema(Language.PHP);
                tb.SyntaxHighlighter.PHPSyntaxHighlight(r);
            }
        }
예제 #10
0
 private void fctb_TextChanged(object sender, TextChangedEventArgs e)
 {
     switch (lang)
     {
         case "CSharp (custom highlighter)":
             //For sample, we will highlight the syntax of C# manually, although could use built-in highlighter
             CSharpSyntaxHighlight(e);//custom highlighting
             break;
         default:
             break;//for highlighting of other languages, we using built-in FastColoredTextBox highlighter
     }
 }
예제 #11
0
 private void fctb_TextChangedDelayed(object sender, TextChangedEventArgs e)
 {
     e.ChangedRange.ClearStyle(blueStyle);
     e.ChangedRange.SetStyle(blueStyle, @"(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?");
 }
 private void fctb_TextChangedDelayed(object sender, TextChangedEventArgs e)
 {
     HighlightVisibleRange();
 }
예제 #13
0
 private void FastColoredTextBox1OnTextChangedDelayed(object sender, TextChangedEventArgs args)
 {
     LogLine("TextChangedDelayed " + args.ChangedRange.Text);
     Console.WriteLine("TextChangedDelayed " + args.ChangedRange.Text);
 }