37
37
public static class TextFileService
39
static List<IFormatter> formatters = new List<IFormatter>();
40
static List<IPrettyPrinter> prettyPrinters = new List<IPrettyPrinter>();
42
// static void PrintCategory (CodeFormatCategory c)
44
// System.Console.WriteLine (c);
45
// foreach (var o in c.Options) {
46
// System.Console.WriteLine(o);
48
// foreach (var sub in c.SubCategories) {
49
// PrintCategory (sub);
53
static TextFileService ()
55
AddinManager.AddExtensionNodeHandler ("/MonoDevelop/ProjectModel/TextFormatters", FormatterExtHandler);
56
AddinManager.AddExtensionNodeHandler ("/MonoDevelop/ProjectModel/TextPrettyPrinters", PrettyPrinterExtHandler);
59
static List<CodeFormatSettings> settings = new List<CodeFormatSettings> ();
61
public static IEnumerable<CodeFormatSettings> GetAvailableSettings (CodeFormatDescription description)
66
public static CodeFormatSettings GetSettings (string description, string name)
68
return GetSettings (GetFormatDescription (description), name);
71
public static CodeFormatSettings GetSettings (CodeFormatDescription description, string name)
73
if (description == null)
75
return GetAvailableSettings (description).FirstOrDefault (s => s.Name == name);
78
public static void SetSettings (CodeFormatDescription description, IEnumerable<CodeFormatSettings> settings)
80
TextFileService.settings = new List<CodeFormatSettings> (settings);
83
static void FormatterExtHandler (object sender, ExtensionNodeEventArgs args)
85
switch (args.Change) {
86
case ExtensionChange.Add:
87
formatters.Add ((IFormatter) args.ExtensionObject);
89
case ExtensionChange.Remove:
90
formatters.Remove ((IFormatter) args.ExtensionObject);
95
static void PrettyPrinterExtHandler (object sender, ExtensionNodeEventArgs args)
97
switch (args.Change) {
98
case ExtensionChange.Add:
99
prettyPrinters.Add ((IPrettyPrinter) args.ExtensionObject);
101
case ExtensionChange.Remove:
102
prettyPrinters.Remove ((IPrettyPrinter) args.ExtensionObject);
107
static void DefinitionExtHandler (object sender, ExtensionNodeEventArgs args)
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);
116
case ExtensionChange.Remove:
117
descriptions.RemoveAll (d => d.MimeType == descr.MimeType);
123
public static CodeFormatDescription GetFormatDescription (string mimeType)
125
return descriptions.Find (d => d.MimeType == mimeType);
128
public static Formatter GetFormatter (string mimeType)
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);
138
39
public static void FireLineCountChanged (ITextFile textFile, int lineNumber, int lineCount, int column)
140
41
if (LineCountChanged != null)