1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections;
8
using System.Reflection;
11
using ICSharpCode.AvalonEdit.Highlighting;
12
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
13
using ICSharpCode.Core;
15
namespace ICSharpCode.AvalonEdit.AddIn
17
public class AddInTreeSyntaxMode
19
ICSharpCode.Core.AddIn addin;
22
public string Name { get; private set; }
23
public string[] Extensions { get; private set; }
25
public AddInTreeSyntaxMode(ICSharpCode.Core.AddIn addin, string resourceName, string name, string[] extensions)
28
throw new ArgumentNullException("addin");
29
if (resourceName == null)
30
throw new ArgumentNullException("resourceName");
32
throw new ArgumentNullException("name");
33
if (extensions == null)
34
throw new ArgumentNullException("extensions");
37
this.resourceName = resourceName;
39
this.Extensions = extensions;
42
public XmlReader CreateXmlReader()
44
Stream stream = addin.GetManifestResourceStream(resourceName);
46
return new XmlTextReader(stream);
48
throw new InvalidOperationException("Could not find resource '" + resourceName + "' in any of the AddIn runtime assemblies.");
52
public XshdSyntaxDefinition LoadXshd()
54
using (XmlReader reader = CreateXmlReader()) {
55
XshdSyntaxDefinition xshd = HighlightingLoader.LoadXshd(reader);
56
if (xshd.Name != this.Name)
57
throw new InvalidOperationException("Loaded XSHD has name '" + xshd.Name + "', but expected was '" + this.Name + "'.");
58
if (!Enumerable.SequenceEqual(xshd.Extensions, this.Extensions))
59
throw new InvalidOperationException("Loaded XSHD has extensions '" + string.Join(";", xshd.Extensions) + "', but expected was '" + string.Join(";", this.Extensions) + "'.");
64
public void Register(HighlightingManager manager)
66
manager.RegisterHighlighting(
67
this.Name, this.Extensions, delegate {
68
return HighlightingLoader.Load(LoadXshd(), manager);
74
/// Creates AddInTreeSyntaxMode objects that wrap a .xshd syntax mode stored as resource in the
77
/// <attribute name="name" use="required">
78
/// Name of the language for which the syntax mode is used.
80
/// <attribute name="extensions" use="required">
81
/// Semicolon-separated list of file extensions for which the syntax mode is used.
83
/// <attribute name="resource" use="required">
84
/// Fully qualified name of the resource file.
86
/// <usage>Only in /SharpDevelop/ViewContent/AvalonEdit/SyntaxModes</usage>
88
/// An AddInTreeSyntaxMode object that loads the resource from the addin assembly when
89
/// its CreateTextReader method is called.
91
public class SyntaxModeDoozer : IDoozer
93
public const string Path = "/SharpDevelop/ViewContent/AvalonEdit/SyntaxModes";
96
/// Gets if the doozer handles codon conditions on its own.
97
/// If this property return false, the item is excluded when the condition is not met.
99
public bool HandleConditions {
100
get { return false; }
103
public object BuildItem(BuildItemArgs args)
105
Codon codon = args.Codon;
106
string highlightingName = codon.Properties["name"];
107
string[] extensions = codon.Properties["extensions"].Split(';');
108
string resource = codon.Properties["resource"];
110
return new AddInTreeSyntaxMode(codon.AddIn, resource, highlightingName, extensions);