30
30
using System.Collections.Generic;
31
31
using MonoDevelop.Ide.Gui.Content;
32
32
using MonoDevelop.Ide;
33
using MonoDevelop.Projects.Text;
34
33
using MonoDevelop.Projects.Policies;
34
using MonoDevelop.Ide.CodeFormatting;
36
36
namespace MonoDevelop.Xml.Formatting
38
public class XmlFormatter: IPrettyPrinter
38
public class XmlFormatter: ICodeFormatter
40
public bool CanFormat (string mimeType)
42
return DesktopService.GetMimeTypeIsSubtype (mimeType, "application/xml");
45
public string FormatXml (TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
40
public static string FormatXml (TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
49
44
doc = new XmlDocument ();
50
45
doc.LoadXml (input);
46
} catch (Exception ex) {
52
47
// Ignore malformed xml
48
MonoDevelop.Core.LoggingService.LogWarning ("Error formatting XML file", ex);
56
StringWriter sw = new StringWriter ();
57
XmlFormatterWriter xmlWriter = new XmlFormatterWriter (sw);
52
var sw = new StringWriter ();
53
var xmlWriter = new XmlFormatterWriter (sw);
58
54
xmlWriter.WriteNode (doc, formattingPolicy, textPolicy);
59
55
xmlWriter.Flush ();
60
56
return sw.ToString ();
62
public void CorrectIndenting (object textEditorData, int line)
67
public void OnTheFlyFormat (object textEditorData, MonoDevelop.Projects.Dom.IType callingType, MonoDevelop.Projects.Dom.IMember callingMember, MonoDevelop.Projects.Dom.Parser.ProjectDom dom, MonoDevelop.Projects.Dom.ICompilationUnit unit, MonoDevelop.Projects.Dom.DomLocation endLocation)
69
throw new System.NotImplementedException();
72
public string FormatText (PolicyContainer policyParent, string mimeType, string input)
74
XmlFormattingPolicy xmlPol = policyParent.Get<XmlFormattingPolicy> (mimeType);
75
TextStylePolicy txtPol = policyParent.Get<TextStylePolicy> (mimeType);
59
public string FormatText (PolicyContainer policyParent, IEnumerable<string> mimeTypeInheritanceChain, string input)
61
var txtPol = policyParent.Get<TextStylePolicy> (mimeTypeInheritanceChain);
62
var xmlPol = policyParent.Get<XmlFormattingPolicy> (mimeTypeInheritanceChain);
76
63
return FormatXml (txtPol, xmlPol, input);
79
public string FormatText (PolicyContainer policyParent, string mimeType, string input, int fromOffest, int toOffset)
66
public string FormatText (PolicyContainer policyParent, IEnumerable<string> mimeTypeInheritanceChain, string input, int fromOffest, int toOffset)
84
public bool SupportsOnTheFlyFormatting {