Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/addins/Xml/Editor/XmlTextEditorExtension.cs')
-rw-r--r--main/src/addins/Xml/Editor/XmlTextEditorExtension.cs683
1 files changed, 446 insertions, 237 deletions
diff --git a/main/src/addins/Xml/Editor/XmlTextEditorExtension.cs b/main/src/addins/Xml/Editor/XmlTextEditorExtension.cs
index 58790e1276..d04db17fd2 100644
--- a/main/src/addins/Xml/Editor/XmlTextEditorExtension.cs
+++ b/main/src/addins/Xml/Editor/XmlTextEditorExtension.cs
@@ -32,17 +32,19 @@ using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
-using Mono.TextEditor;
-
using MonoDevelop.Components.Commands;
using MonoDevelop.Core;
using MonoDevelop.Ide;
using MonoDevelop.Ide.CodeCompletion;
using MonoDevelop.Ide.Gui.Content;
using MonoDevelop.Ide.Tasks;
+using MonoDevelop.Ide;
+using MonoDevelop.Ide.CodeFormatting;
+using MonoDevelop.Ide.Editor;
using MonoDevelop.Xml.Completion;
using MonoDevelop.Xml.Dom;
using MonoDevelop.Xml.Parser;
+using MonoDevelop.Ide.Editor.Extension;
namespace MonoDevelop.Xml.Editor
{
@@ -56,12 +58,12 @@ namespace MonoDevelop.Xml.Editor
InferredXmlCompletionProvider inferredCompletionData;
bool inferenceQueued;
- public override bool ExtendsEditor (MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
+ public override bool IsValidInContext (DocumentContext context)
{
- return IsFileNameHandled (doc.Name) && base.ExtendsEditor (doc, editor);
+ return IsFileNameHandled (context.Name) && base.IsValidInContext (context);
}
- public override void Initialize ()
+ protected override void Initialize ()
{
base.Initialize ();
XmlEditorOptions.XmlFileAssociationChanged += HandleXmlFileAssociationChanged;
@@ -69,16 +71,16 @@ namespace MonoDevelop.Xml.Editor
XmlSchemaManager.UserSchemaRemoved += UserSchemaRemoved;
SetDefaultSchema ();
- var view = Document.GetContent<MonoDevelop.SourceEditor.SourceEditorView> ();
- if (view != null && string.IsNullOrEmpty (view.Document.MimeType)) {
- view.Document.MimeType = ApplicationXmlMimeType;
- Document.ReparseDocument ();
+ //var view = Document.GetContent<MonoDevelop.SourceEditor.SourceEditorView> ();
+ if (string.IsNullOrEmpty (Editor.MimeType)) {
+ Editor.MimeType = ApplicationXmlMimeType;
+ DocumentContext.ReparseDocument ();
}
}
void HandleXmlFileAssociationChanged (object sender, XmlFileAssociationChangedEventArgs e)
{
- var filename = document.FileName;
+ var filename = DocumentContext.Name;
if (filename != null && filename.ToString ().EndsWith (e.Extension, StringComparison.Ordinal))
SetDefaultSchema ();
}
@@ -89,7 +91,8 @@ namespace MonoDevelop.Xml.Editor
if (!disposed) {
disposed = false;
XmlEditorOptions.XmlFileAssociationChanged -= HandleXmlFileAssociationChanged;
- XmlSchemaManager.UserSchemaAdded -= UserSchemaAdded;
+ XmlSchemaManager.UserSchemaAdded -= UserSchemaAdded;
+
XmlSchemaManager.UserSchemaRemoved -= UserSchemaRemoved;
base.Dispose ();
}
@@ -108,18 +111,23 @@ namespace MonoDevelop.Xml.Editor
protected override void GetElementCompletions (CompletionDataList list)
{
- var path = GetElementPath ();
+ var path = GetElementPath ();
+
if (path.Elements.Count > 0) {
IXmlCompletionProvider schema = FindSchema (path);
if (schema == null)
- schema = inferredCompletionData;
- if (schema != null) {
+ schema = inferredCompletionData;
+
+ if (schema != null) {
+
var completionData = schema.GetChildElementCompletionData (path);
if (completionData != null)
list.AddRange (completionData);
- }
+ }
+
} else if (defaultSchemaCompletionData != null) {
- list.AddRange (defaultSchemaCompletionData.GetElementCompletionData (defaultNamespacePrefix));
+ list.AddRange (defaultSchemaCompletionData.GetElementCompletionData (defaultNamespacePrefix));
+
} else if (inferredCompletionData != null) {
list.AddRange (inferredCompletionData.GetElementCompletionData ());
}
@@ -129,12 +137,15 @@ namespace MonoDevelop.Xml.Editor
protected override CompletionDataList GetAttributeCompletions (IAttributedXObject attributedOb,
Dictionary<string, string> existingAtts)
{
- var path = GetElementPath ();
+ var path = GetElementPath ();
+
if (path.Elements.Count > 0) {
IXmlCompletionProvider schema = FindSchema (path);
if (schema == null)
- schema = inferredCompletionData;
- if (schema != null)
+ schema = inferredCompletionData;
+
+ if (schema != null)
+
return schema.GetAttributeCompletionData (path);
}
return null;
@@ -142,10 +153,13 @@ namespace MonoDevelop.Xml.Editor
protected override CompletionDataList GetAttributeValueCompletions (IAttributedXObject attributedOb, XAttribute att)
{
- var path = GetElementPath ();
+ var path = GetElementPath ();
+
if (path.Elements.Count > 0) {
- var schema = FindSchema (path);
- if (schema != null)
+ var schema = FindSchema (path);
+
+ if (schema != null)
+
return schema.GetAttributeValueCompletionData (path, att.Name.FullName);
}
return null;
@@ -170,47 +184,79 @@ namespace MonoDevelop.Xml.Editor
return FindSchema (XmlSchemaManager.SchemaCompletionDataItems, path);
}
- /// <summary>
- /// Finds the schema given the xml element path.
- /// </summary>
- public XmlSchemaCompletionData FindSchema (IXmlSchemaCompletionDataCollection schemaCompletionDataItems, XmlElementPath path)
- {
- if (path.Elements.Count > 0) {
- string namespaceUri = path.Elements[0].Namespace;
- if (namespaceUri.Length > 0) {
- return schemaCompletionDataItems[namespaceUri];
- } else if (defaultSchemaCompletionData != null) {
-
- // Use the default schema namespace if none
- // specified in a xml element path, otherwise
- // we will not find any attribute or element matches
- // later.
- foreach (QualifiedName name in path.Elements) {
- if (name.Namespace.Length == 0) {
- name.Namespace = defaultSchemaCompletionData.NamespaceUri;
- }
- }
- return defaultSchemaCompletionData;
- }
- }
- return null;
+ /// <summary>
+
+ /// Finds the schema given the xml element path.
+
+ /// </summary>
+
+ public XmlSchemaCompletionData FindSchema (IXmlSchemaCompletionDataCollection schemaCompletionDataItems, XmlElementPath path)
+
+ {
+
+ if (path.Elements.Count > 0) {
+
+ string namespaceUri = path.Elements[0].Namespace;
+
+ if (namespaceUri.Length > 0) {
+
+ return schemaCompletionDataItems[namespaceUri];
+
+ } else if (defaultSchemaCompletionData != null) {
+
+
+
+ // Use the default schema namespace if none
+
+ // specified in a xml element path, otherwise
+
+ // we will not find any attribute or element matches
+
+ // later.
+
+ foreach (QualifiedName name in path.Elements) {
+
+ if (name.Namespace.Length == 0) {
+
+ name.Namespace = defaultSchemaCompletionData.NamespaceUri;
+
+ }
+
+ }
+
+ return defaultSchemaCompletionData;
+
+ }
+
+ }
+
+ return null;
+
}
#endregion
#region Schema resolution
- /// <summary>
- /// Gets the XmlSchemaObject that defines the currently selected xml element or attribute.
- /// </summary>
+ /// <summary>
+
+ /// Gets the XmlSchemaObject that defines the currently selected xml element or attribute.
+
+ /// </summary>
+
/// <param name="currentSchemaCompletionData">This is the schema completion data for the schema currently being
- /// displayed. This can be null if the document is not a schema.</param>
- public XmlSchemaObject GetSchemaObjectSelected (XmlSchemaCompletionData currentSchemaCompletionData)
- {
- // Find element under cursor.
+ /// displayed. This can be null if the document is not a schema.</param>
+
+ public XmlSchemaObject GetSchemaObjectSelected (XmlSchemaCompletionData currentSchemaCompletionData)
+
+ {
+
+ // Find element under cursor.
+
XmlElementPath path = GetElementPath ();
- //attribute name under cursor, if valid
+ //attribute name under cursor, if valid
+
string attributeName = null;
XAttribute xatt = Tracker.Engine.Nodes.Peek (0) as XAttribute;
if (xatt != null) {
@@ -219,173 +265,306 @@ namespace MonoDevelop.Xml.Editor
xattName = GetCompleteName ();
}
attributeName = xattName.FullName;
- }
+ }
+
- // Find schema definition object.
- XmlSchemaCompletionData schemaCompletionData = FindSchema (path);
- XmlSchemaObject schemaObject = null;
+ // Find schema definition object.
+
+ XmlSchemaCompletionData schemaCompletionData = FindSchema (path);
+
+ XmlSchemaObject schemaObject = null;
+
if (schemaCompletionData != null) {
- XmlSchemaElement element = schemaCompletionData.FindElement(path);
- schemaObject = element;
+ XmlSchemaElement element = schemaCompletionData.FindElement(path);
+
+ schemaObject = element;
+
if (element != null) {
if (!string.IsNullOrEmpty (attributeName)) {
- XmlSchemaAttribute attribute = schemaCompletionData.FindAttribute(element, attributeName);
+ XmlSchemaAttribute attribute = schemaCompletionData.FindAttribute(element, attributeName);
+
if (attribute != null) {
- if (currentSchemaCompletionData != null) {
- schemaObject = GetSchemaObjectReferenced (currentSchemaCompletionData, element, attribute);
- } else {
- schemaObject = attribute;
- }
- }
- }
- return schemaObject;
- }
- }
- return null;
- }
-
- /// <summary>
- /// If the attribute value found references another item in the schema
- /// return this instead of the attribute schema object. For example, if the
- /// user can select the attribute value and the code will work out the schema object pointed to by the ref
- /// or type attribute:
- ///
- /// xs:element ref="ref-name"
- /// xs:attribute type="type-name"
- /// </summary>
- /// <returns>
- /// The <paramref name="attribute"/> if no schema object was referenced.
- /// </returns>
- XmlSchemaObject GetSchemaObjectReferenced (XmlSchemaCompletionData currentSchemaCompletionData, XmlSchemaElement element, XmlSchemaAttribute attribute)
- {
- XmlSchemaObject schemaObject = null;
- if (IsXmlSchemaNamespace(element)) {
+ if (currentSchemaCompletionData != null) {
+
+ schemaObject = GetSchemaObjectReferenced (currentSchemaCompletionData, element, attribute);
+
+ } else {
+
+ schemaObject = attribute;
+
+ }
+
+ }
+
+ }
+
+ return schemaObject;
+
+ }
+
+ }
+
+ return null;
+
+ }
+
+ /// <summary>
+
+ /// If the attribute value found references another item in the schema
+
+ /// return this instead of the attribute schema object. For example, if the
+
+ /// user can select the attribute value and the code will work out the schema object pointed to by the ref
+
+ /// or type attribute:
+
+ ///
+
+ /// xs:element ref="ref-name"
+
+ /// xs:attribute type="type-name"
+
+ /// </summary>
+
+ /// <returns>
+
+ /// The <paramref name="attribute"/> if no schema object was referenced.
+
+ /// </returns>
+
+ XmlSchemaObject GetSchemaObjectReferenced (XmlSchemaCompletionData currentSchemaCompletionData, XmlSchemaElement element, XmlSchemaAttribute attribute)
+
+ {
+
+ XmlSchemaObject schemaObject = null;
+
+ if (IsXmlSchemaNamespace(element)) {
+
// Find attribute value.
- //fixme implement
- string attributeValue = "";// XmlParser.GetAttributeValueAtIndex(xml, index);
- if (attributeValue.Length == 0) {
- return attribute;
- }
-
- if (attribute.Name == "ref") {
- schemaObject = FindSchemaObjectReference(attributeValue, currentSchemaCompletionData, element.Name);
- } else if (attribute.Name == "type") {
- schemaObject = FindSchemaObjectType(attributeValue, currentSchemaCompletionData, element.Name);
- }
- }
-
- if (schemaObject != null) {
- return schemaObject;
- }
- return attribute;
- }
-
- /// <summary>
- /// Checks whether the element belongs to the XSD namespace.
- /// </summary>
- static bool IsXmlSchemaNamespace (XmlSchemaElement element)
- {
- XmlQualifiedName qualifiedName = element.QualifiedName;
- if (qualifiedName != null) {
- return XmlSchemaManager.IsXmlSchemaNamespace (qualifiedName.Namespace);
- }
- return false;
- }
-
- /// <summary>
- /// Attempts to locate the reference name in the specified schema.
- /// </summary>
- /// <param name="name">The reference to look up.</param>
- /// <param name="schemaCompletionData">The schema completion data to use to
- /// find the reference.</param>
- /// <param name="elementName">The element to determine what sort of reference it is
- /// (e.g. group, attribute, element).</param>
- /// <returns><see langword="null"/> if no match can be found.</returns>
- XmlSchemaObject FindSchemaObjectReference(string name, XmlSchemaCompletionData schemaCompletionData, string elementName)
- {
- QualifiedName qualifiedName = schemaCompletionData.CreateQualifiedName(name);
- XmlSchemaCompletionData qualifiedNameSchema = FindSchema(qualifiedName.Namespace);
- if (qualifiedNameSchema != null) {
- schemaCompletionData = qualifiedNameSchema;
- }
- switch (elementName) {
- case "element":
- return schemaCompletionData.FindElement(qualifiedName);
- case "attribute":
- return schemaCompletionData.FindAttribute(qualifiedName.Name);
- case "group":
- return schemaCompletionData.FindGroup(qualifiedName.Name);
- case "attributeGroup":
- return schemaCompletionData.FindAttributeGroup(qualifiedName.Name);
- }
- return null;
- }
-
- /// <summary>
- /// Attempts to locate the type name in the specified schema.
- /// </summary>
- /// <param name="name">The type to look up.</param>
- /// <param name="schemaCompletionData">The schema completion data to use to
- /// find the type.</param>
- /// <param name="elementName">The element to determine what sort of type it is
- /// (e.g. group, attribute, element).</param>
- /// <returns><see langword="null"/> if no match can be found.</returns>
- XmlSchemaObject FindSchemaObjectType(string name, XmlSchemaCompletionData schemaCompletionData, string elementName)
- {
- QualifiedName qualifiedName = schemaCompletionData.CreateQualifiedName(name);
- XmlSchemaCompletionData qualifiedNameSchema = FindSchema(qualifiedName.Namespace);
- if (qualifiedNameSchema != null) {
- schemaCompletionData = qualifiedNameSchema;
- }
- switch (elementName) {
- case "element":
- return schemaCompletionData.FindComplexType(qualifiedName);
- case "attribute":
- return schemaCompletionData.FindSimpleType(qualifiedName.Name);
- }
- return null;
+ //fixme implement
+
+ string attributeValue = "";// XmlParser.GetAttributeValueAtIndex(xml, index);
+
+ if (attributeValue.Length == 0) {
+
+ return attribute;
+
+ }
+
+
+
+ if (attribute.Name == "ref") {
+
+ schemaObject = FindSchemaObjectReference(attributeValue, currentSchemaCompletionData, element.Name);
+
+ } else if (attribute.Name == "type") {
+
+ schemaObject = FindSchemaObjectType(attributeValue, currentSchemaCompletionData, element.Name);
+
+ }
+
+ }
+
+
+
+ if (schemaObject != null) {
+
+ return schemaObject;
+
+ }
+
+ return attribute;
+
+ }
+
+ /// <summary>
+
+ /// Checks whether the element belongs to the XSD namespace.
+
+ /// </summary>
+
+ static bool IsXmlSchemaNamespace (XmlSchemaElement element)
+
+ {
+
+ XmlQualifiedName qualifiedName = element.QualifiedName;
+
+ if (qualifiedName != null) {
+
+ return XmlSchemaManager.IsXmlSchemaNamespace (qualifiedName.Namespace);
+
+ }
+
+ return false;
+
+ }
+
+ /// <summary>
+
+ /// Attempts to locate the reference name in the specified schema.
+
+ /// </summary>
+
+ /// <param name="name">The reference to look up.</param>
+
+ /// <param name="schemaCompletionData">The schema completion data to use to
+
+ /// find the reference.</param>
+
+ /// <param name="elementName">The element to determine what sort of reference it is
+
+ /// (e.g. group, attribute, element).</param>
+
+ /// <returns><see langword="null"/> if no match can be found.</returns>
+
+ XmlSchemaObject FindSchemaObjectReference(string name, XmlSchemaCompletionData schemaCompletionData, string elementName)
+
+ {
+
+ QualifiedName qualifiedName = schemaCompletionData.CreateQualifiedName(name);
+
+ XmlSchemaCompletionData qualifiedNameSchema = FindSchema(qualifiedName.Namespace);
+
+ if (qualifiedNameSchema != null) {
+
+ schemaCompletionData = qualifiedNameSchema;
+
+ }
+
+ switch (elementName) {
+
+ case "element":
+
+ return schemaCompletionData.FindElement(qualifiedName);
+
+ case "attribute":
+
+ return schemaCompletionData.FindAttribute(qualifiedName.Name);
+
+ case "group":
+
+ return schemaCompletionData.FindGroup(qualifiedName.Name);
+
+ case "attributeGroup":
+
+ return schemaCompletionData.FindAttributeGroup(qualifiedName.Name);
+
+ }
+
+ return null;
+
+ }
+
+
+
+ /// <summary>
+
+ /// Attempts to locate the type name in the specified schema.
+
+ /// </summary>
+
+ /// <param name="name">The type to look up.</param>
+
+ /// <param name="schemaCompletionData">The schema completion data to use to
+
+ /// find the type.</param>
+
+ /// <param name="elementName">The element to determine what sort of type it is
+
+ /// (e.g. group, attribute, element).</param>
+
+ /// <returns><see langword="null"/> if no match can be found.</returns>
+
+ XmlSchemaObject FindSchemaObjectType(string name, XmlSchemaCompletionData schemaCompletionData, string elementName)
+
+ {
+
+ QualifiedName qualifiedName = schemaCompletionData.CreateQualifiedName(name);
+
+ XmlSchemaCompletionData qualifiedNameSchema = FindSchema(qualifiedName.Namespace);
+
+ if (qualifiedNameSchema != null) {
+
+ schemaCompletionData = qualifiedNameSchema;
+
+ }
+
+ switch (elementName) {
+
+ case "element":
+
+ return schemaCompletionData.FindComplexType(qualifiedName);
+
+ case "attribute":
+
+ return schemaCompletionData.FindSimpleType(qualifiedName.Name);
+
+ }
+
+ return null;
+
}
#endregion
#region Settings handling
- void SetDefaultSchema ()
+ void SetDefaultSchema ()
+
{
- var filename = document.FileName;
+ var filename = DocumentContext.Name;
if (filename == null)
return;
-
+
+
defaultSchemaCompletionData = XmlSchemaManager.GetSchemaCompletionDataForFileName (filename);
if (defaultSchemaCompletionData != null)
inferredCompletionData = null;
else
- QueueInference ();
- defaultNamespacePrefix = XmlSchemaManager.GetNamespacePrefixForFileName (filename);
- }
-
- /// Updates the default schema association since the schema may have been added.
- void UserSchemaAdded (object source, EventArgs e)
+ QueueInference ();
+
+ defaultNamespacePrefix = XmlSchemaManager.GetNamespacePrefixForFileName (filename);
+
+ }
+
+
+
+ /// Updates the default schema association since the schema may have been added.
+
+ void UserSchemaAdded (object source, EventArgs e)
+
{
SetDefaultSchema ();
- }
-
- // Updates the default schema association since the schema may have been removed.
- void UserSchemaRemoved (object source, EventArgs e)
- {
- SetDefaultSchema ();
+ }
+
+
+
+ // Updates the default schema association since the schema may have been removed.
+
+ void UserSchemaRemoved (object source, EventArgs e)
+
+ {
+
+ SetDefaultSchema ();
+
}
#endregion
#region Stylesheet handling
- /// <summary>
- /// Gets or sets the stylesheet associated with this xml file.
- /// </summary>
- public string StylesheetFileName {
- get { return stylesheetFileName; }
- set { stylesheetFileName = value; }
+ /// <summary>
+
+ /// Gets or sets the stylesheet associated with this xml file.
+
+ /// </summary>
+
+ public string StylesheetFileName {
+
+ get { return stylesheetFileName; }
+
+ set { stylesheetFileName = value; }
+
}
#endregion
@@ -430,16 +609,17 @@ namespace MonoDevelop.Xml.Editor
#region Smart indent
- public override bool KeyPress (Gdk.Key key, char keyChar, Gdk.ModifierType modifier)
+ public override bool KeyPress (KeyDescriptor descriptor)
{
bool result;
-
- if (Document.Editor.Options.IndentStyle == IndentStyle.Smart && key == Gdk.Key.Return) {
- result = base.KeyPress (key, keyChar, modifier);
- SmartIndentLine (Editor.Caret.Line);
+
+
+ if (Editor.Options.IndentStyle == IndentStyle.Smart && descriptor.SpecialKey == SpecialKey.Return) {
+ result = base.KeyPress (descriptor);
+ SmartIndentLine (Editor.CaretLine);
return result;
}
- return base.KeyPress (key, keyChar, modifier);
+ return base.KeyPress (descriptor);
}
void SmartIndentLine (int line)
@@ -500,8 +680,10 @@ namespace MonoDevelop.Xml.Editor
[CommandHandler (XmlCommands.CreateSchema)]
public void CreateSchemaCommand ()
{
- try {
- TaskService.Errors.Clear ();
+ try {
+
+ TaskService.Errors.Clear ();
+
string xml = Editor.Text;
using (ProgressMonitor monitor = XmlEditorService.GetMonitor ()) {
XmlDocument doc = XmlEditorService.ValidateWellFormedness (monitor, xml, FileName);
@@ -509,7 +691,8 @@ namespace MonoDevelop.Xml.Editor
return;
monitor.BeginTask (GettextCatalog.GetString ("Creating schema..."), 0);
try {
- string schema = XmlEditorService.CreateSchema (Document, xml);
+ string schema = XmlEditorService.CreateSchema (Editor, xml);
+
string fileName = XmlEditorService.GenerateFileName (FileName, "{0}.xsd");
IdeApp.Workbench.NewDocument (fileName, "application/xml", schema);
monitor.ReportSuccess (GettextCatalog.GetString ("Schema created."));
@@ -518,22 +701,30 @@ namespace MonoDevelop.Xml.Editor
LoggingService.LogError (msg, ex);
monitor.ReportError (msg, ex);
}
- }
- } catch (Exception ex) {
- MessageService.ShowError (ex.Message);
+ }
+
+ } catch (Exception ex) {
+
+ MessageService.ShowError (ex.Message);
+
}
}
[CommandHandler (XmlCommands.OpenStylesheet)]
public void OpenStylesheetCommand ()
- {
- if (!string.IsNullOrEmpty (stylesheetFileName)) {
- try {
- IdeApp.Workbench.OpenDocument (stylesheetFileName, Document.Project);
+ {
+
+ if (!string.IsNullOrEmpty (stylesheetFileName)) {
+
+ try {
+
+ IdeApp.Workbench.OpenDocument (stylesheetFileName, DocumentContext.Project);
+
} catch (Exception ex) {
- MessageService.ShowError ("Could not open document.", ex);
- }
- }
+ LoggingService.LogError ("Could not open document.", ex);
+ MessageService.ShowException (ex, "Could not open document.");
+ }
+ }
}
[CommandUpdateHandler (XmlCommands.OpenStylesheet)]
@@ -546,21 +737,28 @@ namespace MonoDevelop.Xml.Editor
public void GoToSchemaDefinitionCommand ()
{
try {
- //try to resolve the schema
- XmlSchemaCompletionData currentSchemaCompletionData = FindSchemaFromFileName (FileName);
- XmlSchemaObject schemaObject = GetSchemaObjectSelected (currentSchemaCompletionData);
-
- // Open schema if resolved
- if (schemaObject != null && schemaObject.SourceUri != null && schemaObject.SourceUri.Length > 0) {
+ //try to resolve the schema
+
+ XmlSchemaCompletionData currentSchemaCompletionData = FindSchemaFromFileName (FileName);
+
+ XmlSchemaObject schemaObject = GetSchemaObjectSelected (currentSchemaCompletionData);
+
+
+
+ // Open schema if resolved
+
+ if (schemaObject != null && schemaObject.SourceUri != null && schemaObject.SourceUri.Length > 0) {
+
string schemaFileName = schemaObject.SourceUri.Replace ("file:/", String.Empty);
IdeApp.Workbench.OpenDocument (
schemaFileName,
- Document.Project,
+ DocumentContext.Project,
Math.Max (1, schemaObject.LineNumber),
Math.Max (1, schemaObject.LinePosition));
}
} catch (Exception ex) {
- MessageService.ShowError ("Could not open document.", ex);
+ MonoDevelop.Core.LoggingService.LogError ("Could not open document.", ex);
+ MessageService.ShowException (ex, "Could not open document.");
}
}
@@ -571,7 +769,8 @@ namespace MonoDevelop.Xml.Editor
using (ProgressMonitor monitor = XmlEditorService.GetMonitor()) {
if (IsSchema)
XmlEditorService.ValidateSchema (monitor, Editor.Text, FileName);
- else
+ else
+
XmlEditorService.ValidateXml (monitor, Editor.Text, FileName);
}
}
@@ -579,17 +778,22 @@ namespace MonoDevelop.Xml.Editor
[CommandHandler (XmlCommands.AssignStylesheet)]
public void AssignStylesheetCommand ()
{
- // Prompt user for filename.
- string fileName = XmlEditorService.BrowseForStylesheetFile ();
- if (!string.IsNullOrEmpty (stylesheetFileName))
+ // Prompt user for filename.
+
+ string fileName = XmlEditorService.BrowseForStylesheetFile ();
+
+ if (!string.IsNullOrEmpty (stylesheetFileName))
+
stylesheetFileName = fileName;
}
[CommandHandler (XmlCommands.RunXslTransform)]
public void RunXslTransformCommand ()
{
- if (string.IsNullOrEmpty (stylesheetFileName)) {
- stylesheetFileName = XmlEditorService.BrowseForStylesheetFile ();
+ if (string.IsNullOrEmpty (stylesheetFileName)) {
+
+ stylesheetFileName = XmlEditorService.BrowseForStylesheetFile ();
+
if (string.IsNullOrEmpty (stylesheetFileName))
return;
}
@@ -616,7 +820,7 @@ namespace MonoDevelop.Xml.Editor
string newFileName = XmlEditorService.GenerateFileName (FileName, "-transformed{0}.xml");
monitor.BeginTask (GettextCatalog.GetString ("Executing transform..."), 1);
- using (XmlTextWriter output = XmlEditorService.CreateXmlTextWriter(Document)) {
+ using (XmlTextWriter output = XmlEditorService.CreateXmlTextWriter(Editor)) {
xslt.Transform (doc, null, output);
IdeApp.Workbench.NewDocument (
newFileName, "application/xml", output.ToString ());
@@ -626,19 +830,24 @@ namespace MonoDevelop.Xml.Editor
} catch (Exception ex) {
string msg = GettextCatalog.GetString ("Could not run transform.");
monitor.ReportError (msg, ex);
- monitor.EndTask ();
+ monitor.EndTask ();
+
}
}
}
- string GetFileContent (string fileName)
+ string GetFileContent (string fileName)
+
{
- MonoDevelop.Projects.Text.IEditableTextFile tf =
- MonoDevelop.Ide.TextFileProvider.Instance.GetEditableTextFile (fileName);
+ var tf =
+ MonoDevelop.Ide.TextFileProvider.Instance.GetReadOnlyTextEditorData (fileName);
if (tf != null)
- return tf.Text;
- System.IO.StreamReader reader = new System.IO.StreamReader (fileName, true);
- return reader.ReadToEnd();
+ return tf.Text;
+
+ System.IO.StreamReader reader = new System.IO.StreamReader (fileName, true);
+
+ return reader.ReadToEnd();
+
}
#endregion
@@ -650,7 +859,7 @@ namespace MonoDevelop.Xml.Editor
return;
if (inferredCompletionData == null
|| (doc.LastWriteTimeUtc - inferredCompletionData.TimeStampUtc).TotalSeconds >= 5
- && doc.Errors.Count <= inferredCompletionData.ErrorCount)
+ && doc.GetErrorsAsync().Result.Count <= inferredCompletionData.ErrorCount)
{
inferenceQueued = true;
System.Threading.ThreadPool.QueueUserWorkItem (delegate {
@@ -658,7 +867,7 @@ namespace MonoDevelop.Xml.Editor
InferredXmlCompletionProvider newData = new InferredXmlCompletionProvider ();
newData.Populate (doc.XDocument);
newData.TimeStampUtc = DateTime.UtcNow;
- newData.ErrorCount = doc.Errors.Count;
+ newData.ErrorCount = doc.GetErrorsAsync().Result.Count;
this.inferenceQueued = false;
this.inferredCompletionData = newData;
} catch (Exception ex) {