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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/TextFileService.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:
36
36
{
37
37
        public static class TextFileService
38
38
        {
39
 
                static List<IFormatter> formatters = new List<IFormatter>();
40
 
                static List<IPrettyPrinter> prettyPrinters = new List<IPrettyPrinter>();
41
 
                
42
 
//              static void PrintCategory (CodeFormatCategory c)
43
 
//              {
44
 
//                      System.Console.WriteLine (c);
45
 
//                      foreach (var o in c.Options) {
46
 
//                              System.Console.WriteLine(o);
47
 
//                      }
48
 
//                      foreach (var sub in c.SubCategories) {
49
 
//                              PrintCategory (sub);
50
 
//                      }
51
 
//              }
52
 
                
53
 
                static TextFileService ()
54
 
                {
55
 
                        AddinManager.AddExtensionNodeHandler ("/MonoDevelop/ProjectModel/TextFormatters", FormatterExtHandler);
56
 
                        AddinManager.AddExtensionNodeHandler ("/MonoDevelop/ProjectModel/TextPrettyPrinters", PrettyPrinterExtHandler);
57
 
                }
58
 
                /*
59
 
                static List<CodeFormatSettings> settings = new List<CodeFormatSettings> ();
60
 
                
61
 
                public static IEnumerable<CodeFormatSettings> GetAvailableSettings (CodeFormatDescription description)
62
 
                {
63
 
                        return settings;
64
 
                }
65
 
                
66
 
                public static CodeFormatSettings GetSettings (string description, string name)
67
 
                {
68
 
                        return GetSettings (GetFormatDescription (description), name);
69
 
                }
70
 
                
71
 
                public static CodeFormatSettings GetSettings (CodeFormatDescription description, string name)
72
 
                {
73
 
                        if (description == null)
74
 
                                return null;
75
 
                        return GetAvailableSettings (description).FirstOrDefault (s => s.Name == name);
76
 
                }
77
 
                
78
 
                public static void SetSettings (CodeFormatDescription description, IEnumerable<CodeFormatSettings> settings)
79
 
                {
80
 
                        TextFileService.settings = new List<CodeFormatSettings> (settings);
81
 
                }*/
82
 
                
83
 
                static void FormatterExtHandler (object sender, ExtensionNodeEventArgs args)
84
 
                {
85
 
                        switch (args.Change) {
86
 
                        case ExtensionChange.Add:
87
 
                                formatters.Add ((IFormatter) args.ExtensionObject);
88
 
                                break;
89
 
                        case ExtensionChange.Remove:
90
 
                                formatters.Remove ((IFormatter) args.ExtensionObject);
91
 
                                break;
92
 
                        }
93
 
                }
94
 
                
95
 
                static void PrettyPrinterExtHandler (object sender, ExtensionNodeEventArgs args)
96
 
                {
97
 
                        switch (args.Change) {
98
 
                        case ExtensionChange.Add:
99
 
                                prettyPrinters.Add ((IPrettyPrinter) args.ExtensionObject);
100
 
                                break;
101
 
                        case ExtensionChange.Remove:
102
 
                                prettyPrinters.Remove ((IPrettyPrinter) args.ExtensionObject);
103
 
                                break;
104
 
                        }
105
 
                }
106
 
                /*
107
 
                static void DefinitionExtHandler (object sender, ExtensionNodeEventArgs args)
108
 
                {
109
 
                        XmlDefinitionCodon xmlDef = args.ExtensionNode as XmlDefinitionCodon;
110
 
                        using (XmlReader reader = xmlDef.Open ()) {
111
 
                                CodeFormatDescription descr = CodeFormatDescription.Read (reader);
112
 
                                switch (args.Change) {
113
 
                                case ExtensionChange.Add:
114
 
                                        descriptions.Add (descr);
115
 
                                        break;
116
 
                                case ExtensionChange.Remove:
117
 
                                        descriptions.RemoveAll (d => d.MimeType == descr.MimeType);
118
 
                                        break;
119
 
                                }
120
 
                        }
121
 
                }
122
 
                
123
 
                public static CodeFormatDescription GetFormatDescription (string mimeType)
124
 
                {
125
 
                        return descriptions.Find (d => d.MimeType == mimeType);
126
 
                }*/
127
 
                
128
 
                public static Formatter GetFormatter (string mimeType)
129
 
                {
130
 
                        IPrettyPrinter prettyPrinter = prettyPrinters.Find (x => x.CanFormat (mimeType));
131
 
                        IFormatter formatter = formatters.Find (x => x.CanFormat (mimeType));
132
 
                        if (prettyPrinter != null || formatter != null)
133
 
                                return new Formatter (mimeType, prettyPrinter, formatter);
134
 
                        else
135
 
                                return null;
136
 
                }
137
 
                
138
39
                public static void FireLineCountChanged (ITextFile textFile, int lineNumber, int lineCount, int column)
139
40
                {
140
41
                        if (LineCountChanged != null)