/// <summary> /// Updates the configured file extension to namespace mappings. /// </summary> void UpdateSchemaAssociations() { foreach (XmlSchemaAssociationListBoxItem item in fileExtensionComboBox.Items) { if (item.IsDirty) { XmlSchemaAssociation association = new XmlSchemaAssociation(item.Extension, item.NamespaceUri, item.NamespacePrefix); XmlEditorAddInOptions.SetSchemaAssociation(association); } } }
/// <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> /// 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> /// Reads the configured xml file extensions and their associated namespaces. /// </summary> void PopulateFileExtensionComboBox() { string [] extensions = XmlView.GetXmlFileExtensions(); foreach (string extension in extensions) { XmlSchemaAssociation association = XmlEditorAddInOptions.GetSchemaAssociation(extension); XmlSchemaAssociationListBoxItem item = new XmlSchemaAssociationListBoxItem(association.Extension, association.NamespaceUri, association.NamespacePrefix); fileExtensionComboBox.Items.Add(item); } if (fileExtensionComboBox.Items.Count > 0) { fileExtensionComboBox.SelectedIndex = 0; FileExtensionComboBoxSelectedIndexChanged(this, new EventArgs()); } }
/// <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); }
/// <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()); }
/// <summary> /// Updates the configured file extension to namespace mappings. /// </summary> void UpdateSchemaAssociations() { foreach (XmlSchemaAssociationListBoxItem item in fileExtensionComboBox.Items) { if (item.IsDirty) { XmlSchemaAssociation association = new XmlSchemaAssociation(item.Extension, item.NamespaceUri, item.NamespacePrefix); XmlEditorAddInOptions.SetSchemaAssociation(association); } } }
public static void SetSchemaAssociation(XmlSchemaAssociation association) { Properties.Set("ext" + association.Extension, association.ConvertToString()); }
/// <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; }