/// <summary> /// Creates the lexer from XML file used by the Notepad++ software. /// </summary> /// <param name="scintilla">The <see cref="Scintilla"/> which lexer style to set.</param> /// <param name="lexerType">Type of the lexer.</param> /// <param name="fileName">A file name to get the lexer type from.</param> /// <param name="useGlobalOverride">A flag indicating whether the style "Global override" should be set for the lexer from the XML document.</param> /// <param name="font">A flag indicating whether to use the defined font name from the XML document or not.</param> /// <param name="useWhiteSpace">A flag indicating whether to color the white space symbol.</param> /// <param name="useSelectionColors">A flag indicating whether to color the selection.</param> /// <param name="useMarginColors">A flag indicating whether to color the margin.</param> /// <returns><c>true</c> if the operation was successful, <c>false</c> otherwise.</returns> public static bool CreateLexerFromFile(Scintilla scintilla, LexerType lexerType, string fileName, bool useGlobalOverride, bool font, bool useWhiteSpace, bool useSelectionColors, bool useMarginColors) { try { XDocument document = XDocument.Load(fileName); ScintillaNotepadPlusPlusStyles.SetGlobalDefaultStyles(document, scintilla, useGlobalOverride, font); ScintillaNotepadPlusPlusStyles.LoadScintillaStyleFromNotepadPlusXml(document, scintilla, useWhiteSpace, useSelectionColors, useMarginColors); ScintillaNotepadPlusPlusStyles.LoadLexerStyleFromNotepadPlusXml(document, scintilla, lexerType); // TODO::Font? scintilla.Lexer = LexerTypeName.GetLexerByLexerType(lexerType); ScintillaKeyWords.SetKeywords(scintilla, lexerType); LexerFoldProperties.SetFoldProperties(scintilla, lexerType); ScintillaNotepadPlusPlusStyles.SetFolding(document, scintilla); System.Diagnostics.Debug.WriteLine(scintilla.DescribeKeywordSets()); return(true); } catch { return(false); } }
/// <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); } }