private void CreateDefaultHighlightingStrategy()
        {
            DefaultHighlightingStrategy defaultHighlightingStrategy = new DefaultHighlightingStrategy();

            defaultHighlightingStrategy.Extensions = new string[0];
            defaultHighlightingStrategy.Rules.Add(new HighlightRuleSet());
            this.highlightingDefs["Default"] = defaultHighlightingStrategy;
        }
        private IHighlightingStrategy LoadDefinition(DictionaryEntry entry)
        {
            SyntaxMode syntaxMode = (SyntaxMode)entry.Key;
            ISyntaxModeFileProvider     syntaxModeFileProvider      = (ISyntaxModeFileProvider)entry.Value;
            DefaultHighlightingStrategy defaultHighlightingStrategy = HighlightingDefinitionParser.Parse(syntaxMode, syntaxModeFileProvider.GetSyntaxModeFile(syntaxMode));

            this.highlightingDefs[syntaxMode.Name] = defaultHighlightingStrategy;
            defaultHighlightingStrategy.ResolveReferences();
            return(defaultHighlightingStrategy);
        }
Esempio n. 3
0
        public static DefaultHighlightingStrategy Parse(SyntaxMode syntaxMode, XmlTextReader xmlTextReader)
        {
            DefaultHighlightingStrategy result;

            try
            {
                XmlValidatingReader xmlValidatingReader = new XmlValidatingReader(xmlTextReader);
                Stream baseStream = new StreamReader(Application.StartupPath + "\\TextStyle\\Mode.xsd", Encoding.Default).BaseStream;
                xmlValidatingReader.Schemas.Add("", new XmlTextReader(baseStream));
                xmlValidatingReader.ValidationType          = ValidationType.Schema;
                xmlValidatingReader.ValidationEventHandler += new ValidationEventHandler(HighlightingDefinitionParser.ValidationHandler);
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(xmlValidatingReader);
                DefaultHighlightingStrategy defaultHighlightingStrategy = new DefaultHighlightingStrategy(xmlDocument.DocumentElement.Attributes["name"].InnerText);
                if (xmlDocument.DocumentElement.Attributes["extensions"] != null)
                {
                    defaultHighlightingStrategy.Extensions = xmlDocument.DocumentElement.Attributes["extensions"].InnerText.Split(new char[]
                    {
                        ';',
                        '|'
                    });
                }
                XmlElement xmlElement = xmlDocument.DocumentElement["Environment"];
                if (xmlElement != null)
                {
                    foreach (XmlNode xmlNode in xmlElement.ChildNodes)
                    {
                        if (xmlNode is XmlElement)
                        {
                            XmlElement xmlElement2 = (XmlElement)xmlNode;
                            defaultHighlightingStrategy.SetColorFor(xmlElement2.Name, xmlElement2.HasAttribute("bgcolor") ? new HighlightBackground(xmlElement2) : new HighlightColor(xmlElement2));
                        }
                    }
                }
                if (xmlDocument.DocumentElement["Properties"] != null)
                {
                    foreach (XmlElement xmlElement3 in xmlDocument.DocumentElement["Properties"].ChildNodes)
                    {
                        defaultHighlightingStrategy.Properties[xmlElement3.Attributes["name"].InnerText] = xmlElement3.Attributes["value"].InnerText;
                    }
                }
                if (xmlDocument.DocumentElement["Digits"] != null)
                {
                    defaultHighlightingStrategy.DigitColor = new HighlightColor(xmlDocument.DocumentElement["Digits"]);
                }
                XmlNodeList elementsByTagName = xmlDocument.DocumentElement.GetElementsByTagName("RuleSet");
                foreach (XmlElement el in elementsByTagName)
                {
                    defaultHighlightingStrategy.AddRuleSet(new HighlightRuleSet(el));
                }
                xmlTextReader.Close();
                if (HighlightingDefinitionParser.errors != null)
                {
                    HighlightingDefinitionParser.ReportErrors(syntaxMode.FileName);
                    HighlightingDefinitionParser.errors = null;
                    result = null;
                }
                else
                {
                    result = defaultHighlightingStrategy;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not load mode definition file.\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                result = null;
            }
            return(result);
        }