//
//
//
//
// $Revision: -1 $
//
using ICSharpCode.SharpDevelop.Editor;
using System;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XmlEditor
{
///
/// Display binding for the xml editor.
///
public class XmlDisplayBinding : ISecondaryDisplayBinding
{
public bool ReattachWhenParserServiceIsReady {
get {
return false;
}
}
public bool CanAttachTo(IViewContent content)
{
return content.PrimaryFileName != null && IsFileNameHandled(content.PrimaryFileName);
}
///
/// Returns whether the view can handle the specified file.
///
public static bool IsFileNameHandled(string fileName)
{
return IsXmlFileExtension(Path.GetExtension(fileName));
}
///
/// Checks that the file extension refers to an xml file as
/// specified in the SyntaxModes.xml file.
///
static bool IsXmlFileExtension(string extension)
{
if (string.IsNullOrEmpty(extension))
return false;
foreach (string currentExtension in GetXmlFileExtensions()) {
if (string.Compare(extension, currentExtension, StringComparison.OrdinalIgnoreCase) == 0) {
return true;
}
}
return false;
}
///
/// Gets the known xml file extensions.
///
public static string[] GetXmlFileExtensions()
{
foreach (ParserDescriptor parser in AddInTree.BuildItems("/Workspace/Parser", null, false)) {
if (parser.Codon.Id == "XmlFoldingParser") {
return parser.Supportedextensions;
}
}
// // Did not find the XmlFoldingParser so default to those files defined by the
// // HighlightingManager.
// TODO : not supported in AvalonEdit
// IHighlightingStrategy strategy = HighlightingManager.Manager.FindHighlighter("XML");
// if (strategy != null) {
// return strategy.Extensions;
// }
return new string[] { ".xml", ".addin" };
}
public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent)
{
return (new List() {
new XmlTreeView(viewContent)
}).ToArray();
}
public static bool XmlViewContentActive {
get {
ITextEditorProvider view = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;
if (view != null)
return IsFileNameHandled(view.TextEditor.FileName);
return false;
}
}
}
}