Ejemplo n.º 1
0
        // perform syntax coloring
        void UpdateSyntaxColoring(C1TextRange range)
        {
            // remove old coloring
            _rangeStyles.RemoveRange(range);

            var input = range.Text;

            // highlight the matches
            foreach (Match m in Regex.Matches(input, tagPattern))
            {
                // select whole tag, make it dark blue
                _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, m), brDarkBlue));

                // select tag name, make it dark red
                var tagName = m.Groups["tagName"];
                _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, tagName), brDarkRed));

                // select attribute names, make them light red
                var attGroup = m.Groups["attName"];
                if (attGroup != null)
                {
                    var atts = attGroup.Captures;
                    for (int i = 0; i < atts.Count; i++)
                    {
                        var att = atts[i];
                        _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, att), brLightRed));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void FindText()
        {
            bool textFound = true;
            do
            {
                int index = rtb.FindText(txtFindText.Text);
                if (index < 0 || _listStart.Contains(index))
                    textFound = false;
                else
                {
                    _listStart.Add(index);
                    _rangeStyles.Add(new C1RangeStyle(rtb.Selection, _highlightStyle));
                }
            } while (textFound);

            if (_listStart.Count > 0)
            {
                rtb.StyleOverrides.Add(_rangeStyles);
                tbxReplaceText.IsEnabled = true;
                btnReplace.IsEnabled = true;
                btnReplaceAll.IsEnabled = true;
                if (_listStart.Count > 1)
                {
                    btnPrevious.IsEnabled = true;
                    btnNext.IsEnabled = true;
                }
            }
        }
        // perform syntax coloring
        void UpdateSyntaxColoring()
        {
            C1TextRange range = c1RichTextBox1.Document.ContentRange;

            // reset coloring
            _rangeStyles = new C1RangeStyleCollection();
            c1RichTextBox1.StyleOverrides.Clear();
            c1RichTextBox1.StyleOverrides.Add(_rangeStyles);

            var input = range.Text;

            if (Mode == SyntaxMode.Xaml)
            {
                // highlight the matches
                foreach (Match m in Regex.Matches(input, tagPattern))
                {
                    // select whole tag, make it dark blue
                    _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, m), brDarkBlue));

                    // select tag name, make it dark red
                    var tagName = m.Groups["tagName"];
                    _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, tagName), brDarkRed));

                    // select attribute names, make them light red
                    var attGroup = m.Groups["attName"];
                    if (attGroup != null)
                    {
                        var atts = attGroup.Captures;
                        for (int i = 0; i < atts.Count; i++)
                        {
                            var att = atts[i];
                            _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, att), brLightRed));
                        }
                    }
                }
            }
            else if (Mode == SyntaxMode.CSharp)
            {
                // highlight reserved words first
                foreach (string keyword in reservedWords)
                {
                    foreach (Match m in Regex.Matches(input, keyword + " "))
                    {
                        // select reserved word, make it blue
                        _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, m), brBlue));
                    }
                }

                // highlight strings
                foreach (Match m in Regex.Matches(input, stringPattern))
                {
                    // select string, make it red
                    _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, m), brDarkRed));
                }

                // highlight comments
                foreach (Match m in Regex.Matches(input, commentPattern))
                {
                    // select comment, make it green
                    _rangeStyles.Add(new C1RangeStyle(GetRangeAtTextOffset(range.Start, m), brGreen));
                }
            }
        }