Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Span"/> class.
        /// </summary>
        /// <param name="span">The XML element that describes the span.</param>
        public Span(XmlElement span)
        {
            color = new HighlightColor(span);

              if (span.HasAttribute("rule"))
            rule = span.GetAttribute("rule");

              if (span.HasAttribute("escapecharacter"))
            escapeCharacter = span.GetAttribute("escapecharacter")[0];

              name = span.GetAttribute("name");
              if (span.HasAttribute("stopateol"))
            stopEOL = Boolean.Parse(span.GetAttribute("stopateol"));

              begin = span["Begin"].InnerText.ToCharArray();
              beginColor = new HighlightColor(span["Begin"], color);

              if (span["Begin"].HasAttribute("singleword"))
            isBeginSingleWord = Boolean.Parse(span["Begin"].GetAttribute("singleword"));

              if (span["Begin"].HasAttribute("startofline"))
            isBeginStartOfLine = Boolean.Parse(span["Begin"].GetAttribute("startofline"));

              if (span["End"] != null)
              {
            end = span["End"].InnerText.ToCharArray();
            endColor = new HighlightColor(span["End"], color);
            if (span["End"].HasAttribute("singleword"))
              isEndSingleWord = Boolean.Parse(span["End"].GetAttribute("singleword"));
              }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultHighlightingStrategy"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public DefaultHighlightingStrategy(string name)
        {
            _name = name;

              _digitColor = new HighlightColor(SystemColors.WindowText, false, false);
              _defaultTextColor = new HighlightColor(SystemColors.WindowText, false, false);

              Color inactiveSelectionForeground = BlendColors(SystemColors.HighlightText, SystemColors.Highlight, 0.2f);
              Color inactiveSelectionBackground = BlendColors(SystemColors.Highlight, SystemColors.Window, 0.4f);

              // set small 'default color environment'
              _environmentColors["Default"] = new HighlightBackground("WindowText", "Window", false, false);
              _environmentColors["Selection"] = new HighlightColor("HighlightText", "Highlight", false, false);
              _environmentColors["SelectionInactive"] = new HighlightColor(inactiveSelectionForeground, inactiveSelectionBackground, false, false);
              _environmentColors["VRuler"] = new HighlightColor("ControlLight", "Window", false, false);
              _environmentColors["InvalidLines"] = new HighlightColor(Color.Red, false, false);
              _environmentColors["CaretMarker"] = new HighlightColor(Color.FromArgb(0xff, 0xff, 0xcc), false, false);
              _environmentColors["CaretLine"] = new HighlightBackground("ControlLight", "Window", false, false);
              _environmentColors["LineNumbers"] = new HighlightBackground("ControlDark", "Window", false, false);
              _environmentColors["FoldLine"] = new HighlightColor("ControlDark", false, false);
              _environmentColors["FoldMarker"] = new HighlightColor("WindowText", "Window", false, false);
              _environmentColors["SelectedFoldLine"] = new HighlightColor("WindowText", false, false);
              _environmentColors["EOLMarkers"] = new HighlightColor("ControlLight", "Window", false, false);
              _environmentColors["SpaceMarkers"] = new HighlightColor("ControlLight", "Window", false, false);
              _environmentColors["TabMarkers"] = new HighlightColor("ControlLight", "Window", false, false);
        }
 /// <summary>
 /// Creates a new instance of <see cref="NextMarker"/>
 /// </summary>
 /// <param name="mark">The XML element that defines this <see cref="NextMarker"/>.</param>
 public NextMarker(XmlElement mark)
 {
   _color = new HighlightColor(mark);
   _what = mark.InnerText;
   if (mark.Attributes["markmarker"] != null)
     _markMarker = Boolean.Parse(mark.Attributes["markmarker"].InnerText);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TextWord"/> class.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="line">The line.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="color">The color.</param>
        /// <param name="hasDefaultColor">if set to <c>true</c> [has default color].</param>
        public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
        {
            Debug.Assert(document != null);
              Debug.Assert(line != null);
              Debug.Assert(color != null);

              _document = document;
              _line = line;
              _offset = offset;
              _length = length;
              _color = color;
              _hasDefaultColor = hasDefaultColor;
        }
    /// <summary>
    /// Imports the settings from another highlighting strategy.
    /// </summary>
    /// <param name="source">The source.</param>
    protected void ImportSettingsFrom(DefaultHighlightingStrategy source)
    {
      if (source == null)
        throw new ArgumentNullException("source");

      properties = source.properties;
      extensions = source.extensions;
      digitColor = source.digitColor;
      defaultRuleSet = source.defaultRuleSet;
      name = source.name;
      rules = source.rules;
      environmentColors = source.environmentColors;
      defaultTextColor = source.defaultTextColor;
    }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextWord"/> class.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="line">The line.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="color">The color.</param>
        /// <param name="hasDefaultColor">if set to <see langword="true"/> [has default color].</param>
        public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
        {
            Debug.Assert(document != null);
            Debug.Assert(line != null);
            Debug.Assert(color != null);

            _document        = document;
            _line            = line;
            _offset          = offset;
            _length          = length;
            _color           = color;
            _hasDefaultColor = hasDefaultColor;
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="TextWord"/> class.
    /// </summary>
    /// <param name="document">The document.</param>
    /// <param name="span">The <see cref="Span"/>.</param>
    /// <param name="line">The line.</param>
    /// <param name="offset">The offset.</param>
    /// <param name="length">The length.</param>
    /// <param name="color">The color.</param>
    /// <param name="hasDefaultColor">if set to <c>true</c> [has default color].</param>
    public TextWord(IDocument document, Span span, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor)
    {
      Debug.Assert(document != null);
      Debug.Assert(line != null);
      Debug.Assert(color != null);

      this.document = document;
      _span = span;
      this.line = line;
      this.offset = offset;
      this.length = length;
      this.color = color;
      this.hasDefaultColor = hasDefaultColor;
    }
        /// <summary>
        /// Imports the settings from another highlighting strategy.
        /// </summary>
        /// <param name="source">The source.</param>
        protected void ImportSettingsFrom(DefaultHighlightingStrategy source)
        {
            if (source == null)
            throw new ArgumentNullException("source");

              _properties = source._properties;
              _extensions = source._extensions;
              _digitColor = source._digitColor;
              _defaultRuleSet = source._defaultRuleSet;
              _name = source._name;
              _rules = source._rules;
              _environmentColors = source._environmentColors;
              _defaultTextColor = source._defaultTextColor;
        }
        /// <summary>
        /// Sets the color for an environment element.
        /// </summary>
        /// <param name="name">The name of the environment element.</param>
        /// <param name="color">The highlighting color.</param>
        public void SetColorFor(string name, HighlightColor color)
        {
            if (name == "Default")
            _defaultTextColor = new HighlightColor(color.Color, color.Bold, color.Italic);

              _environmentColors[name] = color;
        }
        /// <summary>
        /// pushes the curWord string on the word list, with the
        /// correct color.
        /// </summary>
        void PushCurWord(IDocument document, ref HighlightColor markNext, List<TextWord> words)
        {
            // Svante Lidman : Need to look through the next prev logic.
              if (_currentLength > 0)
              {
            if (words.Count > 0 && _activeRuleSet != null)
            {
              TextWord prevWord;
              int pInd = words.Count - 1;
              while (pInd >= 0)
              {
            if (!words[pInd].IsWhiteSpace)
            {
              prevWord = words[pInd];
              if (prevWord.HasDefaultColor)
              {
                PrevMarker marker = (PrevMarker) _activeRuleSet.PrevMarkers[document, _currentLine, _currentOffset, _currentLength];
                if (marker != null)
                {
                  prevWord.SyntaxColor = marker.Color;
                }
              }
              break;
            }
            pInd--;
              }
            }

            if (_inSpan)
            {
              HighlightColor highlightColor;
              bool hasDefaultColor = true;
              if (_activeSpan.Rule == null)
              {
            highlightColor = _activeSpan.Color;
              }
              else
              {
            highlightColor = GetColor(_activeRuleSet, document, _currentLine, _currentOffset, _currentLength);
            hasDefaultColor = false;
              }

              if (highlightColor == null)
              {
            highlightColor = _activeSpan.Color;
            if (highlightColor.Color == Color.Transparent)
              highlightColor = DefaultTextColor;

            hasDefaultColor = true;
              }
              words.Add(new TextWord(document, _currentLine, _currentOffset, _currentLength, markNext ?? highlightColor, hasDefaultColor));
            }
            else
            {
              HighlightColor c = markNext ?? GetColor(_activeRuleSet, document, _currentLine, _currentOffset, _currentLength);
              if (c == null)
            words.Add(new TextWord(document, _currentLine, _currentOffset, _currentLength, DefaultTextColor, true));
              else
            words.Add(new TextWord(document, _currentLine, _currentOffset, _currentLength, c, false));
            }

            if (_activeRuleSet != null)
            {
              NextMarker nextMarker = (NextMarker) _activeRuleSet.NextMarkers[document, _currentLine, _currentOffset, _currentLength];
              if (nextMarker != null)
              {
            if (nextMarker.MarkMarker && words.Count > 0)
            {
              TextWord prevword = words[words.Count - 1];
              prevword.SyntaxColor = nextMarker.Color;
            }
            markNext = nextMarker.Color;
              }
              else
              {
            markNext = null;
              }
            }
            _currentOffset += _currentLength;
            _currentLength = 0;
              }
        }
    /// <summary>
    /// Creates a new instance of <see cref="HighlightColor"/>
    /// </summary>
    /// <param name="el">The XML element that describes the highlighting color.</param>
    /// <param name="defaultColor">The default highlighting color.</param>
    /// <remarks>
    /// Attributes that are not explicitly set in the XML element will be inherited
    /// from <paramref name="defaultColor"/>.
    /// </remarks>
    public HighlightColor(XmlElement el, HighlightColor defaultColor)
    {
      Debug.Assert(el != null, "DigitalRune.Windows.TextEditor.Document.SyntaxColor(XmlElement el) : el == null");
      if (el.Attributes["bold"] != null)
        _bold = Boolean.Parse(el.Attributes["bold"].InnerText);
      else
        _bold = defaultColor.Bold;

      if (el.Attributes["italic"] != null)
        _italic = Boolean.Parse(el.Attributes["italic"].InnerText);
      else
        _italic = defaultColor.Italic;

      if (el.Attributes["color"] != null)
      {
        string c = el.Attributes["color"].InnerText;
        if (c[0] == '#')
        {
          _color = ParseColor(c);
        }
        else if (c.StartsWith("SystemColors."))
        {
          _color = ParseColorString(c.Substring("SystemColors.".Length));
        }
        else
        {
          _color = (Color) (Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
        }
        _hasForeground = true;
      }
      else
      {
        _color = defaultColor._color;
      }

      if (el.Attributes["bgcolor"] != null)
      {
        string c = el.Attributes["bgcolor"].InnerText;
        if (c[0] == '#')
        {
          _backgroundcolor = ParseColor(c);
        }
        else if (c.StartsWith("SystemColors."))
        {
          _backgroundcolor = ParseColorString(c.Substring("SystemColors.".Length));
        }
        else
        {
          _backgroundcolor = (Color) (Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
        }
        _hasBackground = true;
      }
      else
      {
        _backgroundcolor = defaultColor.BackgroundColor;
      }
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="TextWord.SpaceTextWord"/> class.
 /// </summary>
 /// <param name="color">The color.</param>
 public SpaceTextWord(HighlightColor color)
 {
   _length = 1;
   SyntaxColor = color;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="HighlightRuleSet"/> class.
        /// </summary>
        /// <param name="el">The XML element that describes the rule set.</param>
        public HighlightRuleSet(XmlElement el)
        {
            if (el.Attributes["name"] != null)
            Name = el.Attributes["name"].InnerText;

              if (el.HasAttribute("escapecharacter"))
            escapeCharacter = el.GetAttribute("escapecharacter")[0];

              if (el.Attributes["reference"] != null)
            reference = el.Attributes["reference"].InnerText;

              if (el.Attributes["ignorecase"] != null)
            ignoreCase = Boolean.Parse(el.Attributes["ignorecase"].InnerText);

              if (el.Attributes["highlightDigits"] != null)
            highlightDigits = Boolean.Parse(el.Attributes["highlightDigits"].InnerText);

              for (int i = 0; i < Delimiters.Length; ++i)
            delimiters[i] = false;

              if (el["Delimiters"] != null)
              {
            string delimiterString = el["Delimiters"].InnerText;
            foreach (char ch in delimiterString)
              delimiters[ch] = true;
              }

              keyWords = new LookupTable(!IgnoreCase);
              prevMarkers = new LookupTable(!IgnoreCase);
              nextMarkers = new LookupTable(!IgnoreCase);

              XmlNodeList nodes = el.GetElementsByTagName("KeyWords");
              foreach (XmlElement el2 in nodes)
              {
            HighlightColor color = new HighlightColor(el2);

            XmlNodeList keys = el2.GetElementsByTagName("Key");
            foreach (XmlElement node in keys)
            {
              keyWords[node.Attributes["word"].InnerText] = color;
            }
              }

              nodes = el.GetElementsByTagName("Span");
              foreach (XmlElement el2 in nodes)
            Spans.Add(new Span(el2));

              nodes = el.GetElementsByTagName("MarkPrevious");
              foreach (XmlElement el2 in nodes)
              {
            PrevMarker prev = new PrevMarker(el2);
            prevMarkers[prev.What] = prev;
              }

              nodes = el.GetElementsByTagName("MarkFollowing");
              foreach (XmlElement el2 in nodes)
              {
            NextMarker next = new NextMarker(el2);
            nextMarkers[next.What] = next;
              }
        }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextWord.SpaceTextWord"/> class.
 /// </summary>
 /// <param name="color">The color.</param>
 public SpaceTextWord(HighlightColor color)
 {
     _length     = 1;
     SyntaxColor = color;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="HighlightRuleSet"/> class.
        /// </summary>
        /// <param name="el">The XML element that describes the rule set.</param>
        public HighlightRuleSet(XmlElement el)
        {
            XmlNodeList nodes;

            if (el.Attributes["name"] != null)
            {
                Name = el.Attributes["name"].InnerText;
            }

            if (el.HasAttribute("escapecharacter"))
            {
                escapeCharacter = el.GetAttribute("escapecharacter")[0];
            }

            if (el.Attributes["reference"] != null)
            {
                reference = el.Attributes["reference"].InnerText;
            }

            if (el.Attributes["ignorecase"] != null)
            {
                ignoreCase = Boolean.Parse(el.Attributes["ignorecase"].InnerText);
            }

            if (el.Attributes["highlightDigits"] != null)
            {
                highlightDigits = Boolean.Parse(el.Attributes["highlightDigits"].InnerText);
            }

            for (int i = 0; i < Delimiters.Length; ++i)
            {
                delimiters[i] = false;
            }

            if (el["Delimiters"] != null)
            {
                string delimiterString = el["Delimiters"].InnerText;
                foreach (char ch in delimiterString)
                {
                    delimiters[(int)ch] = true;
                }
            }

            keyWords    = new LookupTable(!IgnoreCase);
            prevMarkers = new LookupTable(!IgnoreCase);
            nextMarkers = new LookupTable(!IgnoreCase);

            nodes = el.GetElementsByTagName("KeyWords");
            foreach (XmlElement el2 in nodes)
            {
                HighlightColor color = new HighlightColor(el2);

                XmlNodeList keys = el2.GetElementsByTagName("Key");
                foreach (XmlElement node in keys)
                {
                    keyWords[node.Attributes["word"].InnerText] = color;
                }
            }

            nodes = el.GetElementsByTagName("Span");
            foreach (XmlElement el2 in nodes)
            {
                Spans.Add(new Span(el2));
            }

            nodes = el.GetElementsByTagName("MarkPrevious");
            foreach (XmlElement el2 in nodes)
            {
                PrevMarker prev = new PrevMarker(el2);
                prevMarkers[prev.What] = prev;
            }

            nodes = el.GetElementsByTagName("MarkFollowing");
            foreach (XmlElement el2 in nodes)
            {
                NextMarker next = new NextMarker(el2);
                nextMarkers[next.What] = next;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TextWord.SpaceTextWord"/> class.
 /// </summary>
 /// <param name="color">The color.</param>
 public SpaceTextWord(HighlightColor color)
 {
   length = 1;
   base.SyntaxColor = color;
 }
    /// <summary>
    /// pushes the curWord string on the word list, with the
    /// correct color.
    /// </summary>
    void PushCurWord(IDocument document, ref HighlightColor markNext, List<TextWord> words)
    {
      // Svante Lidman : Need to look through the next prev logic.
      if (currentLength > 0)
      {
        if (words.Count > 0 && activeRuleSet != null)
        {
          TextWord prevWord = null;
          int pInd = words.Count - 1;
          while (pInd >= 0)
          {
            if (!((TextWord) words[pInd]).IsWhiteSpace)
            {
              prevWord = (TextWord) words[pInd];
              if (prevWord.HasDefaultColor)
              {
                PrevMarker marker = (PrevMarker) activeRuleSet.PrevMarkers[document, currentLine, currentOffset, currentLength];
                if (marker != null)
                {
                  prevWord.SyntaxColor = marker.Color;
                }
              }
              break;
            }
            pInd--;
          }
        }

        if (inSpan)
        {
          HighlightColor c = null;
          bool hasDefaultColor = true;
          if (activeSpan.Rule == null)
          {
            c = activeSpan.Color;
          }
          else
          {
            c = GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
            hasDefaultColor = false;
          }

          if (c == null)
          {
            c = activeSpan.Color;
            if (c.Color == Color.Transparent)
              c = this.DefaultTextColor;

            hasDefaultColor = true;
          }
          words.Add(new TextWord(document, activeSpan, currentLine, currentOffset, currentLength, markNext != null ? markNext : c, hasDefaultColor));
        }
        else
        {
          HighlightColor c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
          if (c == null)
            words.Add(new TextWord(document, activeSpan, currentLine, currentOffset, currentLength, this.DefaultTextColor, true));
          else
            words.Add(new TextWord(document, activeSpan, currentLine, currentOffset, currentLength, c, false));
        }

        if (activeRuleSet != null)
        {
          NextMarker nextMarker = (NextMarker) activeRuleSet.NextMarkers[document, currentLine, currentOffset, currentLength];
          if (nextMarker != null)
          {
            if (nextMarker.MarkMarker && words.Count > 0)
            {
              TextWord prevword = ((TextWord) words[words.Count - 1]);
              prevword.SyntaxColor = nextMarker.Color;
            }
            markNext = nextMarker.Color;
          }
          else
          {
            markNext = null;
          }
        }
        currentOffset += currentLength;
        currentLength = 0;
      }
    }
        /// <summary>
        /// Creates a new instance of <see cref="HighlightColor"/>
        /// </summary>
        /// <param name="el">The XML element that describes the highlighting color.</param>
        /// <param name="defaultColor">The default highlighting color.</param>
        /// <remarks>
        /// Attributes that are not explicitly set in the XML element will be inherited
        /// from <paramref name="defaultColor"/>.
        /// </remarks>
        public HighlightColor(XmlElement el, HighlightColor defaultColor)
        {
            Debug.Assert(el != null, "DigitalRune.Windows.TextEditor.Document.SyntaxColor(XmlElement el) : el == null");
            if (el.Attributes["bold"] != null)
            {
                bold = Boolean.Parse(el.Attributes["bold"].InnerText);
            }
            else
            {
                bold = defaultColor.Bold;
            }

            if (el.Attributes["italic"] != null)
            {
                italic = Boolean.Parse(el.Attributes["italic"].InnerText);
            }
            else
            {
                italic = defaultColor.Italic;
            }

            if (el.Attributes["color"] != null)
            {
                string c = el.Attributes["color"].InnerText;
                if (c[0] == '#')
                {
                    color = ParseColor(c);
                }
                else if (c.StartsWith("SystemColors."))
                {
                    systemColor     = true;
                    systemColorName = c.Substring("SystemColors.".Length);
                }
                else
                {
                    color = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
                }
                hasForeground = true;
            }
            else
            {
                color = defaultColor.color;
            }

            if (el.Attributes["bgcolor"] != null)
            {
                string c = el.Attributes["bgcolor"].InnerText;
                if (c[0] == '#')
                {
                    backgroundcolor = ParseColor(c);
                }
                else if (c.StartsWith("SystemColors."))
                {
                    systemBgColor     = true;
                    systemBgColorName = c.Substring("SystemColors.".Length);
                }
                else
                {
                    backgroundcolor = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]);
                }
                hasBackground = true;
            }
            else
            {
                backgroundcolor = defaultColor.BackgroundColor;
            }
        }