Exemple #1
0
        private void TextChange(FastColoredTextBox textBox, 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(textBox, e);    //custom highlighting
                break;

            default:
                break;    //for highlighting of other languages, we using built-in FastColoredTextBox highlighter
            }

            if (textBox.Text.Trim().StartsWith("<?xml"))
            {
                textBox.Language = Language.XML;

                textBox.ClearStylesBuffer();
                textBox.Range.ClearStyle(StyleIndex.All);
                InitStylesPriority(textBox);
                textBox.AutoIndentNeeded -= fastRichTextBoxQuery_AutoIndentNeeded;

                textBox.OnSyntaxHighlight(new TextChangedEventArgs(textBox.Range));
            }
        }
Exemple #2
0
        public static void SetFormattedMessage(string language, FastColoredTextBox textBox)
        {
            if (string.IsNullOrEmpty(language))
            {
                throw new ArgumentNullException(nameof(language), $"{nameof(language)} parameter cannot be null");
            }

            if (textBox == null)
            {
                throw new ArgumentNullException(nameof(textBox), $"{nameof(textBox)} parameter cannot be null");
            }

            textBox.ClearStylesBuffer();
            textBox.Range.ClearStyle(StyleIndex.All);

            switch (language)
            {
            case "JSON":
                textBox.Language = Language.JSON;
                break;

            case "XML":
                textBox.Language = Language.HTML;
                break;

            default:
                textBox.Language = Language.Custom;
                break;
            }
            textBox.OnTextChanged();
        }
Exemple #3
0
        private void UPDFNDText(string result, string ext)
        {
            Invoke((MethodInvoker) delegate
            {
                _tb.Text = result;
                _tb.ClearStylesBuffer();
                _tb.Range.ClearStyle(StyleIndex.All);
                _tb.Language = Language.CSharp;
                switch (ext)
                {
                case ".vb": _tb.Language = Language.VB; break;

                case ".hml": _tb.Language = Language.HTML; break;

                case ".xml": _tb.Language = Language.XML; break;

                case ".sql": _tb.Language = Language.SQL; break;

                case ".php": _tb.Language = Language.PHP; break;

                case ".js": _tb.Language = Language.JS; break;

                case ".lua": _tb.Language = Language.Lua; break;
                }
                _tb.OnSyntaxHighlight(new TextChangedEventArgs(_tb.Range));
            });
        }
Exemple #4
0
        public void clearHighlights(object sender, TextChangedEventArgs e)
        {
            codeTextBox.ClearStylesBuffer();
            //codeTextBox.Range.ClearStyle(StyleIndex.All);

            syntaxHighlights(e, this.codeTextBox);
            codeTextBox.AutoIndentNeeded -= fctb_AutoIndentNeeded;

            codeTextBox.Language          = Language.Custom;
            codeTextBox.CommentPrefix     = "//";
            codeTextBox.AutoIndentNeeded += fctb_AutoIndentNeeded;
            //call OnTextChanged for refresh syntax highlighting
            codeTextBox.OnTextChanged();
        }
Exemple #5
0
        private void InitStyles()
        {
            var commentStyle = new TextStyle(Brushes.Green, null, FontStyle.Italic);
            var keywordStyle = new TextStyle(Brushes.Blue, null, FontStyle.Bold);
            var literalStyle = new TextStyle(Brushes.DarkRed, null, FontStyle.Regular);

            TokenStyles[TokenColor.Comment]    = commentStyle;
            TokenStyles[TokenColor.Identifier] = DefaultTokenStyle;
            TokenStyles[TokenColor.Keyword]    = keywordStyle;
            TokenStyles[TokenColor.Number]     = literalStyle;
            TokenStyles[TokenColor.String]     = literalStyle;
            TokenStyles[TokenColor.Text]       = DefaultTokenStyle;

            TextBox.ClearStylesBuffer();
            TextBox.AddStyle(DefaultTokenStyle);
            TextBox.AddStyle(ErrorTokenStyle);
            TextBox.AddStyle(commentStyle);
            TextBox.AddStyle(keywordStyle);
            TextBox.AddStyle(literalStyle);
            TextBox.BracketsStyle  = new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Blue)));
            TextBox.BracketsStyle2 = new MarkerStyle(new SolidBrush(Color.FromArgb(70, Color.Green)));
        }
        public void InitStyles(ColorSettings settings)
        {
            TokenStyles.Clear();
            TokenStyles[TokenColor.Comment]    = settings.Comment ?? settings.Default;
            TokenStyles[TokenColor.Identifier] = settings.Identifier ?? settings.Default;
            TokenStyles[TokenColor.Keyword]    = settings.Keyword ?? settings.Default;
            TokenStyles[TokenColor.Number]     = settings.Number ?? settings.Default;
            TokenStyles[TokenColor.String]     = settings.String ?? settings.Default;
            TokenStyles[TokenColor.Text]       = settings.Text ?? settings.Default;

            TextBox.ClearStylesBuffer();
            TextBox.AddStyle(DefaultTokenStyle);
            TextBox.AddStyle(ErrorTokenStyle);

            foreach (var style in TokenStyles.Values)
            {
                TextBox.AddStyle(style);
            }

            TextBox.BracketsStyle  = new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Blue)));
            TextBox.BracketsStyle2 = new MarkerStyle(new SolidBrush(Color.FromArgb(70, Color.Green)));
        }
Exemple #7
0
 public void RefreshGlobalStyles()
 {
     foreach (FastColoredTextBox tb in AllTextBoxes)
     {
         tb.Font           = TextStyles.Font;
         tb.SelectionColor = TextStyles.SelectionColor;
         tb.BackColor      = TextStyles.BackColor;
         tb.ForeColor      = TextStyles.ForeColor;
     }
     foreach (EditorGUI editor in Editors)
     {
         editor.RefreshGlobalStyles();
     }
     if (Editors.Count == 0)
     {
         docBox.ClearStylesBuffer();
     }
     else
     {
         Editors.Last().RefreshGlobalStyles(docBox);
     }
 }
Exemple #8
0
        public void Load_setting()
        {
            StreamReader reader = new StreamReader("init\\setting.txt");
            string       line;

            string[]   split;
            SolidBrush brush;

            line = reader.ReadLine();
            while (line != null)
            {
                fctb.ClearStylesBuffer();
                split = line.Split('=');
                split[0].Replace(" ", "");
                split[1].Replace(" ", "");

                if (split[0] == "comment_style")
                {
                    split         = split[1].Split(';');
                    brush         = new SolidBrush(Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2])));
                    comment_style = new TextStyle(brush, null, FontStyle.Regular);
                }
                else if (split[0] == "drawing_style")
                {
                    split         = split[1].Split(';');
                    brush         = new SolidBrush(Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2])));
                    drawing_style = new TextStyle(brush, null, FontStyle.Regular);
                }
                else if (split[0] == "scad_style")
                {
                    split      = split[1].Split(';');
                    brush      = new SolidBrush(Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2])));
                    scad_style = new TextStyle(brush, null, FontStyle.Regular);
                }
                else if (split[0] == "variable_style")
                {
                    split          = split[1].Split(';');
                    brush          = new SolidBrush(Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2])));
                    variable_style = new TextStyle(brush, null, FontStyle.Regular);
                }
                else if (split[0] == "BackColor")
                {
                    split          = split[1].Split(';');
                    fctb.BackColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "BookmarkColor")
                {
                    split = split[1].Split(';');
                    fctb.BookmarkColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "CaretColor")
                {
                    split           = split[1].Split(';');
                    fctb.CaretColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "ChangedLineColor")
                {
                    split = split[1].Split(';');
                    fctb.ChangedLineColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "CurrentLineColor")
                {
                    split = split[1].Split(';');
                    fctb.CurrentLineColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "DisabledColor")
                {
                    split = split[1].Split(';');
                    fctb.DisabledColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "FoldingIndicatorColor")
                {
                    split = split[1].Split(';');
                    fctb.FoldingIndicatorColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "ForeColor")
                {
                    split          = split[1].Split(';');
                    fctb.ForeColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "IndentBackColor")
                {
                    split = split[1].Split(';');
                    fctb.IndentBackColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "LineNumberColor")
                {
                    split = split[1].Split(';');
                    fctb.LineNumberColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "PaddingBackColor")
                {
                    split = split[1].Split(';');
                    fctb.PaddingBackColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "SelectionColor")
                {
                    split = split[1].Split(';');
                    fctb.SelectionColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "ServiceLinesColor")
                {
                    split = split[1].Split(';');
                    fctb.ServiceLinesColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "TextAreaBorderColor")
                {
                    split = split[1].Split(';');
                    fctb.TextAreaBorderColor = Color.FromArgb(Convert.ToInt16(split[0]), Convert.ToInt16(split[1]), Convert.ToInt16(split[2]));
                }
                else if (split[0] == "scad_filename")
                {
                    scad_filename = split[1];
                }
                line = reader.ReadLine();
            }
            reader.Close();
            Refresh();
        }