Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5582 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
22 changed files with 689 additions and 769 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,116 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <author name="Daniel Grunwald"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Reflection; |
||||||
|
using System.Xml; |
||||||
|
|
||||||
|
using ICSharpCode.AvalonEdit.Highlighting; |
||||||
|
using ICSharpCode.AvalonEdit.Highlighting.Xshd; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.AvalonEdit.AddIn |
||||||
|
{ |
||||||
|
public class AddInTreeSyntaxMode |
||||||
|
{ |
||||||
|
ICSharpCode.Core.AddIn addin; |
||||||
|
string resourceName; |
||||||
|
|
||||||
|
public string Name { get; private set; } |
||||||
|
public string[] Extensions { get; private set; } |
||||||
|
|
||||||
|
public AddInTreeSyntaxMode(ICSharpCode.Core.AddIn addin, string resourceName, string name, string[] extensions) |
||||||
|
{ |
||||||
|
if (addin == null) |
||||||
|
throw new ArgumentNullException("addin"); |
||||||
|
if (resourceName == null) |
||||||
|
throw new ArgumentNullException("resourceName"); |
||||||
|
if (name == null) |
||||||
|
throw new ArgumentNullException("name"); |
||||||
|
if (extensions == null) |
||||||
|
throw new ArgumentNullException("extensions"); |
||||||
|
|
||||||
|
this.addin = addin; |
||||||
|
this.resourceName = resourceName; |
||||||
|
this.Name = name; |
||||||
|
this.Extensions = extensions; |
||||||
|
} |
||||||
|
|
||||||
|
public XmlReader CreateXmlReader() |
||||||
|
{ |
||||||
|
Stream stream = addin.GetManifestResourceStream(resourceName); |
||||||
|
if (stream != null) { |
||||||
|
return new XmlTextReader(stream); |
||||||
|
} else { |
||||||
|
throw new InvalidOperationException("Could not find resource '" + resourceName + "' in any of the AddIn runtime assemblies."); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public XshdSyntaxDefinition LoadXshd() |
||||||
|
{ |
||||||
|
using (XmlReader reader = CreateXmlReader()) { |
||||||
|
XshdSyntaxDefinition xshd = HighlightingLoader.LoadXshd(reader); |
||||||
|
if (xshd.Name != this.Name) |
||||||
|
throw new InvalidOperationException("Loaded XSHD has name '" + xshd.Name + "', but expected was '" + this.Name + "'."); |
||||||
|
if (!Enumerable.SequenceEqual(xshd.Extensions, this.Extensions)) |
||||||
|
throw new InvalidOperationException("Loaded XSHD has extensions '" + string.Join(";", xshd.Extensions) + "', but expected was '" + string.Join(";", this.Extensions) + "'."); |
||||||
|
return xshd; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Register(HighlightingManager manager) |
||||||
|
{ |
||||||
|
manager.RegisterHighlighting( |
||||||
|
this.Name, this.Extensions, delegate { |
||||||
|
return HighlightingLoader.Load(LoadXshd(), manager); |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates AddInTreeSyntaxMode objects that wrap a .xshd syntax mode stored as resource in the
|
||||||
|
/// addin assembly.
|
||||||
|
/// </summary>
|
||||||
|
/// <attribute name="name" use="required">
|
||||||
|
/// Name of the language for which the syntax mode is used.
|
||||||
|
/// </attribute>
|
||||||
|
/// <attribute name="extensions" use="required">
|
||||||
|
/// Semicolon-separated list of file extensions for which the syntax mode is used.
|
||||||
|
/// </attribute>
|
||||||
|
/// <attribute name="resource" use="required">
|
||||||
|
/// Fully qualified name of the resource file.
|
||||||
|
/// </attribute>
|
||||||
|
/// <usage>Only in /SharpDevelop/ViewContent/AvalonEdit/SyntaxModes</usage>
|
||||||
|
/// <returns>
|
||||||
|
/// An AddInTreeSyntaxMode object that loads the resource from the addin assembly when
|
||||||
|
/// its CreateTextReader method is called.
|
||||||
|
/// </returns>
|
||||||
|
public class SyntaxModeDoozer : IDoozer |
||||||
|
{ |
||||||
|
public const string Path = "/SharpDevelop/ViewContent/AvalonEdit/SyntaxModes"; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets if the doozer handles codon conditions on its own.
|
||||||
|
/// If this property return false, the item is excluded when the condition is not met.
|
||||||
|
/// </summary>
|
||||||
|
public bool HandleConditions { |
||||||
|
get { return false; } |
||||||
|
} |
||||||
|
|
||||||
|
public object BuildItem(object caller, Codon codon, ArrayList subItems) |
||||||
|
{ |
||||||
|
string highlightingName = codon.Properties["name"]; |
||||||
|
string[] extensions = codon.Properties["extensions"].Split(';'); |
||||||
|
string resource = codon.Properties["resource"]; |
||||||
|
|
||||||
|
return new AddInTreeSyntaxMode(codon.AddIn, resource, highlightingName, extensions); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,49 +0,0 @@ |
|||||||
// <file>
|
|
||||||
// <copyright see="prj:///doc/copyright.txt"/>
|
|
||||||
// <license see="prj:///doc/license.txt"/>
|
|
||||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
|
||||||
// <version>$Revision$</version>
|
|
||||||
// </file>
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Diagnostics; |
|
||||||
using System.Xml; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.TextEditor.Document; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Codons |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Description of AddInTreeSyntaxModeProvider.
|
|
||||||
/// </summary>
|
|
||||||
public class AddInTreeSyntaxModeProvider : ISyntaxModeFileProvider |
|
||||||
{ |
|
||||||
const string syntaxModePath = "/SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes"; |
|
||||||
|
|
||||||
List<SyntaxMode> syntaxModes; |
|
||||||
|
|
||||||
public ICollection<SyntaxMode> SyntaxModes { |
|
||||||
get { |
|
||||||
return syntaxModes; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public AddInTreeSyntaxModeProvider() |
|
||||||
{ |
|
||||||
syntaxModes = AddInTree.BuildItems<SyntaxMode>(syntaxModePath, this, false); |
|
||||||
} |
|
||||||
|
|
||||||
public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode) |
|
||||||
{ |
|
||||||
Debug.Assert(syntaxMode is AddInTreeSyntaxMode); |
|
||||||
return ((AddInTreeSyntaxMode)syntaxMode).CreateTextReader(); |
|
||||||
} |
|
||||||
|
|
||||||
public void UpdateSyntaxModeList() |
|
||||||
{ |
|
||||||
// addintree doesn't change during runtime
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,112 +0,0 @@ |
|||||||
// <file>
|
|
||||||
// <copyright see="prj:///doc/copyright.txt"/>
|
|
||||||
// <license see="prj:///doc/license.txt"/>
|
|
||||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
|
||||||
// <version>$Revision$</version>
|
|
||||||
// </file>
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Collections; |
|
||||||
using System.IO; |
|
||||||
using System.Reflection; |
|
||||||
using System.Xml; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using ICSharpCode.SharpDevelop.Editor; |
|
||||||
using ICSharpCode.TextEditor.Document; |
|
||||||
using AvalonEdit = ICSharpCode.AvalonEdit; |
|
||||||
using ICSharpCode.AvalonEdit.Highlighting; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.DefaultEditor.Codons |
|
||||||
{ |
|
||||||
public class AddInTreeSyntaxMode : SyntaxMode |
|
||||||
{ |
|
||||||
Runtime[] runtimes; |
|
||||||
|
|
||||||
public AddInTreeSyntaxMode(Runtime[] runtimes, string fileName, string name, string[] extensions) : base(fileName, name, extensions) |
|
||||||
{ |
|
||||||
this.runtimes = runtimes; |
|
||||||
} |
|
||||||
|
|
||||||
public XmlTextReader CreateTextReader() |
|
||||||
{ |
|
||||||
foreach (Runtime runtime in runtimes) { |
|
||||||
Assembly assembly = runtime.LoadedAssembly; |
|
||||||
if (assembly != null) { |
|
||||||
Stream stream = assembly.GetManifestResourceStream(FileName); |
|
||||||
if (stream != null) { |
|
||||||
return new XmlTextReader(stream); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates AddInTreeSyntaxMode objects that wrap a .xshd syntax mode stored as resource in the
|
|
||||||
/// addin assembly.
|
|
||||||
/// </summary>
|
|
||||||
/// <attribute name="name" use="required">
|
|
||||||
/// Name of the language for which the syntax mode is used.
|
|
||||||
/// </attribute>
|
|
||||||
/// <attribute name="extensions" use="required">
|
|
||||||
/// Semicolon-separated list of file extensions for which the syntax mode is used.
|
|
||||||
/// </attribute>
|
|
||||||
/// <attribute name="resource" use="required">
|
|
||||||
/// Fully qualified name of the resource file.
|
|
||||||
/// </attribute>
|
|
||||||
/// <usage>Only in /SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes</usage>
|
|
||||||
/// <returns>
|
|
||||||
/// An AddInTreeSyntaxMode object that loads the resource from the addin assembly when
|
|
||||||
/// its CreateTextReader method is called.
|
|
||||||
/// </returns>
|
|
||||||
public class SyntaxModeDoozer : IDoozer |
|
||||||
{ |
|
||||||
AvalonEdit.Highlighting.HighlightingManager highlightingManager; |
|
||||||
|
|
||||||
public SyntaxModeDoozer(AvalonEdit.Highlighting.HighlightingManager highlightingManager) |
|
||||||
{ |
|
||||||
this.highlightingManager = highlightingManager; |
|
||||||
} |
|
||||||
|
|
||||||
public SyntaxModeDoozer() |
|
||||||
: this(AvalonEdit.Highlighting.HighlightingManager.Instance) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets if the doozer handles codon conditions on its own.
|
|
||||||
/// If this property return false, the item is excluded when the condition is not met.
|
|
||||||
/// </summary>
|
|
||||||
public bool HandleConditions { |
|
||||||
get { return false; } |
|
||||||
} |
|
||||||
|
|
||||||
public object BuildItem(object caller, Codon codon, ArrayList subItems) |
|
||||||
{ |
|
||||||
string highlightingName = codon.Properties["name"]; |
|
||||||
string[] extensions = codon.Properties["extensions"].Split(';'); |
|
||||||
string resource = codon.Properties["resource"]; |
|
||||||
|
|
||||||
Runtime[] assemblies = new Runtime[codon.AddIn.Runtimes.Count]; |
|
||||||
int i = 0; |
|
||||||
foreach (Runtime library in codon.AddIn.Runtimes) { |
|
||||||
assemblies[i++] = library; |
|
||||||
} |
|
||||||
|
|
||||||
highlightingManager.RegisterHighlighting(highlightingName, extensions, LoadHighlighting(assemblies, resource)); |
|
||||||
|
|
||||||
return new AddInTreeSyntaxMode(assemblies, resource, highlightingName, extensions); |
|
||||||
} |
|
||||||
|
|
||||||
Func<IHighlightingDefinition> LoadHighlighting(Runtime[] runtimes, string resourceName) |
|
||||||
{ |
|
||||||
Func<IHighlightingDefinition> func = delegate { |
|
||||||
AddInHighlightingResource highlightingResource = new AddInHighlightingResource(runtimes); |
|
||||||
return highlightingResource.LoadHighlighting(resourceName, highlightingManager); |
|
||||||
}; |
|
||||||
return func; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue