allow colors from referenced rulesets to be customized

This commit is contained in:
Siegfried Pammer 2012-07-24 20:06:33 +02:00
Родитель 62ae66d84a
Коммит aa30704f38
10 изменённых файлов: 101 добавлений и 7 удалений

Просмотреть файл

@ -20,7 +20,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </remarks>
public class HighlightingManager : IHighlightingDefinitionReferenceResolver
{
sealed class DelayLoadedHighlightingDefinition : IHighlightingDefinition
sealed class DelayLoadedHighlightingDefinition : IHighlightingDefinition2
{
readonly object lockObj = new object();
readonly string name;
@ -104,6 +104,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting
{
return this.Name;
}
public IDictionary<string, string> Properties {
get {
var def = GetDefinition() as IHighlightingDefinition2;
if (def != null)
return def.Properties;
return null;
}
}
}
readonly object lockObj = new object();

Просмотреть файл

@ -40,4 +40,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </summary>
IEnumerable<HighlightingColor> NamedHighlightingColors { get; }
}
/// <summary>
/// Extension of IHighlightingDefinition to avoid breaking changes in the API.
/// </summary>
public interface IHighlightingDefinition2 : IHighlightingDefinition
{
/// <summary>
/// Gets the list of properties.
/// </summary>
IDictionary<string, string> Properties { get; }
}
}

Просмотреть файл

@ -27,6 +27,8 @@
<Color name="TrueFalse" fontWeight="bold" foreground="DarkCyan" exampleText="b = false; a = true;" />
<Color name="TypeKeywords" fontWeight="bold" foreground="DarkCyan" exampleText="if (x is int) { a = x as int; type = typeof(int); size = sizeof(int); c = new object(); }"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word>

Просмотреть файл

@ -50,6 +50,13 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="Property">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="value" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
<!-- Regular expression -->
<xsd:simpleType name="regex">
<xsd:restriction base="xsd:string"/>
@ -135,6 +142,7 @@
<xsd:element name="SyntaxDefinition">
<xsd:complexType>
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element ref="Property"/>
<xsd:element ref="Color"/>
<xsd:element ref="RuleSet"/>
</xsd:choice>

Просмотреть файл

@ -18,6 +18,8 @@
<Color name="FunctionKeywords" foreground="Blue" exampleText="CInt(a)" />
<Color name="ContextKeywords" foreground="Blue" exampleText="Declare Unicode Sub SomeMethod" />
<Property name="DocCommentMarker" value="'''" />
<RuleSet ignoreCase="true">
<Span color="String">
<Begin>"</Begin>

Просмотреть файл

@ -1,9 +1,9 @@
<?xml version="1.0"?>
<SyntaxDefinition name="XmlDoc" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="XmlString" foreground="Silver" fontWeight="bold" />
<Color name="DocComment" foreground="Gray" />
<Color name="XmlPunctuation" fontWeight="bold" />
<Color name="KnownDocTags" fontWeight="bold" />
<Color name="XmlString" foreground="Silver" fontWeight="bold" exampleText="${DocCommentMarker} &lt;exception cref=&quot;System.Exception&quot; /&gt;" />
<Color name="DocComment" foreground="Gray" exampleText="${DocCommentMarker} &lt;exception cref=&quot;System.Exception&quot; /&gt;" />
<Color name="XmlPunctuation" fontWeight="bold" exampleText="${DocCommentMarker} &lt;exception cref=&quot;System.Exception&quot; /&gt;" />
<Color name="KnownDocTags" fontWeight="bold" exampleText="${DocCommentMarker} &lt;exception cref=&quot;System.Exception&quot; /&gt;" />
<RuleSet name="DocCommentSet">
<Span color="DocComment">

Просмотреть файл

@ -64,6 +64,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
case "RuleSet":
c.Add(ParseRuleSet(reader));
break;
case "Property":
c.Add(ParseProperty(reader));
break;
case "Color":
c.Add(ParseNamedColor(reader));
break;
@ -85,6 +88,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
}
}
static XshdElement ParseProperty(XmlReader reader)
{
XshdProperty property = new XshdProperty();
SetPosition(property, reader);
property.Name = reader.GetAttribute("name");
property.Value = reader.GetAttribute("value");
return property;
}
static XshdRuleSet ParseRuleSet(XmlReader reader)
{
XshdRuleSet ruleSet = new XshdRuleSet();

Просмотреть файл

@ -5,15 +5,15 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
{
[Serializable]
sealed class XmlHighlightingDefinition : IHighlightingDefinition
sealed class XmlHighlightingDefinition : IHighlightingDefinition2
{
public string Name { get; private set; }
@ -37,6 +37,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
throw new HighlightingDefinitionInvalidException("Could not find main RuleSet.");
// Translate elements within the rulesets (resolving references and processing imports)
xshd.AcceptElements(new TranslateElementVisitor(this, rnev.ruleSets, resolver));
foreach (var p in xshd.Elements.OfType<XshdProperty>())
propDict.Add(p.Name, p.Value);
}
#region RegisterNamedElements
@ -358,6 +361,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
Dictionary<string, HighlightingRuleSet> ruleSetDict = new Dictionary<string, HighlightingRuleSet>();
Dictionary<string, HighlightingColor> colorDict = new Dictionary<string, HighlightingColor>();
[OptionalField]
Dictionary<string, string> propDict = new Dictionary<string, string>();
public HighlightingRuleSet MainRuleSet { get; private set; }
@ -391,5 +396,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
{
return this.Name;
}
public IDictionary<string, string> Properties {
get {
return propDict;
}
}
}
}

Просмотреть файл

@ -0,0 +1,38 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
{
/// <summary>
/// A property in an Xshd file.
/// </summary>
[Serializable]
public class XshdProperty : XshdElement
{
/// <summary>
/// Gets/sets the name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets/sets the value.
/// </summary>
public string Value { get; set; }
/// <summary>
/// Creates a new XshdColor instance.
/// </summary>
public XshdProperty()
{
}
/// <inheritdoc/>
public override object AcceptVisitor(IXshdVisitor visitor)
{
return null;
// return visitor.VisitProperty(this);
}
}
}

Просмотреть файл

@ -212,6 +212,7 @@
<Compile Include="Highlighting\Xshd\XmlHighlightingDefinition.cs" />
<Compile Include="Highlighting\Xshd\XshdColor.cs" />
<Compile Include="Highlighting\Xshd\XshdImport.cs" />
<Compile Include="Highlighting\Xshd\XshdProperty.cs" />
<Compile Include="Highlighting\Xshd\XshdReference.cs" />
<Compile Include="Highlighting\Xshd\XshdElement.cs" />
<Compile Include="Highlighting\Xshd\XshdKeywords.cs" />