Browse Source

Highlighting editor: allow editing colors of highlighting definitions defined in AddIns.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5582 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
b5f9f09c40
  1. 1
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 2
      src/AddIns/BackendBindings/FSharpBinding/FSharpBinding.addin
  3. 2
      src/AddIns/BackendBindings/FSharpBinding/Resources/FS-Mode.xshd
  4. 2
      src/AddIns/BackendBindings/ILAsmBinding/Project/ILAsmBinding.addin
  5. 1051
      src/AddIns/BackendBindings/ILAsmBinding/Project/Resources/ILAsm-Mode.xshd
  6. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin
  7. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs
  8. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ConvertToPythonProjectCommandTestFixture.cs
  9. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs
  10. 8
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonSyntaxModeTestFixture.cs
  11. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/AddInHelper.cs
  12. 2
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.addin
  13. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin
  14. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  15. 26
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditDisplayBinding.cs
  16. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  17. 23
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  18. 116
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxModeDoozer.cs
  19. 2
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  20. 49
      src/Main/Base/Project/Src/TextEditor/Codons/AddInTreeSyntaxModeProvider.cs
  21. 112
      src/Main/Base/Project/Src/TextEditor/Codons/SyntaxModeDoozer.cs
  22. 3
      src/Main/Base/Test/Highlighting/SyntaxDoozerAddsHighlightingToHighlightingManagerTestFixture.cs

1
AddIns/ICSharpCode.SharpDevelop.addin

@ -41,7 +41,6 @@ @@ -41,7 +41,6 @@
<Doozer name="LanguageBinding" class="ICSharpCode.SharpDevelop.LanguageBindingDoozer"/>
<Doozer name="Parser" class="ICSharpCode.SharpDevelop.ParserDoozer"/>
<Doozer name="ProjectContentRegistry" class="ICSharpCode.SharpDevelop.ProjectContentRegistryDoozer"/>
<Doozer name="SyntaxMode" class="ICSharpCode.SharpDevelop.DefaultEditor.Codons.SyntaxModeDoozer"/>
<Doozer name="BrowserSchemeExtension" class="ICSharpCode.SharpDevelop.BrowserDisplayBinding.SchemeExtensionDoozer"/>
<Doozer name="CodeCompletionBinding" class="ICSharpCode.SharpDevelop.Editor.CodeCompletion.CodeCompletionBindingDoozer"/>
<Doozer name="Debugger" class="ICSharpCode.SharpDevelop.Debugging.DebuggerDoozer"/>

2
src/AddIns/BackendBindings/FSharpBinding/FSharpBinding.addin

@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
class = "FSharpBindings.FSharpAmbience"/>
</Path>
<Path name = "/SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes">
<Path name = "/SharpDevelop/ViewContent/AvalonEdit/SyntaxModes">
<SyntaxMode id = "F# Syntax Mode"
name = "F#"
extensions = ".fs;.fsi"

2
src/AddIns/BackendBindings/FSharpBinding/Resources/FS-Mode.xshd

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- syntaxdefinition for F# 2000 by Robert Pickering -->
<SyntaxDefinition name = "F#" extensions = ".fs">
<SyntaxDefinition name = "F#" extensions = ".fs;.fsi">
<Properties>
<Property name="LineComment" value="//"/>

2
src/AddIns/BackendBindings/ILAsmBinding/Project/ILAsmBinding.addin

@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
<Directory id = "ILAsm" path = "./Templates" />
</Path>
<Path name = "/SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes">
<Path name = "/SharpDevelop/ViewContent/AvalonEdit/SyntaxModes">
<SyntaxMode id = "IL Syntax Mode"
name = "ILAsm"
extensions = ".il"

1051
src/AddIns/BackendBindings/ILAsmBinding/Project/Resources/ILAsm-Mode.xshd

File diff suppressed because it is too large Load Diff

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
<Import assembly="PythonBinding.dll"/>
</Runtime>
<Path name="/SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes">
<Path name="/SharpDevelop/ViewContent/AvalonEdit/SyntaxModes">
<SyntaxMode id="Python.SyntaxMode"
extensions=".py"
name="Python"

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs

@ -11,7 +11,6 @@ using System.IO; @@ -11,7 +11,6 @@ using System.IO;
using System.Reflection;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
using ICSharpCode.TextEditor.Document;
using NUnit.Framework;
using PythonBinding.Tests.Utils;

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ConvertToPythonProjectCommandTestFixture.cs

@ -13,7 +13,6 @@ using ICSharpCode.Core; @@ -13,7 +13,6 @@ using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
using ICSharpCode.SharpDevelop.Project;
using NUnit.Framework;
using PythonBinding.Tests.Utils;

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs

@ -14,7 +14,6 @@ using ICSharpCode.Core; @@ -14,7 +14,6 @@ using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
using ICSharpCode.SharpDevelop.Project;
using NUnit.Framework;
using PythonBinding.Tests.Utils;

8
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonSyntaxModeTestFixture.cs

@ -12,8 +12,8 @@ using System.IO; @@ -12,8 +12,8 @@ using System.IO;
using System.Reflection;
using System.Xml;
using ICSharpCode.AvalonEdit.AddIn;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
using ICSharpCode.TextEditor.Document;
using NUnit.Framework;
@ -34,7 +34,7 @@ namespace PythonBinding.Tests @@ -34,7 +34,7 @@ namespace PythonBinding.Tests
Span stringSpan;
Span charSpan;
Span docCommentSpan;
const string SyntaxModePath = "/SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes";
const string SyntaxModePath = SyntaxModeDoozer.Path;
XmlElement importsKeyWordsElement;
XmlElement iterationStatementsKeyWordsElement;
XmlElement jumpStatementsKeyWordsElement;
@ -92,7 +92,7 @@ namespace PythonBinding.Tests @@ -92,7 +92,7 @@ namespace PythonBinding.Tests
if (syntaxModeCodon != null) {
SyntaxModeDoozer doozer = new SyntaxModeDoozer();
AddInTreeSyntaxMode syntaxMode = (AddInTreeSyntaxMode)doozer.BuildItem(null, syntaxModeCodon, null);
highlightingStrategy = HighlightingDefinitionParser.Parse(syntaxMode, syntaxMode.CreateTextReader());
highlightingStrategy = HighlightingDefinitionParser.Parse(new SyntaxMode(null, syntaxMode.Name, syntaxMode.Extensions), syntaxMode.CreateXmlReader());
// Load Python syntax file into XML document since
// we cannot get all the information stored in this
@ -101,7 +101,7 @@ namespace PythonBinding.Tests @@ -101,7 +101,7 @@ namespace PythonBinding.Tests
// LookupTable does not have a getter which is easy
// to use.
syntaxModeDocument = new XmlDocument();
syntaxModeDocument.Load(syntaxMode.CreateTextReader());
syntaxModeDocument.Load(syntaxMode.CreateXmlReader());
// Get default ruleset.
foreach (HighlightRuleSet ruleSet in highlightingStrategy.Rules) {

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/AddInHelper.cs

@ -9,7 +9,6 @@ using System; @@ -9,7 +9,6 @@ using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
namespace PythonBinding.Tests.Utils
{

2
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/RubyBinding.addin

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
<Import assembly="RubyBinding.dll"/>
</Runtime>
<Path name="/SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes">
<Path name="/SharpDevelop/ViewContent/AvalonEdit/SyntaxModes">
<SyntaxMode id="Ruby.SyntaxMode"
extensions=".rb"
name="Ruby"

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin

@ -9,7 +9,9 @@ @@ -9,7 +9,9 @@
<Runtime>
<Import assembly = ":ICSharpCode.AvalonEdit"/>
<Import assembly = "ICSharpCode.AvalonEdit.AddIn.dll"/>
<Import assembly = "ICSharpCode.AvalonEdit.AddIn.dll">
<Doozer name="SyntaxMode" class="ICSharpCode.AvalonEdit.AddIn.SyntaxModeDoozer"/>
</Import>
</Runtime>
<Path name = "/SharpDevelop/Workbench/DisplayBindings">

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -135,6 +135,7 @@ @@ -135,6 +135,7 @@
<Compile Include="Src\SharpDevelopCompletionWindow.cs" />
<Compile Include="Src\SharpDevelopInsightWindow.cs">
</Compile>
<Compile Include="Src\SyntaxModeDoozer.cs" />
<Compile Include="Src\TextMarkerService.cs" />
<EmbeddedResource Include="Resources\IncrementalSearchCursor.cur" />
<EmbeddedResource Include="Resources\ReverseIncrementalSearchCursor.cur" />

26
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditDisplayBinding.cs

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
@ -15,8 +15,18 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -15,8 +15,18 @@ namespace ICSharpCode.AvalonEdit.AddIn
{
public class AvalonEditDisplayBinding : IDisplayBinding
{
const string path = "/SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes";
bool builtAddInHighlighting;
static bool addInHighlightingDefinitionsRegistered;
internal static void RegisterAddInHighlightingDefinitions()
{
WorkbenchSingleton.AssertMainThread();
if (!addInHighlightingDefinitionsRegistered) {
foreach (AddInTreeSyntaxMode syntaxMode in AddInTree.BuildItems<AddInTreeSyntaxMode>(SyntaxModeDoozer.Path, null, false)) {
syntaxMode.Register(HighlightingManager.Instance);
}
addInHighlightingDefinitionsRegistered = true;
}
}
public bool CanCreateContentForFile(string fileName)
{
@ -25,16 +35,8 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -25,16 +35,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
public IViewContent CreateContentForFile(OpenedFile file)
{
BuildAddInHighlighting();
RegisterAddInHighlightingDefinitions();
return new AvalonEditViewContent(file);
}
void BuildAddInHighlighting()
{
if (!builtAddInHighlighting) {
builtAddInHighlighting = true;
AddInTree.BuildItems<object>(path, this, false);
}
}
}
}

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -45,6 +45,8 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -45,6 +45,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
public CodeEditorView()
{
AvalonEditDisplayBinding.RegisterAddInHighlightingDefinitions();
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, OnHelpExecuted));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Print, OnPrint));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.PrintPreview, OnPrintPreview));

23
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs

@ -26,6 +26,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -26,6 +26,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{
public HighlightingOptions()
{
// ensure all definitions from AddIns are registered so that they are available for the example view
AvalonEditDisplayBinding.RegisterAddInHighlightingDefinitions();
InitializeComponent();
textEditor.Document.UndoStack.SizeLimit = 0;
textEditor.Options = CodeEditorOptions.Instance;
@ -50,16 +53,18 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -50,16 +53,18 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
base.LoadOptions();
if (allSyntaxDefinitions == null) {
allSyntaxDefinitions = (
from name in typeof(HighlightingManager).Assembly.GetManifestResourceNames()
from name in typeof(HighlightingManager).Assembly.GetManifestResourceNames().AsParallel()
where name.StartsWith(typeof(HighlightingManager).Namespace + ".Resources.", StringComparison.OrdinalIgnoreCase)
&& name.EndsWith(".xshd", StringComparison.OrdinalIgnoreCase)
&& !name.EndsWith("XmlDoc.xshd", StringComparison.OrdinalIgnoreCase)
let def = LoadBuiltinXshd(name)
where def.Elements.OfType<XshdColor>().Any(c => c.ExampleText != null)
orderby def.Name
select def
).ToList();
// TODO: also find syntax definitions defined in addins
select LoadBuiltinXshd(name)
).Concat(
ICSharpCode.Core.AddInTree.BuildItems<AddInTreeSyntaxMode>(SyntaxModeDoozer.Path, null, false).AsParallel()
.Select(m => m.LoadXshd())
)
.Where(def => def.Elements.OfType<XshdColor>().Any(c => c.ExampleText != null))
.OrderBy(def => def.Name)
.ToList();
}
customizationList = CustomizedHighlightingColor.LoadColors();
@ -77,6 +82,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -77,6 +82,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
if (xshd != null) {
IHighlightingDefinition def = HighlightingManager.Instance.GetDefinition(xshd.Name);
if (def == null) {
throw new InvalidOperationException("Expected that all XSHDs are registered in default highlighting manager; but highlighting definition was not found");
} else {
foreach (XshdColor namedColor in xshd.Elements.OfType<XshdColor>()) {
if (namedColor.ExampleText != null) {
IHighlightingItem item = new NamedColorHighlightingItem(def, namedColor);
@ -85,6 +93,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -85,6 +93,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
item.PropertyChanged += item_PropertyChanged;
}
}
}
if (listBox.Items.Count > 0)
listBox.SelectedIndex = 0;
}

116
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxModeDoozer.cs

@ -0,0 +1,116 @@ @@ -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);
}
}
}

2
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -573,8 +573,6 @@ @@ -573,8 +573,6 @@
<Compile Include="Src\Bookmarks\BookmarkManager.cs" />
<Compile Include="Src\Bookmarks\SDMarkerBookmark.cs" />
<Compile Include="Src\TextEditor\ClipboardHandling.cs" />
<Compile Include="Src\TextEditor\Codons\AddInTreeSyntaxModeProvider.cs" />
<Compile Include="Src\TextEditor\Codons\SyntaxModeDoozer.cs" />
<Compile Include="Src\TextEditor\Commands\SearchCommands.cs" />
<Compile Include="Src\TextEditor\Commands\ToolCommands.cs" />
<Compile Include="Src\TextEditor\Conditions\TextContentCondition.cs" />

49
src/Main/Base/Project/Src/TextEditor/Codons/AddInTreeSyntaxModeProvider.cs

@ -1,49 +0,0 @@ @@ -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
}
}
}

112
src/Main/Base/Project/Src/TextEditor/Codons/SyntaxModeDoozer.cs

@ -1,112 +0,0 @@ @@ -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;
}
}
}

3
src/Main/Base/Test/Highlighting/SyntaxDoozerAddsHighlightingToHighlightingManagerTestFixture.cs

@ -13,12 +13,12 @@ using System.Text; @@ -13,12 +13,12 @@ using System.Text;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core;
using ICSharpCode.Core.Tests.Utils;
using ICSharpCode.SharpDevelop.DefaultEditor.Codons;
using ICSharpCode.SharpDevelop.Tests.Utils;
using NUnit.Framework;
namespace ICSharpCode.SharpDevelop.Tests.Highlighting
{
/* TODO: create Tests-project for AvalonEdit.AddIn and move this test there
[TestFixture]
public class SyntaxDoozerAddsHighlightingToHighlightingManagerTestFixture
{
@ -117,4 +117,5 @@ namespace ICSharpCode.SharpDevelop.Tests.Highlighting @@ -117,4 +117,5 @@ namespace ICSharpCode.SharpDevelop.Tests.Highlighting
Assert.AreEqual("XML", highlightingDefinition.Name);
}
}
*/
}

Loading…
Cancel
Save