~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.Formatting/XmlFormatter.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
35
35
 
36
36
namespace MonoDevelop.Xml.Formatting
37
37
{
38
 
        public class XmlFormatter: IPrettyPrinter
 
38
        public class XmlFormatter: ICodeFormatter
39
39
        {
40
 
                public bool CanFormat (string mimeType)
41
 
                {
42
 
                        return DesktopService.GetMimeTypeIsSubtype (mimeType, "application/xml");
43
 
                }
44
 
                
45
 
                public string FormatXml (TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
 
40
                public static string FormatXml (TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
46
41
                {
47
42
                        XmlDocument doc;
48
43
                        try {
49
44
                                doc = new XmlDocument ();
50
45
                                doc.LoadXml (input);
51
 
                        } catch {
 
46
                        } catch (Exception ex) {
52
47
                                // Ignore malformed xml
53
 
                                return input;
 
48
                                MonoDevelop.Core.LoggingService.LogWarning ("Error formatting XML file", ex);
 
49
                                return null;
54
50
                        }
55
51
                        
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 ();
61
57
                }
62
 
                public void CorrectIndenting (object textEditorData, int line)
63
 
                {
64
 
                        // TODO
65
 
                }
66
 
                
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)
68
 
                {
69
 
                        throw new System.NotImplementedException();
70
 
                }
71
 
                
72
 
                public string FormatText (PolicyContainer policyParent, string mimeType, string input)
73
 
                {
74
 
                        XmlFormattingPolicy xmlPol = policyParent.Get<XmlFormattingPolicy> (mimeType);
75
 
                        TextStylePolicy txtPol = policyParent.Get<TextStylePolicy> (mimeType);
 
58
                
 
59
                public string FormatText (PolicyContainer policyParent, IEnumerable<string> mimeTypeInheritanceChain, string input)
 
60
                {
 
61
                        var txtPol = policyParent.Get<TextStylePolicy> (mimeTypeInheritanceChain);
 
62
                        var xmlPol = policyParent.Get<XmlFormattingPolicy> (mimeTypeInheritanceChain);
76
63
                        return FormatXml (txtPol, xmlPol, input);
77
64
                }
78
65
                
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)
80
67
                {
81
 
                        return input;
82
 
                }
83
 
                
84
 
                public bool SupportsOnTheFlyFormatting {
85
 
                        get {
86
 
                                return false;
87
 
                        }
 
68
                        return null;
88
69
                }
89
70
        }
90
71
}