public ResourceSyntaxModeProvider()
        {
            Stream baseStream = new StreamReader(Application.StartupPath + "\\TextStyle\\SyntaxModes.xml", Encoding.Default).BaseStream;

            if (baseStream == null)
            {
                throw new ApplicationException();
            }
            this.syntaxModes = SyntaxMode.GetSyntaxModes(baseStream);
        }
        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);
        }
        public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
        {
            string text = Path.Combine(this.directory, syntaxMode.FileName);

            if (!File.Exists(text))
            {
                MessageBox.Show("Can't load highlighting definition " + text + " (file not found)!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                return(null);
            }
            return(new XmlTextReader(File.OpenRead(text)));
        }
        public FileSyntaxModeProvider(string directory)
        {
            this.directory = directory;
            string path = Path.Combine(directory, "SyntaxModes.xml");

            if (File.Exists(path))
            {
                Stream stream = File.OpenRead(path);
                this.syntaxModes = SyntaxMode.GetSyntaxModes(stream);
                stream.Close();
                return;
            }
            this.syntaxModes = this.ScanDirectory(directory);
        }
        public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
        {
            Stream baseStream = new StreamReader(Application.StartupPath + "\\TextStyle\\" + syntaxMode.FileName, Encoding.Default).BaseStream;

            return(new XmlTextReader(baseStream));
        }
Example #6
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);
        }