Browse Source
- code clean up git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/XmlEditor@4167 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
63 changed files with 414 additions and 5452 deletions
@ -1,167 +0,0 @@
@@ -1,167 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1662 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Xml; |
||||
using System.Xml.XPath; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Stores an XmlNode and its associated line number and position after an
|
||||
/// XPath query has been evaluated.
|
||||
/// </summary>
|
||||
public class XPathNodeMatch : IXmlLineInfo |
||||
{ |
||||
int? lineNumber; |
||||
int linePosition; |
||||
string value; |
||||
string displayValue; |
||||
XPathNodeType nodeType; |
||||
|
||||
/// <summary>
|
||||
/// Creates an XPathNodeMatch from the navigator which should be position on the
|
||||
/// node.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We deliberately use the OuterXml when we find a Namespace since the
|
||||
/// navigator location returned starts from the xmlns attribute.
|
||||
/// </remarks>
|
||||
public XPathNodeMatch(XPathNavigator currentNavigator) |
||||
{ |
||||
SetLineNumbers(currentNavigator as IXmlLineInfo); |
||||
nodeType = currentNavigator.NodeType; |
||||
switch (nodeType) { |
||||
case XPathNodeType.Text: |
||||
SetTextValue(currentNavigator); |
||||
break; |
||||
case XPathNodeType.Comment: |
||||
SetCommentValue(currentNavigator); |
||||
break; |
||||
case XPathNodeType.Namespace: |
||||
SetNamespaceValue(currentNavigator); |
||||
break; |
||||
case XPathNodeType.Element: |
||||
SetElementValue(currentNavigator); |
||||
break; |
||||
case XPathNodeType.ProcessingInstruction: |
||||
SetProcessingInstructionValue(currentNavigator); |
||||
break; |
||||
case XPathNodeType.Attribute: |
||||
SetAttributeValue(currentNavigator); |
||||
break; |
||||
default: |
||||
value = currentNavigator.LocalName; |
||||
displayValue = value; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Line numbers are zero based.
|
||||
/// </summary>
|
||||
public int LineNumber { |
||||
get { |
||||
return lineNumber.GetValueOrDefault(0); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Line positions are zero based.
|
||||
/// </summary>
|
||||
public int LinePosition { |
||||
get { |
||||
return linePosition; |
||||
} |
||||
} |
||||
|
||||
public bool HasLineInfo() |
||||
{ |
||||
return lineNumber.HasValue; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the text value of the node.
|
||||
/// </summary>
|
||||
public string Value { |
||||
get { |
||||
return value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the node display value. This includes the angle brackets if it is
|
||||
/// an element, for example.
|
||||
/// </summary>
|
||||
public string DisplayValue { |
||||
get { |
||||
return displayValue; |
||||
} |
||||
} |
||||
|
||||
public XPathNodeType NodeType { |
||||
get { |
||||
return nodeType; |
||||
} |
||||
} |
||||
|
||||
void SetElementValue(XPathNavigator navigator) |
||||
{ |
||||
value = navigator.Name; |
||||
if (navigator.IsEmptyElement) { |
||||
displayValue = String.Concat("<", value, "/>"); |
||||
} else { |
||||
displayValue = String.Concat("<", value, ">"); |
||||
} |
||||
} |
||||
|
||||
void SetTextValue(XPathNavigator navigator) |
||||
{ |
||||
value = navigator.Value; |
||||
displayValue = value; |
||||
} |
||||
|
||||
void SetCommentValue(XPathNavigator navigator) |
||||
{ |
||||
value = navigator.Value; |
||||
displayValue = navigator.OuterXml; |
||||
} |
||||
|
||||
void SetNamespaceValue(XPathNavigator navigator) |
||||
{ |
||||
value = navigator.OuterXml; |
||||
displayValue = value; |
||||
} |
||||
|
||||
void SetProcessingInstructionValue(XPathNavigator navigator) |
||||
{ |
||||
value = navigator.Name; |
||||
displayValue = navigator.OuterXml; |
||||
} |
||||
|
||||
void SetAttributeValue(XPathNavigator navigator) |
||||
{ |
||||
value = navigator.Name; |
||||
displayValue = String.Concat("@", value); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Takes one of the xml line number so the numbers are now zero
|
||||
/// based instead of one based.
|
||||
/// </summary>
|
||||
/// <remarks>A namespace query (e.g. //namespace::*) will return
|
||||
/// a line info of -1, -1 for the xml namespace. Which looks like
|
||||
/// a bug in the XPathDocument class.</remarks>
|
||||
void SetLineNumbers(IXmlLineInfo lineInfo) |
||||
{ |
||||
if (lineInfo.HasLineInfo() && lineInfo.LineNumber > 0) { |
||||
lineNumber = lineInfo.LineNumber - 1; |
||||
linePosition = lineInfo.LinePosition - 1; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1965 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/* |
||||
/// <summary>
|
||||
/// A text marker for an XPath query match.
|
||||
/// </summary>
|
||||
public class XPathNodeTextMarker : TextMarker |
||||
{ |
||||
public static readonly Color MarkerBackColor = Color.FromArgb(159, 255, 162); |
||||
|
||||
public XPathNodeTextMarker(int offset, XPathNodeMatch node) : base(offset, node.Value.Length, TextMarkerType.SolidBlock, MarkerBackColor) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds markers for each XPathNodeMatch.
|
||||
/// </summary>
|
||||
public static void AddMarkers(MarkerStrategy markerStrategy, XPathNodeMatch[] nodes) |
||||
{ |
||||
foreach (XPathNodeMatch node in nodes) { |
||||
AddMarker(markerStrategy, node); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a single marker for the XPathNodeMatch.
|
||||
/// </summary>
|
||||
public static void AddMarker(MarkerStrategy markerStrategy, XPathNodeMatch node) |
||||
{ |
||||
if (node.HasLineInfo() && node.Value.Length > 0) { |
||||
LineSegment lineSegment = markerStrategy.Document.GetLineSegment(node.LineNumber); |
||||
markerStrategy.AddMarker(new XPathNodeTextMarker(lineSegment.Offset + node.LinePosition, node)); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes all the XPathNodeMarkers from the marker strategy.
|
||||
/// </summary>
|
||||
public static void RemoveMarkers(MarkerStrategy markerStrategy) |
||||
{ |
||||
markerStrategy.RemoveAll(IsXPathNodeTextMarkerMatch); |
||||
} |
||||
|
||||
static bool IsXPathNodeTextMarkerMatch(TextMarker marker) |
||||
{ |
||||
return marker is XPathNodeTextMarker; |
||||
} |
||||
} |
||||
*/ |
||||
} |
@ -1,95 +0,0 @@
@@ -1,95 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1965 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Property descriptor for an XmlAttribute. This is used when displaying
|
||||
/// an XmlAttribute in the property grid.
|
||||
/// </summary>
|
||||
public class XmlAttributePropertyDescriptor : PropertyDescriptor |
||||
{ |
||||
XmlAttribute xmlAttribute; |
||||
public XmlAttributePropertyDescriptor(XmlAttribute xmlAttribute) |
||||
: base(xmlAttribute.LocalName, new Attribute[0]) |
||||
{ |
||||
this.xmlAttribute = xmlAttribute; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the property descriptors for the specified attributes.
|
||||
/// </summary>
|
||||
public static PropertyDescriptorCollection GetProperties(XmlAttributeCollection xmlAttributes) |
||||
{ |
||||
List<PropertyDescriptor> properties = new List<PropertyDescriptor>(); |
||||
foreach (XmlAttribute xmlAttribute in xmlAttributes) { |
||||
properties.Add(new XmlAttributePropertyDescriptor(xmlAttribute)); |
||||
} |
||||
return new PropertyDescriptorCollection(properties.ToArray()); |
||||
} |
||||
|
||||
public override Type ComponentType { |
||||
get { |
||||
return typeof(String); |
||||
} |
||||
} |
||||
|
||||
public override bool IsReadOnly { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the property type in this case a string.
|
||||
/// </summary>
|
||||
public override Type PropertyType { |
||||
get { |
||||
return typeof(String); |
||||
} |
||||
} |
||||
|
||||
public override bool CanResetValue(object component) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the xml attribute.
|
||||
/// </summary>
|
||||
public override object GetValue(object component) |
||||
{ |
||||
return xmlAttribute.Value; |
||||
} |
||||
|
||||
public override void ResetValue(object component) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the xml attribute value.
|
||||
/// </summary>
|
||||
public override void SetValue(object component, object value) |
||||
{ |
||||
xmlAttribute.Value = (String)value; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If the current value has changed from the default value then this
|
||||
/// method will return true.
|
||||
/// </summary>
|
||||
public override bool ShouldSerializeValue(object component) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
} |
@ -1,94 +0,0 @@
@@ -1,94 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1965 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Type descriptor that allows us to display properties in the property grid
|
||||
/// for Xml attributes.
|
||||
/// </summary>
|
||||
public class XmlAttributeTypeDescriptor : ICustomTypeDescriptor |
||||
{ |
||||
PropertyDescriptorCollection properties; |
||||
|
||||
public XmlAttributeTypeDescriptor(XmlAttributeCollection xmlAttributes) |
||||
{ |
||||
if (xmlAttributes != null) { |
||||
properties = XmlAttributePropertyDescriptor.GetProperties(xmlAttributes); |
||||
} else { |
||||
properties = new PropertyDescriptorCollection(new XmlAttributePropertyDescriptor[0]); |
||||
} |
||||
} |
||||
|
||||
public AttributeCollection GetAttributes() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public string GetClassName() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public string GetComponentName() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public TypeConverter GetConverter() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public EventDescriptor GetDefaultEvent() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public PropertyDescriptor GetDefaultProperty() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public object GetEditor(Type editorBaseType) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public EventDescriptorCollection GetEvents() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public EventDescriptorCollection GetEvents(Attribute[] attributes) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public PropertyDescriptorCollection GetProperties() |
||||
{ |
||||
return GetProperties(new Attribute[0]); |
||||
} |
||||
|
||||
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) |
||||
{ |
||||
return properties; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns this class instance.
|
||||
/// </summary>
|
||||
public object GetPropertyOwner(PropertyDescriptor pd) |
||||
{ |
||||
return this; |
||||
} |
||||
} |
||||
} |
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 2128 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Xml; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for XmlTextTreeNodes and XmlCommentTreeNodes
|
||||
/// </summary>
|
||||
public abstract class XmlCharacterDataTreeNode : ExtTreeNode |
||||
{ |
||||
XmlCharacterData characterData; |
||||
|
||||
public XmlCharacterDataTreeNode(XmlCharacterData characterData) |
||||
{ |
||||
this.characterData = characterData; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the display text based on changes in the
|
||||
/// XmlCharacterData's InnerText associated with this node.
|
||||
/// </summary>
|
||||
public void Update() |
||||
{ |
||||
Text = GetDisplayText(characterData.InnerText); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the text to display for this tree node.
|
||||
/// </summary>
|
||||
/// <remarks>If the text is a single line then it is returned, but
|
||||
/// trimmed. If the text has multiple lines then the first line that
|
||||
/// is not empty is returned. This line may have "..." appended to indicate
|
||||
/// there is more text for this node that is not being displayed. The
|
||||
/// "..." will be appended only if there are multiple lines containing
|
||||
/// text.</remarks>
|
||||
static string GetDisplayText(string s) |
||||
{ |
||||
string[] lines = s.Trim().Split('\n'); |
||||
for (int i = 0; i < lines.Length; ++i) { |
||||
string line = lines[i].Trim(); |
||||
if (line.Length > 0) { |
||||
if (lines.Length == 1) { |
||||
return line; |
||||
} else { |
||||
return String.Concat(line, "..."); |
||||
} |
||||
} |
||||
} |
||||
return String.Empty; |
||||
} |
||||
} |
||||
} |
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 2164 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Xml; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an xml comment in the tree.
|
||||
/// </summary>
|
||||
public class XmlCommentTreeNode : XmlCharacterDataTreeNode |
||||
{ |
||||
public const string XmlCommentTreeNodeImageKey = "XmlCommentTreeNodeImage"; |
||||
public const string XmlCommentTreeNodeGhostImageKey = "XmlCommentTreeNodeGhostImage"; |
||||
|
||||
XmlComment comment; |
||||
|
||||
public XmlCommentTreeNode(XmlComment comment) |
||||
: base(comment) |
||||
{ |
||||
this.comment = comment; |
||||
ImageKey = XmlCommentTreeNodeImageKey; |
||||
SelectedImageKey = ImageKey; |
||||
Update(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the XmlComment associated with this tree node.
|
||||
/// </summary>
|
||||
public XmlComment XmlComment { |
||||
get { |
||||
return comment; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether to show the ghost image which is
|
||||
/// displayed when cutting the node.
|
||||
/// </summary>
|
||||
public bool ShowGhostImage { |
||||
get { |
||||
return ImageKey == XmlCommentTreeNodeGhostImageKey; |
||||
} |
||||
set { |
||||
if (value) { |
||||
ImageKey = XmlCommentTreeNodeGhostImageKey; |
||||
} else { |
||||
ImageKey = XmlCommentTreeNodeImageKey; |
||||
} |
||||
SelectedImageKey = ImageKey; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,119 +0,0 @@
@@ -1,119 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1965 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// The Xml Editor add-in options.
|
||||
/// </summary>
|
||||
public static class XmlEditorAddInOptions |
||||
{ |
||||
public static readonly string OptionsProperty = "XmlEditor.AddIn.Options"; |
||||
public static readonly string ShowAttributesWhenFoldedPropertyName = "ShowAttributesWhenFolded"; |
||||
public static readonly string ShowSchemaAnnotationPropertyName = "ShowSchemaAnnotation"; |
||||
|
||||
static Properties properties; |
||||
|
||||
static XmlEditorAddInOptions() |
||||
{ |
||||
properties = PropertyService.Get(OptionsProperty, new Properties()); |
||||
} |
||||
|
||||
static Properties Properties { |
||||
get { |
||||
Debug.Assert(properties != null); |
||||
return properties; |
||||
} |
||||
} |
||||
|
||||
public static event PropertyChangedEventHandler PropertyChanged { |
||||
add { Properties.PropertyChanged += value; } |
||||
remove { Properties.PropertyChanged -= value; } |
||||
} |
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Gets an association between a schema and a file extension.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>The property will be an xml element when the SharpDevelopProperties.xml
|
||||
/// is read on startup. The property will be a schema association
|
||||
/// if the user changes the schema associated with the file
|
||||
/// extension in tools->options.</para>
|
||||
/// <para>The normal way of doing things is to
|
||||
/// pass the GetProperty method a default value which auto-magically
|
||||
/// turns the xml element into a schema association so we would not
|
||||
/// have to check for both. In this case, however, I do not want
|
||||
/// a default saved to the SharpDevelopProperties.xml file unless the user
|
||||
/// makes a change using Tools->Options.</para>
|
||||
/// <para>If we have a file extension that is currently missing a default
|
||||
/// schema then if we ship the schema at a later date the association will
|
||||
/// be updated by the code if the user has not changed the settings themselves.
|
||||
/// </para>
|
||||
/// <para>For example, the initial release of the xml editor add-in had
|
||||
/// no default schema for .xsl files, by default it was associated with
|
||||
/// no schema and this setting is saved if the user ever viewed the settings
|
||||
/// in the tools->options dialog. Now, after the initial release the
|
||||
/// .xsl schema was created and shipped with SharpDevelop, there is
|
||||
/// no way to associate this schema to .xsl files by default since
|
||||
/// the property exists in the SharpDevelopProperties.xml file.</para>
|
||||
/// <para>An alternative way of doing this might be to have the
|
||||
/// config info in the schema itself, which a special SharpDevelop
|
||||
/// namespace. I believe this is what Visual Studio does. This
|
||||
/// way is not as flexible since it requires the user to locate
|
||||
/// the schema and change the association manually.</para>
|
||||
/// </remarks>
|
||||
public static XmlSchemaAssociation GetSchemaAssociation(string extension) |
||||
{ |
||||
extension = extension.ToLower(); |
||||
string property = Properties.Get("ext" + extension, String.Empty); |
||||
XmlSchemaAssociation association = null; |
||||
|
||||
if (property.Length > 0) { |
||||
association = XmlSchemaAssociation.ConvertFromString(property); |
||||
} |
||||
|
||||
// Use default?
|
||||
if (association == null) { |
||||
association = XmlSchemaAssociation.GetDefaultAssociation(extension); |
||||
} |
||||
|
||||
return association; |
||||
} |
||||
|
||||
public static void SetSchemaAssociation(XmlSchemaAssociation association) |
||||
{ |
||||
Properties.Set("ext" + association.Extension, association.ConvertToString()); |
||||
} |
||||
|
||||
public static bool ShowAttributesWhenFolded { |
||||
get { |
||||
return Properties.Get(ShowAttributesWhenFoldedPropertyName, false); |
||||
} |
||||
|
||||
set { |
||||
Properties.Set(ShowAttributesWhenFoldedPropertyName, value); |
||||
} |
||||
} |
||||
|
||||
public static bool ShowSchemaAnnotation { |
||||
get { |
||||
return Properties.Get(ShowSchemaAnnotationPropertyName, true); |
||||
} |
||||
|
||||
set { |
||||
Properties.Set(ShowSchemaAnnotationPropertyName, value); |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -1,99 +0,0 @@
@@ -1,99 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 2164 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Xml; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an XmlElement in the Xml Tree.
|
||||
/// </summary>
|
||||
public class XmlElementTreeNode : ExtTreeNode |
||||
{ |
||||
public const string XmlElementTreeNodeImageKey = "XmlElementTreeNodeImage"; |
||||
public const string XmlElementTreeNodeGhostImageKey = "XmlElementTreeNodeGhostImage"; |
||||
|
||||
XmlElement element; |
||||
|
||||
public XmlElementTreeNode(XmlElement element) |
||||
{ |
||||
this.element = element; |
||||
Text = GetDisplayText(element); |
||||
Tag = element; |
||||
ImageKey = XmlElementTreeNodeImageKey; |
||||
|
||||
if (element.HasChildNodes) { |
||||
// Add dummy node so that the tree node can be
|
||||
// expanded in the tree view.
|
||||
Nodes.Add(new ExtTreeNode()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the XmlElement associated with this tree node.
|
||||
/// </summary>
|
||||
public XmlElement XmlElement { |
||||
get { |
||||
return element; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether to show the ghost image which is
|
||||
/// displayed when cutting the node.
|
||||
/// </summary>
|
||||
public bool ShowGhostImage { |
||||
get { |
||||
return ImageKey == XmlElementTreeNodeGhostImageKey; |
||||
} |
||||
set { |
||||
if (value) { |
||||
ImageKey = XmlElementTreeNodeGhostImageKey; |
||||
} else { |
||||
ImageKey = XmlElementTreeNodeImageKey; |
||||
} |
||||
SelectedImageKey = ImageKey; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds child elements to this tree node.
|
||||
/// </summary>
|
||||
protected override void Initialize() |
||||
{ |
||||
Nodes.Clear(); |
||||
foreach (XmlNode childNode in element.ChildNodes) { |
||||
XmlElement childElement = childNode as XmlElement; |
||||
XmlText text = childNode as XmlText; |
||||
XmlComment comment = childNode as XmlComment; |
||||
if (childElement != null) { |
||||
XmlElementTreeNode treeNode = new XmlElementTreeNode(childElement); |
||||
treeNode.AddTo(this); |
||||
} else if (text != null) { |
||||
XmlTextTreeNode treeNode = new XmlTextTreeNode(text); |
||||
treeNode.AddTo(this); |
||||
} else if (comment != null) { |
||||
XmlCommentTreeNode treeNode = new XmlCommentTreeNode(comment); |
||||
treeNode.AddTo(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the tree node's text for the element.
|
||||
/// </summary>
|
||||
static string GetDisplayText(XmlElement element) |
||||
{ |
||||
if (element.Prefix.Length > 0) { |
||||
return String.Concat(element.Prefix, ":", element.LocalName); |
||||
} |
||||
return element.LocalName; |
||||
} |
||||
} |
||||
} |
@ -1,157 +0,0 @@
@@ -1,157 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1965 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an association between an xml schema and a file extension.
|
||||
/// </summary>
|
||||
public class XmlSchemaAssociation //: IXmlConvertable
|
||||
{ |
||||
string namespaceUri = String.Empty; |
||||
string extension = String.Empty; |
||||
string namespacePrefix = String.Empty; |
||||
|
||||
public XmlSchemaAssociation(string extension) |
||||
: this(extension, String.Empty, String.Empty) |
||||
{ |
||||
} |
||||
|
||||
public XmlSchemaAssociation(string extension, string namespaceUri) |
||||
: this(extension, namespaceUri, String.Empty) |
||||
{ |
||||
} |
||||
|
||||
public XmlSchemaAssociation(string extension, string namespaceUri, string namespacePrefix) |
||||
{ |
||||
this.extension = extension; |
||||
this.namespaceUri = namespaceUri; |
||||
this.namespacePrefix = namespacePrefix; |
||||
} |
||||
|
||||
public string NamespaceUri { |
||||
get { |
||||
return namespaceUri; |
||||
} |
||||
|
||||
set { |
||||
namespaceUri = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file extension (e.g. '.xml').
|
||||
/// </summary>
|
||||
public string Extension { |
||||
get { |
||||
return extension; |
||||
} |
||||
|
||||
set { |
||||
extension = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default namespace prefix that will be added
|
||||
/// to the xml elements.
|
||||
/// </summary>
|
||||
public string NamespacePrefix { |
||||
get { |
||||
return namespacePrefix; |
||||
} |
||||
|
||||
set { |
||||
namespacePrefix = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the default schema association for the file extension.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// These defaults are hard coded.
|
||||
/// </remarks>
|
||||
public static XmlSchemaAssociation GetDefaultAssociation(string extension) |
||||
{ |
||||
XmlSchemaAssociation association = null; |
||||
|
||||
switch (extension.ToLowerInvariant()) { |
||||
case ".wxs": |
||||
association = new XmlSchemaAssociation(extension, @"http://schemas.microsoft.com/wix/2003/01/wi"); |
||||
break; |
||||
case ".config": |
||||
association = new XmlSchemaAssociation(extension, @"urn:app-config"); |
||||
break; |
||||
case ".build": |
||||
association = new XmlSchemaAssociation(extension, @"http://nant.sf.net/release/0.85/nant.xsd"); |
||||
break; |
||||
case ".addin": |
||||
association = new XmlSchemaAssociation(extension, @"http://www.icsharpcode.net/2005/addin"); |
||||
break; |
||||
case ".xsl": |
||||
case ".xslt": |
||||
association = new XmlSchemaAssociation(extension, @"http://www.w3.org/1999/XSL/Transform", "xsl"); |
||||
break; |
||||
case ".xsd": |
||||
association = new XmlSchemaAssociation(extension, @"http://www.w3.org/2001/XMLSchema", "xs"); |
||||
break; |
||||
case ".manifest": |
||||
association = new XmlSchemaAssociation(extension, @"urn:schemas-microsoft-com:asm.v1"); |
||||
break; |
||||
case ".xaml": |
||||
association = new XmlSchemaAssociation(extension, @"http://schemas.microsoft.com/winfx/avalon/2005"); |
||||
break; |
||||
default: |
||||
association = new XmlSchemaAssociation(extension); |
||||
break; |
||||
} |
||||
return association; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Two schema associations are considered equal if their file extension,
|
||||
/// prefix and namespaceUri are the same.
|
||||
/// </summary>
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
bool equals = false; |
||||
|
||||
XmlSchemaAssociation rhs = obj as XmlSchemaAssociation; |
||||
if (rhs != null) { |
||||
if ((this.namespacePrefix == rhs.namespacePrefix) && |
||||
(this.extension == rhs.extension) && |
||||
(this.namespaceUri == rhs.namespaceUri)) { |
||||
equals = true; |
||||
} |
||||
} |
||||
|
||||
return equals; |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return (namespaceUri != null ? namespaceUri.GetHashCode() : 0) ^ (extension != null ? extension.GetHashCode() : 0) ^ (namespacePrefix != null ? namespacePrefix.GetHashCode() : 0); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates an XmlSchemaAssociation from the saved xml.
|
||||
/// </summary>
|
||||
public static XmlSchemaAssociation ConvertFromString(string text) |
||||
{ |
||||
string[] parts = text.Split(new char[] {'|'}, 3); |
||||
return new XmlSchemaAssociation(parts[0], parts[1], parts[2]); |
||||
} |
||||
|
||||
public string ConvertToString() |
||||
{ |
||||
return extension + "|" + namespaceUri + "|" + namespacePrefix; |
||||
} |
||||
} |
||||
} |
@ -1,89 +0,0 @@
@@ -1,89 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1965 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents list box item showing the association between an xml schema
|
||||
/// and a file extension.
|
||||
/// </summary>
|
||||
public class XmlSchemaAssociationListBoxItem |
||||
{ |
||||
bool isDirty = false; |
||||
string namespaceUri = String.Empty; |
||||
string extension = String.Empty; |
||||
string namespacePrefix = String.Empty; |
||||
|
||||
public XmlSchemaAssociationListBoxItem(string extension, string namespaceUri, string namespacePrefix) |
||||
{ |
||||
this.extension = extension; |
||||
this.namespaceUri = namespaceUri; |
||||
this.namespacePrefix = namespacePrefix; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this association has been changed by the user.
|
||||
/// </summary>
|
||||
public bool IsDirty { |
||||
get { |
||||
return isDirty; |
||||
} |
||||
|
||||
set { |
||||
isDirty = value; |
||||
} |
||||
} |
||||
|
||||
public string NamespaceUri { |
||||
get { |
||||
return namespaceUri; |
||||
} |
||||
|
||||
set { |
||||
namespaceUri = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file extension (e.g. '.xml').
|
||||
/// </summary>
|
||||
public string Extension { |
||||
get { |
||||
return extension; |
||||
} |
||||
|
||||
set { |
||||
extension = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default namespace prefix that will be added
|
||||
/// to the xml elements.
|
||||
/// </summary>
|
||||
public string NamespacePrefix { |
||||
get { |
||||
return namespacePrefix; |
||||
} |
||||
|
||||
set { |
||||
namespacePrefix = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the file extension so this can be sorted in a list box.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString() |
||||
{ |
||||
return extension; |
||||
} |
||||
} |
||||
} |
File diff suppressed because one or more lines are too long
@ -1,294 +0,0 @@
@@ -1,294 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1965 $</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.XmlBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// A collection that stores <see cref='XmlSchemaCompletionData'/> objects.
|
||||
/// </summary>
|
||||
[Serializable()] |
||||
public class XmlSchemaCompletionDataCollection : System.Collections.CollectionBase { |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public XmlSchemaCompletionDataCollection() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlSchemaCompletionDataCollection'/> based on another <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A <see cref='XmlSchemaCompletionDataCollection'/> from which the contents are copied
|
||||
/// </param>
|
||||
public XmlSchemaCompletionDataCollection(XmlSchemaCompletionDataCollection val) |
||||
{ |
||||
this.AddRange(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlSchemaCompletionDataCollection'/> containing any array of <see cref='XmlSchemaCompletionData'/> objects.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A array of <see cref='XmlSchemaCompletionData'/> objects with which to intialize the collection
|
||||
/// </param>
|
||||
public XmlSchemaCompletionDataCollection(XmlSchemaCompletionData[] val) |
||||
{ |
||||
this.AddRange(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents the entry at the specified index of the <see cref='XmlSchemaCompletionData'/>.
|
||||
/// </summary>
|
||||
/// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
|
||||
/// <value>The entry at the specified index of the collection.</value>
|
||||
/// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
|
||||
public XmlSchemaCompletionData this[int index] { |
||||
get { |
||||
return ((XmlSchemaCompletionData)(List[index])); |
||||
} |
||||
set { |
||||
List[index] = value; |
||||
} |
||||
} |
||||
|
||||
public ICompletionItemList GetNamespaceCompletionData() |
||||
{ |
||||
XmlCompletionItemList list = new XmlCompletionItemList(); |
||||
|
||||
foreach (XmlSchemaCompletionData schema in this) { |
||||
XmlCompletionItem completionData = new XmlCompletionItem(schema.NamespaceUri, XmlCompletionItem.DataType.NamespaceUri); |
||||
list.Items.Add(completionData); |
||||
} |
||||
|
||||
list.SortItems(); |
||||
|
||||
return list; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents the <see cref='XmlSchemaCompletionData'/> entry with the specified namespace URI.
|
||||
/// </summary>
|
||||
/// <param name='namespaceUri'>The schema's namespace URI.</param>
|
||||
/// <value>The entry with the specified namespace URI.</value>
|
||||
public XmlSchemaCompletionData this[string namespaceUri] { |
||||
get { |
||||
return GetItem(namespaceUri); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref='XmlSchemaCompletionData'/> with the specified value to the
|
||||
/// <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to add.</param>
|
||||
/// <returns>The index at which the new element was inserted.</returns>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.AddRange'/>
|
||||
public int Add(XmlSchemaCompletionData val) |
||||
{ |
||||
return List.Add(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the elements of an array to the end of the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// An array of type <see cref='XmlSchemaCompletionData'/> containing the objects to add to the collection.
|
||||
/// </param>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.Add'/>
|
||||
public void AddRange(XmlSchemaCompletionData[] val) |
||||
{ |
||||
for (int i = 0; i < val.Length; i++) { |
||||
this.Add(val[i]); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the contents of another <see cref='XmlSchemaCompletionDataCollection'/> to the end of the collection.
|
||||
/// </summary>
|
||||
/// <param name='val'>
|
||||
/// A <see cref='XmlSchemaCompletionDataCollection'/> containing the objects to add to the collection.
|
||||
/// </param>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.Add'/>
|
||||
public void AddRange(XmlSchemaCompletionDataCollection val) |
||||
{ |
||||
for (int i = 0; i < val.Count; i++) |
||||
{ |
||||
this.Add(val[i]); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the
|
||||
/// <see cref='XmlSchemaCompletionDataCollection'/> contains the specified <see cref='XmlSchemaCompletionData'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to locate.</param>
|
||||
/// <returns>
|
||||
/// <see langword='true'/> if the <see cref='XmlSchemaCompletionData'/> is contained in the collection;
|
||||
/// otherwise, <see langword='false'/>.
|
||||
/// </returns>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.IndexOf'/>
|
||||
public bool Contains(XmlSchemaCompletionData val) |
||||
{ |
||||
return List.Contains(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the <see cref='XmlSchemaCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the
|
||||
/// specified index.
|
||||
/// </summary>
|
||||
/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='XmlSchemaCompletionDataCollection'/>.</param>
|
||||
/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
|
||||
/// <exception cref='ArgumentException'>
|
||||
/// <para><paramref name='array'/> is multidimensional.</para>
|
||||
/// <para>-or-</para>
|
||||
/// <para>The number of elements in the <see cref='XmlSchemaCompletionDataCollection'/> is greater than
|
||||
/// the available space between <paramref name='arrayIndex'/> and the end of
|
||||
/// <paramref name='array'/>.</para>
|
||||
/// </exception>
|
||||
/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
|
||||
/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
|
||||
/// <seealso cref='Array'/>
|
||||
public void CopyTo(XmlSchemaCompletionData[] array, int index) |
||||
{ |
||||
List.CopyTo(array, index); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the index of a <see cref='XmlSchemaCompletionData'/> in
|
||||
/// the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to locate.</param>
|
||||
/// <returns>
|
||||
/// The index of the <see cref='XmlSchemaCompletionData'/> of <paramref name='val'/> in the
|
||||
/// <see cref='XmlSchemaCompletionDataCollection'/>, if found; otherwise, -1.
|
||||
/// </returns>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.Contains'/>
|
||||
public int IndexOf(XmlSchemaCompletionData val) |
||||
{ |
||||
return List.IndexOf(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a <see cref='XmlSchemaCompletionData'/> into the <see cref='XmlSchemaCompletionDataCollection'/> at the specified index.
|
||||
/// </summary>
|
||||
/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to insert.</param>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection.Add'/>
|
||||
public void Insert(int index, XmlSchemaCompletionData val) |
||||
{ |
||||
List.Insert(index, val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that can iterate through the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <seealso cref='IEnumerator'/>
|
||||
public new XmlSchemaCompletionDataEnumerator GetEnumerator() |
||||
{ |
||||
return new XmlSchemaCompletionDataEnumerator(this); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes a specific <see cref='XmlSchemaCompletionData'/> from the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
/// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to remove from the <see cref='XmlSchemaCompletionDataCollection'/>.</param>
|
||||
/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
|
||||
public void Remove(XmlSchemaCompletionData val) |
||||
{ |
||||
List.Remove(val); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the schema completion data with the same filename.
|
||||
/// </summary>
|
||||
/// <returns><see langword="null"/> if no matching schema found.</returns>
|
||||
public XmlSchemaCompletionData GetSchemaFromFileName(string fileName) |
||||
{ |
||||
foreach (XmlSchemaCompletionData schema in this) { |
||||
if (FileUtility.IsEqualFileName(schema.FileName, fileName)) { |
||||
return schema; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Enumerator that can iterate through a XmlSchemaCompletionDataCollection.
|
||||
/// </summary>
|
||||
/// <seealso cref='IEnumerator'/>
|
||||
/// <seealso cref='XmlSchemaCompletionDataCollection'/>
|
||||
/// <seealso cref='XmlSchemaCompletionData'/>
|
||||
public class XmlSchemaCompletionDataEnumerator : System.Collections.IEnumerator |
||||
{ |
||||
System.Collections.IEnumerator baseEnumerator; |
||||
System.Collections.IEnumerable temp; |
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref='XmlSchemaCompletionDataEnumerator'/>.
|
||||
/// </summary>
|
||||
public XmlSchemaCompletionDataEnumerator(XmlSchemaCompletionDataCollection mappings) |
||||
{ |
||||
this.temp = ((System.Collections.IEnumerable)(mappings)); |
||||
this.baseEnumerator = temp.GetEnumerator(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the current <see cref='XmlSchemaCompletionData'/> in the <seealso cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public XmlSchemaCompletionData Current { |
||||
get { |
||||
return ((XmlSchemaCompletionData)(baseEnumerator.Current)); |
||||
} |
||||
} |
||||
|
||||
object System.Collections.IEnumerator.Current { |
||||
get { |
||||
return baseEnumerator.Current; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Advances the enumerator to the next <see cref='XmlSchemaCompletionData'/> of the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public bool MoveNext() |
||||
{ |
||||
return baseEnumerator.MoveNext(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the enumerator to its initial position, which is before the first element in the <see cref='XmlSchemaCompletionDataCollection'/>.
|
||||
/// </summary>
|
||||
public void Reset() |
||||
{ |
||||
baseEnumerator.Reset(); |
||||
} |
||||
} |
||||
|
||||
XmlSchemaCompletionData GetItem(string namespaceUri) |
||||
{ |
||||
XmlSchemaCompletionData matchedItem = null; |
||||
|
||||
foreach(XmlSchemaCompletionData item in this) |
||||
{ |
||||
if (item.NamespaceUri == namespaceUri) { |
||||
matchedItem = item; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return matchedItem; |
||||
} |
||||
} |
||||
} |
@ -1,61 +0,0 @@
@@ -1,61 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 915 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Media; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// A schema item shown in the tools options dialog.
|
||||
/// </summary>
|
||||
public class XmlSchemaListBoxItem |
||||
{ |
||||
string namespaceUri = String.Empty; |
||||
bool readOnly = false; |
||||
|
||||
/// <summary>
|
||||
/// Creates a new list box item.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A readonly list box item is used for system schemas, those that
|
||||
/// are installed with SharpDevelop.
|
||||
/// </remarks>
|
||||
public XmlSchemaListBoxItem(string namespaceUri, bool readOnly) |
||||
{ |
||||
this.namespaceUri = namespaceUri; |
||||
this.readOnly = readOnly; |
||||
} |
||||
|
||||
public XmlSchemaListBoxItem(string namespaceUri) |
||||
: this(namespaceUri, false) |
||||
{ |
||||
} |
||||
|
||||
public string NamespaceUri { |
||||
get { |
||||
return namespaceUri; |
||||
} |
||||
} |
||||
|
||||
public bool ReadOnly { |
||||
get { |
||||
return readOnly; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the namespace Uri so the list box item is sorted correctly.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString() |
||||
{ |
||||
return namespaceUri; |
||||
} |
||||
} |
||||
} |
@ -1,218 +0,0 @@
@@ -1,218 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 1965 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
|
||||
/// <summary>
|
||||
/// Keeps track of all the schemas that the Xml Editor is aware
|
||||
/// of.
|
||||
/// </summary>
|
||||
public class XmlSchemaManager |
||||
{ |
||||
public const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema"; |
||||
|
||||
static XmlSchemaCompletionDataCollection schemas = null; |
||||
static XmlSchemaManager manager = null; |
||||
|
||||
public static event EventHandler UserSchemaAdded; |
||||
|
||||
public static event EventHandler UserSchemaRemoved; |
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified namespace is actually the W3C namespace for
|
||||
/// XSD files.
|
||||
/// </summary>
|
||||
public static bool IsXmlSchemaNamespace(string schemaNamespace) |
||||
{ |
||||
return schemaNamespace == XmlSchemaNamespace; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the schemas that SharpDevelop knows about.
|
||||
/// </summary>
|
||||
public static XmlSchemaCompletionDataCollection SchemaCompletionDataItems { |
||||
get { |
||||
if (schemas == null) { |
||||
schemas = new XmlSchemaCompletionDataCollection(); |
||||
manager = new XmlSchemaManager(); |
||||
ReadSchemas(); |
||||
} |
||||
|
||||
return schemas; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the schema completion data that is associated with the
|
||||
/// specified file extension.
|
||||
/// </summary>
|
||||
public static XmlSchemaCompletionData GetSchemaCompletionData(string extension) |
||||
{ |
||||
XmlSchemaCompletionData data = null; |
||||
|
||||
XmlSchemaAssociation association = XmlEditorAddInOptions.GetSchemaAssociation(extension); |
||||
if (association != null) { |
||||
if (association.NamespaceUri.Length > 0) { |
||||
data = SchemaCompletionDataItems[association.NamespaceUri]; |
||||
} |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace prefix that is associated with the
|
||||
/// specified file extension.
|
||||
/// </summary>
|
||||
public static string GetNamespacePrefix(string extension) |
||||
{ |
||||
string prefix = String.Empty; |
||||
|
||||
XmlSchemaAssociation association = XmlEditorAddInOptions.GetSchemaAssociation(extension); |
||||
if (association != null) { |
||||
prefix = association.NamespacePrefix; |
||||
} |
||||
|
||||
return prefix; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the schema with the specified namespace from the
|
||||
/// user schemas folder and removes the completion data.
|
||||
/// </summary>
|
||||
public static void RemoveUserSchema(string namespaceUri) |
||||
{ |
||||
XmlSchemaCompletionData schemaData = SchemaCompletionDataItems[namespaceUri]; |
||||
if (schemaData != null) { |
||||
if (File.Exists(schemaData.FileName)) { |
||||
File.Delete(schemaData.FileName); |
||||
} |
||||
SchemaCompletionDataItems.Remove(schemaData); |
||||
OnUserSchemaRemoved(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the schema to the user schemas folder and makes the
|
||||
/// schema available to the xml editor.
|
||||
/// </summary>
|
||||
public static void AddUserSchema(XmlSchemaCompletionData schemaData) |
||||
{ |
||||
if (SchemaCompletionDataItems[schemaData.NamespaceUri] == null) { |
||||
|
||||
if (!Directory.Exists(UserSchemaFolder)) { |
||||
Directory.CreateDirectory(UserSchemaFolder); |
||||
} |
||||
|
||||
string fileName = Path.GetFileName(schemaData.FileName); |
||||
string destinationFileName = Path.Combine(UserSchemaFolder, fileName); |
||||
File.Copy(schemaData.FileName, destinationFileName); |
||||
schemaData.FileName = destinationFileName; |
||||
SchemaCompletionDataItems.Add(schemaData); |
||||
OnUserSchemaAdded(); |
||||
} else { |
||||
LoggingService.Warn("Trying to add a schema that already exists. Namespace=" + schemaData.NamespaceUri); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the system and user added schemas.
|
||||
/// </summary>
|
||||
static void ReadSchemas() |
||||
{ |
||||
// MSBuild schemas are in framework directory:
|
||||
ReadSchemas(RuntimeEnvironment.GetRuntimeDirectory(), true); |
||||
ReadSchemas(SchemaFolder, true); |
||||
ReadSchemas(UserSchemaFolder, false); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads all .xsd files in the specified folder.
|
||||
/// </summary>
|
||||
static void ReadSchemas(string folder, bool readOnly) |
||||
{ |
||||
if (Directory.Exists(folder)) { |
||||
foreach (string fileName in Directory.GetFiles(folder, "*.xsd")) { |
||||
ReadSchema(fileName, readOnly); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads an individual schema and adds it to the collection.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the schema namespace exists in the collection it is not added.
|
||||
/// </remarks>
|
||||
static void ReadSchema(string fileName, bool readOnly) |
||||
{ |
||||
try { |
||||
string baseUri = XmlSchemaCompletionData.GetUri(fileName); |
||||
XmlSchemaCompletionData data = new XmlSchemaCompletionData(baseUri, fileName); |
||||
if (data.NamespaceUri != null) { |
||||
if (schemas[data.NamespaceUri] == null) { |
||||
data.ReadOnly = readOnly; |
||||
schemas.Add(data); |
||||
} else { |
||||
// Namespace already exists.
|
||||
LoggingService.Warn("Ignoring duplicate schema namespace " + data.NamespaceUri); |
||||
} |
||||
} else { |
||||
// Namespace is null.
|
||||
LoggingService.Warn("Ignoring schema with no namespace " + data.FileName); |
||||
} |
||||
} catch (Exception ex) { |
||||
LoggingService.Warn("Unable to read schema '" + fileName + "'. ", ex); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the folder where the schemas for all users on the
|
||||
/// local machine are stored.
|
||||
/// </summary>
|
||||
static string SchemaFolder { |
||||
get { |
||||
return Path.Combine(PropertyService.DataDirectory, "schemas"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the folder where schemas are stored for an individual user.
|
||||
/// </summary>
|
||||
static string UserSchemaFolder { |
||||
get { |
||||
return Path.Combine(PropertyService.ConfigDirectory, "schemas"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Should really pass schema info with the event.
|
||||
/// </summary>
|
||||
static void OnUserSchemaAdded() |
||||
{ |
||||
if (UserSchemaAdded != null) { |
||||
UserSchemaAdded(manager, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Should really pass schema info with the event.
|
||||
/// </summary>
|
||||
static void OnUserSchemaRemoved() |
||||
{ |
||||
if (UserSchemaRemoved != null) { |
||||
UserSchemaRemoved(manager, new EventArgs()); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 2164 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Xml; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an XmlText node in the tree.
|
||||
/// </summary>
|
||||
public class XmlTextTreeNode : XmlCharacterDataTreeNode |
||||
{ |
||||
public const string XmlTextTreeNodeImageKey = "XmlTextTreeNodeImage"; |
||||
public const string XmlTextTreeNodeGhostImageKey = "XmlTextTreeNodeGhostImage"; |
||||
|
||||
XmlText xmlText; |
||||
|
||||
public XmlTextTreeNode(XmlText xmlText) |
||||
: base(xmlText) |
||||
{ |
||||
this.xmlText = xmlText; |
||||
ImageKey = XmlTextTreeNodeImageKey; |
||||
SelectedImageKey = ImageKey; |
||||
Update(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the XmlText associated with this tree node.
|
||||
/// </summary>
|
||||
public XmlText XmlText { |
||||
get { |
||||
return xmlText; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether to show the ghost image which is
|
||||
/// displayed when cutting the node.
|
||||
/// </summary>
|
||||
public bool ShowGhostImage { |
||||
get { |
||||
return ImageKey == XmlTextTreeNodeGhostImageKey; |
||||
} |
||||
set { |
||||
if (value) { |
||||
ImageKey = XmlTextTreeNodeGhostImageKey; |
||||
} else { |
||||
ImageKey = XmlTextTreeNodeImageKey; |
||||
} |
||||
SelectedImageKey = ImageKey; |
||||
} |
||||
} |
||||
} |
||||
} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,578 +0,0 @@
@@ -1,578 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision: 2741 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Windows.Forms; |
||||
using System.Xml; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Displays a tree of XML elements. This is a separate control so it can
|
||||
/// be unit tested. It has no SharpDevelop specific parts, for example,
|
||||
/// the context menus are defined in the XmlTreeViewContainerControl.
|
||||
/// </summary>
|
||||
public class XmlTreeViewControl : ExtTreeView |
||||
{ |
||||
const string ViewStatePropertyName = "XmlTreeViewControl.ViewState"; |
||||
|
||||
XmlDocument document; |
||||
|
||||
enum InsertionMode { |
||||
Before = 0, |
||||
After = 1 |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Raised when the delete key is pressed.
|
||||
/// </summary>
|
||||
public event EventHandler DeleteKeyPressed; |
||||
|
||||
public XmlTreeViewControl() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the xml document currently being displayed.
|
||||
/// </summary>
|
||||
[Browsable(false)] |
||||
public XmlDocument Document { |
||||
get { |
||||
return document; |
||||
} |
||||
set { |
||||
document = value; |
||||
|
||||
// Update display.
|
||||
BeginUpdate(); |
||||
try { |
||||
ShowDocument(); |
||||
} finally { |
||||
EndUpdate(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the selected element in the tree.
|
||||
/// </summary>
|
||||
public XmlElement SelectedElement { |
||||
get { |
||||
XmlElementTreeNode xmlElementTreeNode = SelectedElementNode; |
||||
if (xmlElementTreeNode != null) { |
||||
return xmlElementTreeNode.XmlElement; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether an element is selected in the tree.
|
||||
/// </summary>
|
||||
public bool IsElementSelected { |
||||
get { |
||||
return SelectedElement != null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the selected text node in the tree.
|
||||
/// </summary>
|
||||
public XmlText SelectedTextNode { |
||||
get { |
||||
XmlTextTreeNode xmlTextTreeNode = SelectedNode as XmlTextTreeNode; |
||||
if (xmlTextTreeNode != null) { |
||||
return xmlTextTreeNode.XmlText; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the selected comment node in the tree.
|
||||
/// </summary>
|
||||
public XmlComment SelectedComment { |
||||
get { |
||||
XmlCommentTreeNode commentTreeNode = SelectedNode as XmlCommentTreeNode; |
||||
if (commentTreeNode != null) { |
||||
return commentTreeNode.XmlComment; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether a text node is selected in the tree.
|
||||
/// </summary>
|
||||
public bool IsTextNodeSelected { |
||||
get { |
||||
return SelectedTextNode != null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Saves the current state of the tree.
|
||||
/// </summary>
|
||||
public void SaveViewState(Properties properties) |
||||
{ |
||||
properties.Set(ViewStatePropertyName, TreeViewHelper.GetViewStateString(this)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Restores the node state of the tree.
|
||||
/// </summary>
|
||||
public void RestoreViewState(Properties properties) |
||||
{ |
||||
TreeViewHelper.ApplyViewStateString(properties.Get(ViewStatePropertyName, String.Empty), this); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Appends a new child element to the currently selected node.
|
||||
/// </summary>
|
||||
public void AppendChildElement(XmlElement element) |
||||
{ |
||||
XmlElementTreeNode selectedNode = SelectedElementNode; |
||||
if (selectedNode != null) { |
||||
XmlElementTreeNode newNode = new XmlElementTreeNode(element); |
||||
newNode.AddTo(selectedNode); |
||||
selectedNode.Expand(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Appends a new child text node to the currently selected element.
|
||||
/// </summary>
|
||||
public void AppendChildTextNode(XmlText textNode) |
||||
{ |
||||
XmlElementTreeNode selectedNode = SelectedElementNode; |
||||
if (selectedNode != null) { |
||||
XmlTextTreeNode newNode = new XmlTextTreeNode(textNode); |
||||
newNode.AddTo(selectedNode); |
||||
selectedNode.Expand(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a new element node before the currently selected
|
||||
/// node.
|
||||
/// </summary>
|
||||
public void InsertElementBefore(XmlElement element) |
||||
{ |
||||
InsertElement(element, InsertionMode.Before); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a new element node after the currently selected
|
||||
/// node.
|
||||
/// </summary>
|
||||
public void InsertElementAfter(XmlElement element) |
||||
{ |
||||
InsertElement(element, InsertionMode.After); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the specified element from the tree.
|
||||
/// </summary>
|
||||
public void RemoveElement(XmlElement element) |
||||
{ |
||||
XmlElementTreeNode node = FindElement(element); |
||||
if (node != null) { |
||||
node.Remove(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the specified text node from the tree.
|
||||
/// </summary>
|
||||
public void RemoveTextNode(XmlText textNode) |
||||
{ |
||||
XmlTextTreeNode node = FindTextNode(textNode); |
||||
if (node != null) { |
||||
node.Remove(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a text node before the currently selected
|
||||
/// node.
|
||||
/// </summary>
|
||||
public void InsertTextNodeBefore(XmlText textNode) |
||||
{ |
||||
InsertTextNode(textNode, InsertionMode.Before); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a text node after the currently selected
|
||||
/// node.
|
||||
/// </summary>
|
||||
public void InsertTextNodeAfter(XmlText textNode) |
||||
{ |
||||
InsertTextNode(textNode, InsertionMode.After); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the corresponding tree node's text based on
|
||||
/// the textNode's value.
|
||||
/// </summary>
|
||||
public void UpdateTextNode(XmlText textNode) |
||||
{ |
||||
XmlTextTreeNode node = FindTextNode(textNode); |
||||
if (node != null) { |
||||
node.Update(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the corresponding tree node's text based on
|
||||
/// the comment's value.
|
||||
/// </summary>
|
||||
public void UpdateComment(XmlComment comment) |
||||
{ |
||||
XmlCommentTreeNode node = FindComment(comment); |
||||
if (node != null) { |
||||
node.Update(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Appends a new child comment node to the currently selected element.
|
||||
/// </summary>
|
||||
public void AppendChildComment(XmlComment comment) |
||||
{ |
||||
XmlElementTreeNode selectedNode = SelectedElementNode; |
||||
if (selectedNode != null) { |
||||
XmlCommentTreeNode newNode = new XmlCommentTreeNode(comment); |
||||
newNode.AddTo(selectedNode); |
||||
selectedNode.Expand(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the specified comment from the tree.
|
||||
/// </summary>
|
||||
public void RemoveComment(XmlComment comment) |
||||
{ |
||||
XmlCommentTreeNode node = FindComment(comment); |
||||
if (node != null) { |
||||
node.Remove(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a comment node before the currently selected
|
||||
/// node.
|
||||
/// </summary>
|
||||
public void InsertCommentBefore(XmlComment comment) |
||||
{ |
||||
InsertComment(comment, InsertionMode.Before); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a comment node after the currently selected
|
||||
/// node.
|
||||
/// </summary>
|
||||
public void InsertCommentAfter(XmlComment comment) |
||||
{ |
||||
InsertComment(comment, InsertionMode.After); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the image so the corresponding tree node shows that
|
||||
/// it is in the process of being cut.
|
||||
/// </summary>
|
||||
public void ShowCut(XmlNode node) |
||||
{ |
||||
ShowCut(node, true); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the image so the corresponding tree node no longer
|
||||
/// shows it is in the process of being cut.
|
||||
/// </summary>
|
||||
public void HideCut(XmlNode node) |
||||
{ |
||||
ShowCut(node, false); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If no node is selected after a mouse click then we make
|
||||
/// sure the AfterSelect event is fired. Standard behaviour is
|
||||
/// for the AfterSelect event not to be fired when the user
|
||||
/// deselects all tree nodes.
|
||||
/// </summary>
|
||||
protected override void OnMouseDown(MouseEventArgs e) |
||||
{ |
||||
base.OnMouseDown(e); |
||||
if (SelectedNode == null) { |
||||
this.OnAfterSelect(new TreeViewEventArgs(null, TreeViewAction.ByMouse)); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Raises the DeleteKeyPressed event.
|
||||
/// </summary>
|
||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) |
||||
{ |
||||
if (keyData == Keys.Delete && DeleteKeyPressed != null) { |
||||
DeleteKeyPressed(this, new EventArgs()); |
||||
} |
||||
return base.ProcessCmdKey(ref msg, keyData); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Displays the document in the xml tree.
|
||||
/// </summary>
|
||||
void ShowDocument() |
||||
{ |
||||
Nodes.Clear(); |
||||
if (document != null) { |
||||
foreach (XmlNode node in document.ChildNodes) { |
||||
switch (node.NodeType) { |
||||
case XmlNodeType.Element: |
||||
XmlElementTreeNode elementNode = new XmlElementTreeNode((XmlElement)node); |
||||
elementNode.AddTo(this); |
||||
break; |
||||
case XmlNodeType.Comment: |
||||
XmlCommentTreeNode commentNode = new XmlCommentTreeNode((XmlComment)node); |
||||
commentNode.AddTo(this); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the selected xml element tree node.
|
||||
/// </summary>
|
||||
XmlElementTreeNode SelectedElementNode { |
||||
get { |
||||
return SelectedNode as XmlElementTreeNode; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a new element node either before or after the
|
||||
/// currently selected element node.
|
||||
/// </summary>
|
||||
void InsertElement(XmlElement element, InsertionMode insertionMode) |
||||
{ |
||||
ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode; |
||||
if (selectedNode != null) { |
||||
XmlElementTreeNode parentNode = (XmlElementTreeNode)selectedNode.Parent; |
||||
XmlElementTreeNode newNode = new XmlElementTreeNode(element); |
||||
int index = parentNode.Nodes.IndexOf(selectedNode); |
||||
if (insertionMode == InsertionMode.After) { |
||||
index++; |
||||
} |
||||
newNode.Insert(index, parentNode); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a new text node either before or after the
|
||||
/// currently selected node.
|
||||
/// </summary>
|
||||
void InsertTextNode(XmlText textNode, InsertionMode insertionMode) |
||||
{ |
||||
ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode; |
||||
if (selectedNode != null) { |
||||
XmlElementTreeNode parentNode = (XmlElementTreeNode)selectedNode.Parent; |
||||
XmlTextTreeNode newNode = new XmlTextTreeNode(textNode); |
||||
int index = parentNode.Nodes.IndexOf(selectedNode); |
||||
if (insertionMode == InsertionMode.After) { |
||||
index++; |
||||
} |
||||
newNode.Insert(index, parentNode); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts a new comment node either before or after the
|
||||
/// currently selected node.
|
||||
/// </summary>
|
||||
void InsertComment(XmlComment comment, InsertionMode insertionMode) |
||||
{ |
||||
ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode; |
||||
if (selectedNode != null) { |
||||
ExtTreeNode parentNode = (ExtTreeNode)selectedNode.Parent; |
||||
XmlCommentTreeNode newNode = new XmlCommentTreeNode(comment); |
||||
int index = 0; |
||||
if (parentNode != null) { |
||||
index = parentNode.Nodes.IndexOf(selectedNode); |
||||
} else { |
||||
index = Nodes.IndexOf(selectedNode); |
||||
} |
||||
if (insertionMode == InsertionMode.After) { |
||||
index++; |
||||
} |
||||
if (parentNode != null) { |
||||
newNode.Insert(index, parentNode); |
||||
} else { |
||||
newNode.Insert(index, this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Looks at all the nodes in the tree view and returns the
|
||||
/// tree node that represents the specified element.
|
||||
/// </summary>
|
||||
XmlElementTreeNode FindElement(XmlElement element, TreeNodeCollection nodes) |
||||
{ |
||||
foreach (ExtTreeNode node in nodes) { |
||||
XmlElementTreeNode elementTreeNode = node as XmlElementTreeNode; |
||||
if (elementTreeNode != null) { |
||||
if (elementTreeNode.XmlElement == element) { |
||||
return elementTreeNode; |
||||
} |
||||
|
||||
// Look for a match in the element's child nodes.
|
||||
XmlElementTreeNode childElementTreeNode = FindElement(element, elementTreeNode.Nodes); |
||||
if (childElementTreeNode != null) { |
||||
return childElementTreeNode; |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Finds the corresponding XmlElementTreeNode.
|
||||
/// </summary>
|
||||
XmlElementTreeNode FindElement(XmlElement element) |
||||
{ |
||||
XmlElementTreeNode selectedElementTreeNode = SelectedNode as XmlElementTreeNode; |
||||
if (selectedElementTreeNode != null && selectedElementTreeNode.XmlElement == element) { |
||||
return selectedElementTreeNode; |
||||
} else { |
||||
return FindElement(element, Nodes); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Looks at all the nodes in the tree view and returns the
|
||||
/// tree node that represents the specified text node.
|
||||
/// </summary>
|
||||
XmlTextTreeNode FindTextNode(XmlText textNode, TreeNodeCollection nodes) |
||||
{ |
||||
foreach (ExtTreeNode node in nodes) { |
||||
XmlTextTreeNode textTreeNode = node as XmlTextTreeNode; |
||||
if (textTreeNode != null) { |
||||
if (textTreeNode.XmlText == textNode) { |
||||
return textTreeNode; |
||||
} |
||||
} else { |
||||
// Look for a match in the node's child nodes.
|
||||
XmlTextTreeNode childTextTreeNode = FindTextNode(textNode, node.Nodes); |
||||
if (childTextTreeNode != null) { |
||||
return childTextTreeNode; |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Finds the specified text node in the tree.
|
||||
/// </summary>
|
||||
XmlTextTreeNode FindTextNode(XmlText textNode) |
||||
{ |
||||
XmlTextTreeNode selectedTextTreeNode = SelectedNode as XmlTextTreeNode; |
||||
if (selectedTextTreeNode != null && selectedTextTreeNode.XmlText == textNode) { |
||||
return selectedTextTreeNode; |
||||
} else { |
||||
return FindTextNode(textNode, Nodes); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Looks at all the nodes in the tree view and returns the
|
||||
/// tree node that represents the specified comment node.
|
||||
/// </summary>
|
||||
XmlCommentTreeNode FindComment(XmlComment comment, TreeNodeCollection nodes) |
||||
{ |
||||
foreach (ExtTreeNode node in nodes) { |
||||
XmlCommentTreeNode commentTreeNode = node as XmlCommentTreeNode; |
||||
if (commentTreeNode != null) { |
||||
if (commentTreeNode.XmlComment == comment) { |
||||
return commentTreeNode; |
||||
} |
||||
} else { |
||||
// Look for a match in the node's child nodes.
|
||||
XmlCommentTreeNode childCommentTreeNode = FindComment(comment, node.Nodes); |
||||
if (childCommentTreeNode != null) { |
||||
return childCommentTreeNode; |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Locates the specified comment in the tree.
|
||||
/// </summary>
|
||||
XmlCommentTreeNode FindComment(XmlComment comment) |
||||
{ |
||||
XmlCommentTreeNode selectedCommentTreeNode = SelectedNode as XmlCommentTreeNode; |
||||
if (selectedCommentTreeNode != null && selectedCommentTreeNode.XmlComment == comment) { |
||||
return selectedCommentTreeNode; |
||||
} else { |
||||
return FindComment(comment, Nodes); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the corresponding tree node with the ghosted image
|
||||
/// that indicates it is being cut.
|
||||
/// </summary>
|
||||
void ShowCutElement(XmlElement element, bool showGhostImage) |
||||
{ |
||||
XmlElementTreeNode node = FindElement(element); |
||||
node.ShowGhostImage = showGhostImage; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the corresponding tree node with the ghosted image
|
||||
/// that indicates it is being cut.
|
||||
/// </summary>
|
||||
void ShowCutTextNode(XmlText textNode, bool showGhostImage) |
||||
{ |
||||
XmlTextTreeNode node = FindTextNode(textNode); |
||||
node.ShowGhostImage = showGhostImage; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the corresponding tree node with the ghosted image
|
||||
/// that indicates it is being cut.
|
||||
/// </summary>
|
||||
void ShowCutComment(XmlComment comment, bool showGhostImage) |
||||
{ |
||||
XmlCommentTreeNode node = FindComment(comment); |
||||
node.ShowGhostImage = showGhostImage; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the cut node with a ghost image.
|
||||
/// </summary>
|
||||
/// <param name="showGhostImage">True if the node should be
|
||||
/// shown with the ghost image.</param>
|
||||
void ShowCut(XmlNode node, bool showGhostImage) |
||||
{ |
||||
if (node is XmlElement) { |
||||
ShowCutElement((XmlElement)node, showGhostImage); |
||||
} else if (node is XmlText) { |
||||
ShowCutTextNode((XmlText)node, showGhostImage); |
||||
} else if (node is XmlComment) { |
||||
ShowCutComment((XmlComment)node, showGhostImage); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Description of MockXmlViewContent.
|
||||
/// </summary>
|
||||
public class MockXmlViewContent : AbstractViewContent, IFileDocumentProvider |
||||
{ |
||||
AvalonEditDocumentAdapter document; |
||||
|
||||
public MockXmlViewContent() |
||||
{ |
||||
this.document = new AvalonEditDocumentAdapter(); |
||||
} |
||||
|
||||
public override object Control { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IDocument GetDocumentForFile(OpenedFile file) |
||||
{ |
||||
return document; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue