static private void init() { if (!inited) { inited = true; LoadResource("zen_settings.js"); if (delayOpenConfig == null) // timer for opening config files { delayOpenConfig = new Timer(); delayOpenConfig.Interval = 100; delayOpenConfig.Tick += new EventHandler(delayOpenConfig_Tick); } if (watcherConfig == null) // watching config files changes { watcherConfig = new FileSystemWatcher(Path.Combine(PathHelper.DataDir, "XMLCompletion"), "zen*"); watcherConfig.Changed += new FileSystemEventHandler(watcherConfig_Changed); watcherConfig.Created += new FileSystemEventHandler(watcherConfig_Changed); watcherConfig.EnableRaisingEvents = true; } } ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; string docType = sci != null?sci.ConfigurationLanguage.ToLower() : null; lang = null; if (docType != null) { if (settings.langs.ContainsKey(docType)) { lang = settings.langs[docType]; } } }
private static ZenSettings ReadZenSettings(JsonReader reader) { ZenSettings settings = new ZenSettings(); Type objType = settings.GetType(); reader.Read(); if (reader.Token != JsonToken.ObjectStart) { return(null); } string currentProp = null; while (reader.Read()) { if (reader.Token == JsonToken.ObjectEnd) { break; } if (reader.Token == JsonToken.PropertyName) { currentProp = reader.Value.ToString(); } else if (reader.Token == JsonToken.ObjectStart) { if (currentProp == "variables") { settings.variables = ReadHashtable(reader); } else { settings.langs.Add(currentProp, ReadZenLang(reader)); } } } foreach (ZenLang lang in settings.langs.Values) { if (lang.extends != null && settings.langs.ContainsKey(lang.extends)) { ExtendLang(lang, settings.langs[lang.extends]); } } if (!settings.langs.ContainsKey("xml")) { ZenLang xlang = new ZenLang(); xlang.abbreviations = new Hashtable(); xlang.element_types = new ZenElementTypes(null); xlang.filters = "xml, xsl"; xlang.snippets = new Hashtable(); settings.langs.Add("xml", xlang); } settings.variables["child"] = ""; return(settings); }
private static void ExtendLang(ZenLang lang, ZenLang lang2) { MergeHashtable(ref lang.abbreviations, ref lang2.abbreviations); MergeHashtable(ref lang.snippets, ref lang2.snippets); if (lang.element_types == null) { lang.element_types = lang2.element_types; } else if (lang2.element_types != null) { MergeHashtable(ref lang.element_types.empty, ref lang2.element_types.empty); MergeHashtable(ref lang.element_types.block_level, ref lang2.element_types.block_level); MergeHashtable(ref lang.element_types.inline_level, ref lang2.element_types.inline_level); } }
private static ZenLang ReadZenLang(JsonReader reader) { ZenLang lang = new ZenLang(); Type objType = lang.GetType(); string currentProp = null; while (reader.Read()) { if (reader.Token == JsonToken.ObjectEnd) { break; } if (reader.Token == JsonToken.PropertyName) { currentProp = reader.Value.ToString(); } else if (reader.Token == JsonToken.String) { string value = reader.Value.ToString(); FieldInfo info = objType.GetField(currentProp); if (info != null) { info.SetValue(lang, value); } } else if (reader.Token == JsonToken.ObjectStart) { Hashtable table = ReadHashtable(reader); if (currentProp == "element_types") { lang.element_types = new ZenElementTypes(table); } else { FieldInfo info = objType.GetField(currentProp); if (info != null) { info.SetValue(lang, table); } } } } return(lang); }
private static ZenSettings ReadZenSettings(JsonReader reader) { ZenSettings settings = new ZenSettings(); Type objType = settings.GetType(); reader.Read(); if (reader.Token != JsonToken.ObjectStart) return null; string currentProp = null; while (reader.Read()) { if (reader.Token == JsonToken.ObjectEnd) break; if (reader.Token == JsonToken.PropertyName) currentProp = reader.Value.ToString(); else if (reader.Token == JsonToken.ObjectStart) { if (currentProp == "variables") settings.variables = ReadHashtable(reader); else settings.langs.Add(currentProp, ReadZenLang(reader)); } } foreach (ZenLang lang in settings.langs.Values) { if (lang.extends != null && settings.langs.ContainsKey(lang.extends)) ExtendLang(lang, settings.langs[lang.extends]); } if (!settings.langs.ContainsKey("xml")) { ZenLang xlang = new ZenLang(); xlang.abbreviations = new Hashtable(); xlang.element_types = new ZenElementTypes(null); xlang.filters = "xml, xsl"; xlang.snippets = new Hashtable(); settings.langs.Add("xml", xlang); } settings.variables["child"] = ""; return settings; }
static private void init() { if (!inited) { inited = true; LoadResource("zen_settings.js"); if (delayOpenConfig == null) // timer for opening config files { delayOpenConfig = new Timer(); delayOpenConfig.Interval = 100; delayOpenConfig.Tick += new EventHandler(delayOpenConfig_Tick); } if (watcherConfig == null) // watching config files changes { watcherConfig = new FileSystemWatcher(Path.Combine(PathHelper.DataDir, "XMLCompletion"), "zen*"); watcherConfig.Changed += new FileSystemEventHandler(watcherConfig_Changed); watcherConfig.Created += new FileSystemEventHandler(watcherConfig_Changed); watcherConfig.EnableRaisingEvents = true; } } ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; string docType = sci != null ? sci.ConfigurationLanguage.ToLower() : null; lang = null; if (docType != null) { if (settings.langs.ContainsKey(docType)) lang = settings.langs[docType]; } }
private static ZenLang ReadZenLang(JsonReader reader) { ZenLang lang = new ZenLang(); Type objType = lang.GetType(); string currentProp = null; while (reader.Read()) { if (reader.Token == JsonToken.ObjectEnd) break; if (reader.Token == JsonToken.PropertyName) currentProp = reader.Value.ToString(); else if (reader.Token == JsonToken.String) { string value = reader.Value.ToString(); FieldInfo info = objType.GetField(currentProp); if (info != null) info.SetValue(lang, value); } else if (reader.Token == JsonToken.ObjectStart) { Hashtable table = ReadHashtable(reader); if (currentProp == "element_types") { lang.element_types = new ZenElementTypes(table); } else { FieldInfo info = objType.GetField(currentProp); if (info != null) info.SetValue(lang, table); } } } return lang; }
private static void ExtendLang(ZenLang lang, ZenLang lang2) { MergeHashtable(ref lang.abbreviations, ref lang2.abbreviations); MergeHashtable(ref lang.snippets, ref lang2.snippets); if (lang.element_types == null) lang.element_types = lang2.element_types; else if (lang2.element_types != null) { MergeHashtable(ref lang.element_types.empty, ref lang2.element_types.empty); MergeHashtable(ref lang.element_types.block_level, ref lang2.element_types.block_level); MergeHashtable(ref lang.element_types.inline_level, ref lang2.element_types.inline_level); } }