Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Use XML highlighting for file extensions defined in XMLEditor.addin f…
…ile.
  • Loading branch information
mrward committed Feb 20, 2011
1 parent 14de7f0 commit cbe272c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
Expand Up @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;

Expand All @@ -20,25 +21,65 @@ public override void Attach(ITextEditor editor)
{
// HACK: disable SharpDevelop's built-in folding
codeEditorView = editor.GetService(typeof(AvalonEdit.TextEditor)) as AvalonEdit.AddIn.CodeEditorView;
if (codeEditorView != null)
codeEditorView.DisableParseInformationFolding = true;

DisableParseInformationFolding();

UpdateHighlightingIfNotXml();

foldingManager = new XmlFoldingManager(editor);
foldingManager.UpdateFolds();
foldingManager.Start();

base.Attach(editor);
}

void UpdateHighlightingIfNotXml()
{
if (codeEditorView != null) {
if (!IsUsingXmlHighlighting()) {
ChangeHighlightingToXml();
}
}
}

bool IsUsingXmlHighlighting()
{
IHighlightingDefinition highlighting = codeEditorView.SyntaxHighlighting;
if (highlighting != null) {
return highlighting.Name == "XML";
}
return false;
}

void ChangeHighlightingToXml()
{
codeEditorView.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML");
}

public override void Detach()
{
foldingManager.Stop();
foldingManager.Dispose();

if (codeEditorView != null)
codeEditorView.DisableParseInformationFolding = false;
EnableParseInformationFolding();

base.Detach();
}

void DisableParseInformationFolding()
{
DisableParseInformationFolding(true);
}

void DisableParseInformationFolding(bool disable)
{
if (codeEditorView != null) {
codeEditorView.DisableParseInformationFolding = disable;
}
}

void EnableParseInformationFolding()
{
DisableParseInformationFolding(false);
}
}
}
8 changes: 7 additions & 1 deletion src/AddIns/DisplayBindings/XmlEditor/XmlEditor.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.0.6374
# SharpDevelop 4.1.0.7289-alpha
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "Project\XmlEditor.csproj", "{DCA2703D-250A-463E-A68A-07ED105AE6BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor.Tests", "Test\XmlEditor.Tests.csproj", "{FC0FE702-A87D-4D70-A9B6-1ECCD611125F}"
Expand All @@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "..\..\..\Libr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Tests", "..\..\..\Main\Base\Test\ICSharpCode.SharpDevelop.Tests.csproj", "{4980B743-B32F-4aba-AABD-45E2CAD3568D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvalonEdit.AddIn", "..\AvalonEdit.AddIn\AvalonEdit.AddIn.csproj", "{0162E499-42D0-409B-AA25-EED21F75336B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,5 +74,9 @@ Global
{4980B743-B32F-4ABA-AABD-45E2CAD3568D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4980B743-B32F-4ABA-AABD-45E2CAD3568D}.Release|Any CPU.Build.0 = Release|Any CPU
{4980B743-B32F-4ABA-AABD-45E2CAD3568D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0162E499-42D0-409B-AA25-EED21F75336B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0162E499-42D0-409B-AA25-EED21F75336B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0162E499-42D0-409B-AA25-EED21F75336B}.Release|Any CPU.Build.0 = Release|Any CPU
{0162E499-42D0-409B-AA25-EED21F75336B}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal

0 comments on commit cbe272c

Please sign in to comment.