public AddRuleSet ( ICSharpCode.TextEditor.Document.HighlightRuleSet aRuleSet ) : void | ||
aRuleSet | ICSharpCode.TextEditor.Document.HighlightRuleSet | |
return | void |
public static DefaultHighlightingStrategy Parse(SyntaxMode syntaxMode, XmlTextReader xmlTextReader) { try { XmlValidatingReader validatingReader = new XmlValidatingReader(xmlTextReader); Stream shemaStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Mode.xsd"); validatingReader.Schemas.Add("", new XmlTextReader(shemaStream)); validatingReader.ValidationType = ValidationType.Schema; validatingReader.ValidationEventHandler += new ValidationEventHandler(ValidationHandler); XmlDocument doc = new XmlDocument(); doc.Load(validatingReader); DefaultHighlightingStrategy highlighter = new DefaultHighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText); if (doc.DocumentElement.Attributes["extensions"] != null) { highlighter.Extensions = doc.DocumentElement.Attributes["extensions"].InnerText.Split(new char[] { ';', '|' }); } XmlElement environment = doc.DocumentElement["Environment"]; if (environment != null) { foreach (XmlNode node in environment.ChildNodes) { if (node is XmlElement) { XmlElement el = (XmlElement)node; highlighter.SetColorFor(el.Name, el.HasAttribute("bgcolor") ? new HighlightBackground(el) : new HighlightColor(el)); } } } // parse properties if (doc.DocumentElement["Properties"] != null) { foreach (XmlElement propertyElement in doc.DocumentElement["Properties"].ChildNodes) { highlighter.Properties[propertyElement.Attributes["name"].InnerText] = propertyElement.Attributes["value"].InnerText; } } if (doc.DocumentElement["Digits"] != null) { highlighter.DigitColor = new HighlightColor(doc.DocumentElement["Digits"]); } XmlNodeList nodes = doc.DocumentElement.GetElementsByTagName("RuleSet"); foreach (XmlElement element in nodes) { highlighter.AddRuleSet(new HighlightRuleSet(element)); } xmlTextReader.Close(); if (errors != null) { ReportErrors(syntaxMode.FileName); errors = null; return(null); } else { return(highlighter); } } catch (Exception e) { MessageBox.Show("Could not load mode definition file.\n" + e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(null); } }
public static DefaultHighlightingStrategy Parse(SyntaxMode syntaxMode, XmlTextReader xmlTextReader) { if (syntaxMode == null) throw new ArgumentNullException("syntaxMode"); if (xmlTextReader == null) throw new ArgumentNullException("xmlTextReader"); try { XmlReaderSettings settings = new XmlReaderSettings(); Stream shemaStream = typeof(HighlightingDefinitionParser).Assembly.GetManifestResourceStream("ICSharpCode.TextEditor.Resources.Mode.xsd"); settings.Schemas.Add("", new XmlTextReader(shemaStream)); settings.Schemas.ValidationEventHandler += new ValidationEventHandler(ValidationHandler); settings.ValidationType = ValidationType.Schema; XmlReader validatingReader = XmlReader.Create(xmlTextReader, settings); // XmlValidatingReader validatingReader = new XmlValidatingReader(xmlTextReader); // Stream shemaStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Resources.Mode.xsd"); // validatingReader.Schemas.Add("", new XmlTextReader(shemaStream)); // validatingReader.ValidationType = ValidationType.Schema; XmlDocument doc = new XmlDocument(); doc.Load(validatingReader); DefaultHighlightingStrategy highlighter = new DefaultHighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText); if (doc.DocumentElement.Attributes["extensions"]!= null) { highlighter.Extensions = doc.DocumentElement.Attributes["extensions"].InnerText.Split(new char[] { ';', '|' }); } XmlElement environment = doc.DocumentElement["Environment"]; if (environment != null) { foreach (XmlNode node in environment.ChildNodes) { if (node is XmlElement) { XmlElement el = (XmlElement)node; highlighter.SetColorFor(el.Name, el.HasAttribute("bgcolor") ? new HighlightBackground(el) : new HighlightColor(el)); } } } // parse properties if (doc.DocumentElement["Properties"]!= null) { foreach (XmlElement propertyElement in doc.DocumentElement["Properties"].ChildNodes) { highlighter.Properties[propertyElement.Attributes["name"].InnerText] = propertyElement.Attributes["value"].InnerText; } } if (doc.DocumentElement["Digits"]!= null) { highlighter.DigitColor = new HighlightColor(doc.DocumentElement["Digits"]); } XmlNodeList nodes = doc.DocumentElement.GetElementsByTagName("RuleSet"); foreach (XmlElement element in nodes) { highlighter.AddRuleSet(new HighlightRuleSet(element)); } xmlTextReader.Close(); if(errors!=null) { ReportErrors(syntaxMode.FileName); errors = null; return null; } else { return highlighter; } } catch (Exception e) { MessageBox.Show("Could not load mode definition file.\n" + e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return null; } }