상속: IDisposable
예제 #1
0
        public void HighlightSyntax(SyntaxDescriptor desc, Range range)
        {
            //set style order
            range.tb.ClearStylesBuffer();
            for (int i = 0; i < desc.styles.Count; i++)
            {
                range.tb.Styles[i] = desc.styles[i];
            }
            //brackets
            var oldBrackets = RememberBrackets(range.tb);

            range.tb.LeftBracket   = desc.leftBracket;
            range.tb.RightBracket  = desc.rightBracket;
            range.tb.LeftBracket2  = desc.leftBracket2;
            range.tb.RightBracket2 = desc.rightBracket2;
            //clear styles of range
            range.ClearStyle(desc.styles.ToArray());
            //highlight syntax
            foreach (var rule in desc.rules)
            {
                range.SetStyle(rule.style, rule.Regex);
            }
            //clear folding
            range.ClearFoldingMarkers();
            //folding markers
            foreach (var folding in desc.foldings)
            {
                range.SetFoldingMarkers(folding.startMarkerRegex, folding.finishMarkerRegex, folding.options);
            }

            //
            RestoreBrackets(range.tb, oldBrackets);
        }
        public static SyntaxDescriptor ParseXmlDescription(XmlDocument doc)
        {
            SyntaxDescriptor desc     = new SyntaxDescriptor();
            XmlNode          brackets = doc.SelectSingleNode("doc/brackets");

            if (brackets != null)
            {
                if (brackets.Attributes["left"] == null || brackets.Attributes["right"] == null ||
                    brackets.Attributes["left"].Value == "" || brackets.Attributes["right"].Value == "")
                {
                    desc.leftBracket  = '\x0';
                    desc.rightBracket = '\x0';
                }
                else
                {
                    desc.leftBracket  = brackets.Attributes["left"].Value[0];
                    desc.rightBracket = brackets.Attributes["right"].Value[0];
                }

                if (brackets.Attributes["left2"] == null || brackets.Attributes["right2"] == null ||
                    brackets.Attributes["left2"].Value == "" || brackets.Attributes["right2"].Value == "")
                {
                    desc.leftBracket2  = '\x0';
                    desc.rightBracket2 = '\x0';
                }
                else
                {
                    desc.leftBracket2  = brackets.Attributes["left2"].Value[0];
                    desc.rightBracket2 = brackets.Attributes["right2"].Value[0];
                }
            }

            Dictionary <string, Style> styleByName = new Dictionary <string, Style>();

            foreach (XmlNode style in doc.SelectNodes("doc/style"))
            {
                var s = ParseStyle(style);
                styleByName[style.Attributes["name"].Value] = s;
                desc.styles.Add(s);
            }
            foreach (XmlNode rule in doc.SelectNodes("doc/rule"))
            {
                desc.rules.Add(ParseRule(rule, styleByName));
            }
            foreach (XmlNode folding in doc.SelectNodes("doc/folding"))
            {
                desc.foldings.Add(ParseFolding(folding));
            }
            foreach (XmlNode bgcolor in doc.SelectNodes("doc/background"))
            {
                string[] splits = bgcolor.Attributes["color"].Value.Split(',');
                desc.BackgroundColor = Color.FromArgb(Convert.ToInt32(splits[3]),
                                                      Convert.ToInt32(splits[0]),
                                                      Convert.ToInt32(splits[1]),
                                                      Convert.ToInt32(splits[2]));
            }

            return(desc);
        }
        public static SyntaxDescriptor ParseXmlDescription(XmlDocument doc)
        {
            SyntaxDescriptor desc = new SyntaxDescriptor();
            XmlNode brackets = doc.SelectSingleNode("doc/brackets");
            if (brackets != null)
            {
                if (brackets.Attributes["left"] == null || brackets.Attributes["right"] == null ||
                    brackets.Attributes["left"].Value == "" || brackets.Attributes["right"].Value == "")
                {
                    desc.leftBracket = '\x0';
                    desc.rightBracket = '\x0';
                }
                else
                {
                    desc.leftBracket = brackets.Attributes["left"].Value[0];
                    desc.rightBracket = brackets.Attributes["right"].Value[0];
                }

                if (brackets.Attributes["left2"] == null || brackets.Attributes["right2"] == null ||
            brackets.Attributes["left2"].Value == "" || brackets.Attributes["right2"].Value == "")
                {
                    desc.leftBracket2 = '\x0';
                    desc.rightBracket2 = '\x0';
                }
                else
                {
                    desc.leftBracket2 = brackets.Attributes["left2"].Value[0];
                    desc.rightBracket2 = brackets.Attributes["right2"].Value[0];
                }
            }

            Dictionary<string, Style> styleByName = new Dictionary<string, Style>();

            foreach (XmlNode style in doc.SelectNodes("doc/style"))
            {
                var s = ParseStyle(style);
                styleByName[style.Attributes["name"].Value] = s;
                desc.styles.Add(s);
            }
            foreach (XmlNode rule in doc.SelectNodes("doc/rule"))
                desc.rules.Add(ParseRule(rule, styleByName));
            foreach (XmlNode folding in doc.SelectNodes("doc/folding"))
                desc.foldings.Add(ParseFolding(folding));
            foreach (XmlNode bgcolor in doc.SelectNodes("doc/background")) {
                string[] splits = bgcolor.Attributes["color"].Value.Split(',');
                desc.BackgroundColor = Color.FromArgb(Convert.ToInt32(splits[3]),
                                                      Convert.ToInt32(splits[0]),
                                                      Convert.ToInt32(splits[1]),
                                                      Convert.ToInt32(splits[2]));
            }

            return desc;
        }
예제 #4
0
        public static SyntaxDescriptor ParseXmlDescription(XmlDocument doc)
        {
            SyntaxDescriptor desc     = new SyntaxDescriptor();
            XmlNode          brackets = doc.SelectSingleNode("doc/brackets");

            if (brackets != null)
            {
                if (brackets.Attributes["left"] == null || brackets.Attributes["right"] == null ||
                    brackets.Attributes["left"].Value == "" || brackets.Attributes["right"].Value == "")
                {
                    desc.leftBracket  = '\x0';
                    desc.rightBracket = '\x0';
                }
                else
                {
                    desc.leftBracket  = brackets.Attributes["left"].Value[0];
                    desc.rightBracket = brackets.Attributes["right"].Value[0];
                }

                if (brackets.Attributes["left2"] == null || brackets.Attributes["right2"] == null ||
                    brackets.Attributes["left2"].Value == "" || brackets.Attributes["right2"].Value == "")
                {
                    desc.leftBracket2  = '\x0';
                    desc.rightBracket2 = '\x0';
                }
                else
                {
                    desc.leftBracket2  = brackets.Attributes["left2"].Value[0];
                    desc.rightBracket2 = brackets.Attributes["right2"].Value[0];
                }
            }

            Dictionary <string, Style> styleByName = new Dictionary <string, Style>();

            foreach (XmlNode style in doc.SelectNodes("doc/style"))
            {
                var s = ParseStyle(style);
                styleByName[style.Attributes["name"].Value] = s;
                desc.styles.Add(s);
            }
            foreach (XmlNode rule in doc.SelectNodes("doc/rule"))
            {
                desc.rules.Add(ParseRule(rule, styleByName));
            }
            foreach (XmlNode folding in doc.SelectNodes("doc/folding"))
            {
                desc.foldings.Add(ParseFolding(folding));
            }

            return(desc);
        }
예제 #5
0
        public static SyntaxDescriptor ParseXmlDescription(XmlDocument doc)
        {
            SyntaxDescriptor desc = new SyntaxDescriptor();
            XmlNode brackets = doc.SelectSingleNode("doc/brackets");
            if (brackets != null)
            {
                if (brackets.Attributes["left"] == null || brackets.Attributes["right"] == null ||
                    brackets.Attributes["left"].Value == "" || brackets.Attributes["right"].Value == "")
                {
                    desc.leftBracket = '\x0';
                    desc.rightBracket = '\x0';
                }
                else
                {
                    desc.leftBracket = brackets.Attributes["left"].Value[0];
                    desc.rightBracket = brackets.Attributes["right"].Value[0];
                }

                if (brackets.Attributes["left2"] == null || brackets.Attributes["right2"] == null ||
            brackets.Attributes["left2"].Value == "" || brackets.Attributes["right2"].Value == "")
                {
                    desc.leftBracket2 = '\x0';
                    desc.rightBracket2 = '\x0';
                }
                else
                {
                    desc.leftBracket2 = brackets.Attributes["left2"].Value[0];
                    desc.rightBracket2 = brackets.Attributes["right2"].Value[0];
                }
            }

            Dictionary<string, Style> styleByName = new Dictionary<string, Style>();

            foreach (XmlNode style in doc.SelectNodes("doc/style"))
            {
                var s = ParseStyle(style);
                styleByName[style.Attributes["name"].Value] = s;
                desc.styles.Add(s);
            }
            foreach (XmlNode rule in doc.SelectNodes("doc/rule"))
                desc.rules.Add(ParseRule(rule, styleByName));
            foreach (XmlNode folding in doc.SelectNodes("doc/folding"))
                desc.foldings.Add(ParseFolding(folding));

            return desc;
        }
예제 #6
0
        /// <summary>
        /// Highlights syntax for given XML description file
        /// </summary>
        public virtual void HighlightSyntax(string XMLdescriptionFile, Range range)
        {
            SyntaxDescriptor desc = null;

            if (!descByXMLfileNames.TryGetValue(XMLdescriptionFile, out desc))
            {
                var    doc  = new XmlDocument();
                string file = XMLdescriptionFile;
                if (!File.Exists(file))
                {
                    file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(file));
                }

                doc.LoadXml(File.ReadAllText(file));
                desc = ParseXmlDescription(doc);
                descByXMLfileNames[XMLdescriptionFile] = desc;
            }
            HighlightSyntax(desc, range);
        }
예제 #7
0
        /// <summary>
        /// Uses the given <paramref name="doc"/> to parse a XML description and adds it as syntax descriptor.
        /// The syntax descriptor is used for highlighting when
        /// <list type="bullet">
        ///     <item>Language property of FCTB is set to <see cref="Language.Custom"/></item>
        ///     <item>DescriptionFile property of FCTB has the same value as the method parameter <paramref name="descriptionFileName"/></item>
        /// </list>
        /// </summary>
        /// <param name="descriptionFileName">Name of the description file</param>
        /// <param name="doc">XmlDocument to parse</param>
        public virtual void AddXmlDescription(string descriptionFileName, XmlDocument doc)
        {
            SyntaxDescriptor desc = ParseXmlDescription(doc);

            descByXMLfileNames[descriptionFileName] = desc;
        }
        public void HighlightSyntax(SyntaxDescriptor desc, Range range)
        {
            //set style order
            range.tb.ClearStylesBuffer();
            for(int i=0;i<desc.styles.Count;i++)
                range.tb.Styles[i] = desc.styles[i];
            //brackets
            var oldBrackets = RememberBrackets(range.tb);
            range.tb.LeftBracket = desc.leftBracket;
            range.tb.RightBracket = desc.rightBracket;
            range.tb.LeftBracket2 = desc.leftBracket2;
            range.tb.RightBracket2 = desc.rightBracket2;
            //clear styles of range
            range.ClearStyle(desc.styles.ToArray());
            //highlight syntax
            foreach (var rule in desc.rules)
                range.SetStyle(rule.style, rule.Regex);
            //clear folding
            range.ClearFoldingMarkers();
            //folding markers
            foreach (var folding in desc.foldings)
                range.SetFoldingMarkers(folding.startMarkerRegex, folding.finishMarkerRegex, folding.options);

            //
            RestoreBrackets(range.tb, oldBrackets);
        }
예제 #9
0
        public static SyntaxDescriptor ParseXmlDescription(XmlDocument doc)
        {
            var desc = new SyntaxDescriptor();
            XmlNode brackets = doc.SelectSingleNode("doc/brackets");
            if (brackets != null) {
                if (brackets.Attributes != null && (brackets.Attributes["left"] == null || brackets.Attributes["right"] == null || brackets.Attributes["left"].Value == "" || brackets.Attributes["right"].Value == "")) {
                    desc.leftBracket  = '\x0';
                    desc.rightBracket = '\x0';
                }
                else {
                    if (brackets.Attributes != null) {
                        desc.leftBracket  = brackets.Attributes["left" ].Value[0];
                        desc.rightBracket = brackets.Attributes["right"].Value[0];
                    }
                }

                if (brackets.Attributes != null && (brackets.Attributes["left2"] == null || brackets.Attributes["right2"] == null || brackets.Attributes["left2"].Value == "" || brackets.Attributes["right2"].Value == "")) {
                    desc.leftBracket2  = '\x0';
                    desc.rightBracket2 = '\x0';
                }
                else {
                    if (brackets.Attributes != null) {
                        desc.leftBracket2  = brackets.Attributes["left2" ].Value[0];
                        desc.rightBracket2 = brackets.Attributes["right2"].Value[0];
                    }
                }

                if (brackets.Attributes != null && (brackets.Attributes["strategy"] == null || brackets.Attributes["strategy"].Value == ""))
                    desc.bracketsHighlightStrategy = BracketsHighlightStrategy.Strategy2;
                else if (brackets.Attributes != null)
                    desc.bracketsHighlightStrategy = (BracketsHighlightStrategy) Enum.Parse(typeof(BracketsHighlightStrategy), brackets.Attributes["strategy"].Value);
            }

            var styleByName = new Dictionary<string, Style>();

            var xmlNodeList = doc.SelectNodes("doc/style");
            if (xmlNodeList != null)
                foreach (XmlNode style in xmlNodeList) {
                    var s = ParseStyle(style);
                    if (s == null) continue;
                    if (style.Attributes != null) styleByName[style.Attributes["name"].Value] = s;
                    desc.styles.Add(s);
                }
            var selectNodes = doc.SelectNodes("doc/rule");
            if (selectNodes != null)
                foreach (XmlNode rule in selectNodes)
                    desc.rules.Add(ParseRule(rule, styleByName));
            foreach (XmlNode folding in doc.SelectNodes("doc/folding"))
                desc.foldings.Add(ParseFolding(folding));

            return desc;
        }
 public void HighlightSyntax(SyntaxDescriptor desc, Range range)
 {
     range.tb.ClearStylesBuffer();
     int num;
     for (var i = 0; i < desc.styles.Count; i = num + 1)
     {
         range.tb.Styles[i] = desc.styles[i];
         num = i;
     }
     var oldBrackets = RememberBrackets(range.tb);
     range.tb.LeftBracket = desc.leftBracket;
     range.tb.RightBracket = desc.rightBracket;
     range.tb.LeftBracket2 = desc.leftBracket2;
     range.tb.RightBracket2 = desc.rightBracket2;
     range.ClearStyle(desc.styles.ToArray());
     foreach (var current in desc.rules)
     {
         range.SetStyle(current.style, current.Regex);
     }
     range.ClearFoldingMarkers();
     foreach (var current2 in desc.foldings)
     {
         range.SetFoldingMarkers(current2.startMarkerRegex, current2.finishMarkerRegex, current2.options);
     }
     RestoreBrackets(range.tb, oldBrackets);
 }
 public static SyntaxDescriptor ParseXmlDescription(XmlDocument doc)
 {
     var syntaxDescriptor = new SyntaxDescriptor();
     var xmlNode = doc.SelectSingleNode("doc/brackets");
     var flag = xmlNode != null;
     if (flag)
     {
         var flag2 = xmlNode.Attributes["left"] == null || xmlNode.Attributes["right"] == null ||
                     xmlNode.Attributes["left"].Value == "" || xmlNode.Attributes["right"].Value == "";
         if (flag2)
         {
             syntaxDescriptor.leftBracket = '\0';
             syntaxDescriptor.rightBracket = '\0';
         }
         else
         {
             syntaxDescriptor.leftBracket = xmlNode.Attributes["left"].Value[0];
             syntaxDescriptor.rightBracket = xmlNode.Attributes["right"].Value[0];
         }
         var flag3 = xmlNode.Attributes["left2"] == null || xmlNode.Attributes["right2"] == null ||
                     xmlNode.Attributes["left2"].Value == "" || xmlNode.Attributes["right2"].Value == "";
         if (flag3)
         {
             syntaxDescriptor.leftBracket2 = '\0';
             syntaxDescriptor.rightBracket2 = '\0';
         }
         else
         {
             syntaxDescriptor.leftBracket2 = xmlNode.Attributes["left2"].Value[0];
             syntaxDescriptor.rightBracket2 = xmlNode.Attributes["right2"].Value[0];
         }
         var flag4 = xmlNode.Attributes["strategy"] == null || xmlNode.Attributes["strategy"].Value == "";
         if (flag4)
         {
             syntaxDescriptor.bracketsHighlightStrategy = BracketsHighlightStrategy.Strategy2;
         }
         else
         {
             syntaxDescriptor.bracketsHighlightStrategy =
                 (BracketsHighlightStrategy)
                     Enum.Parse(typeof (BracketsHighlightStrategy), xmlNode.Attributes["strategy"].Value);
         }
     }
     var dictionary = new Dictionary<string, Style>();
     foreach (XmlNode xmlNode2 in doc.SelectNodes("doc/style"))
     {
         var style = ParseStyle(xmlNode2);
         dictionary[xmlNode2.Attributes["name"].Value] = style;
         syntaxDescriptor.styles.Add(style);
     }
     foreach (XmlNode ruleNode in doc.SelectNodes("doc/rule"))
     {
         syntaxDescriptor.rules.Add(ParseRule(ruleNode, dictionary));
     }
     foreach (XmlNode foldingNode in doc.SelectNodes("doc/folding"))
     {
         syntaxDescriptor.foldings.Add(ParseFolding(foldingNode));
     }
     return syntaxDescriptor;
 }