/// <summary>
        /// Gets the styles for a <see cref="Scintilla"/> from the Notepad++'s XML style files for a given lexer.
        /// </summary>
        /// <param name="document">The XML document to read the lexer style from.</param>
        /// <param name="scintilla">The <see cref="Scintilla"/> which lexer style to set.</param>
        /// <param name="lexerType">A <see cref="LexerEnumerations.LexerType"/> enumeration.</param>
        /// <returns><c>true</c> if the operations was successful, <c>false</c> otherwise.</returns>
        public static bool LoadLexerStyleFromNotepadPlusXml(XDocument document, Scintilla scintilla,
                                                            LexerEnumerations.LexerType lexerType)
        {
            try
            {
                var nodes = document.Descendants(XName.Get("LexerType")).Where(f =>
                                                                               f.Attribute("name")?.Value == LexerTypeName.GetLexerXmlName(lexerType)).Descendants();

                // loop through the color definition elements..
                foreach (var node in nodes)
                {
                    var style = XmlStyleNotepadPlusPlusHelper.FromXElement(node);

                    if (style.ColorForeground != Color.Empty)
                    {
                        scintilla.Styles[style.StyleId].ForeColor = style.ColorForeground;
                    }

                    if (style.ColorBackground != Color.Empty)
                    {
                        scintilla.Styles[style.StyleId].BackColor = style.ColorBackground;
                    }

                    scintilla.Styles[style.StyleId].Bold   = style.Bold;
                    scintilla.Styles[style.StyleId].Italic = style.Italic;
                }

                return(true);
            }
            catch
            {
                // an error occurred so return false..
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// Gets the name of the lexer XML used in Notepad++'s XML style files.
        /// </summary>
        /// <param name="lexerType">Type of the lexer.</param>
        /// <returns>The name of the lexer used in Notepad++'s XML style files if successful; otherwise "text".</returns>
        public static string GetLexerXmlName(LexerEnumerations.LexerType lexerType)
        {
            var result = LexerTypeNameList.FirstOrDefault(f => f.Item1 == lexerType);

            return(result == null ? "text" : result.Item2);
        }
示例#3
0
        /// <summary>
        /// Gets the type of the lexer by a given <see cref="LexerEnumerations.LexerType"/> enumeration.
        /// </summary>
        /// <param name="lexerType">Type of the lexer.</param>
        /// <returns>A <see cref="Lexer"/> matching the given <see cref="LexerEnumerations.LexerType"/> enumeration.</returns>
        public static Lexer GetLexerByLexerType(LexerEnumerations.LexerType lexerType)
        {
            var result = LexerTypeNameList.FirstOrDefault(f => f.Item1 == lexerType);

            return(result?.Item3 ?? Lexer.Null);
        }