Ejemplo n.º 1
0
        /// <summary>
        /// A helper method to be used with HTML including scripts.
        /// </summary>
        /// <param name="lexerType">Type of the lexer to embed into the HTML lexer.</param>
        /// <param name="scintilla">An instance to a scintilla to which to append the script lexer.</param>
        /// <param name="lexerColors">A <see cref="LexerColors"/> class instance for the lexer coloring.</param>
        public static void SetScriptedHtml(LexerType lexerType, Scintilla scintilla, LexerColors.LexerColors lexerColors)
        {
            if (lexerType == LexerType.PHP || lexerType == LexerType.HTML)
            {
                SetHtmlStyles(scintilla, lexerColors);

                if (lexerType == LexerType.PHP)
                {
                    var keyWords =
                        ScintillaKeyWords.KeyWordList.FirstOrDefault(f => f.LexerType == LexerType.HTML);

                    if (keyWords != null)
                    {
                        scintilla.SetKeywords(1, keyWords.KeyWords);
                    }
                }
                else if (lexerType == LexerType.HTML)
                {
                    var keyWords =
                        ScintillaKeyWords.KeyWordList.FirstOrDefault(f => f.LexerType == LexerType.PHP);

                    if (keyWords != null)
                    {
                        scintilla.SetKeywords(1, keyWords.KeyWords);
                    }
                }


                LexerFoldProperties.SetScintillaProperties(scintilla, LexerFoldProperties.HyperTextFolding);

                SetHtmlStyles(scintilla, lexerColors);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a "standard" folding to a lexer with given foreground and background colors.
        /// </summary>
        /// <param name="scintilla">An instance to a Scintilla class.</param>
        /// <param name="foregroundColor">The foreground color to be used.</param>
        /// <param name="backgroundColor">The background color to be used.</param>
        internal static void AddFolding(Scintilla scintilla, Color foregroundColor, Color backgroundColor)
        {
            // the default colors as in the example.. (C)::https://github.com/jacobslusser/ScintillaNET/wiki/Automatic-Code-Folding

            // Instruct the lexer to calculate folding..
            LexerFoldProperties.FoldDefault(scintilla);

            // Configure a margin to display folding symbols
            scintilla.Margins[2].Type      = MarginType.Symbol;
            scintilla.Margins[2].Mask      = Marker.MaskFolders;
            scintilla.Margins[2].Sensitive = true;
            scintilla.Margins[2].Width     = 20;


            // Set colors for all folding markers
            for (int i = 25; i <= 31; i++)
            {
                scintilla.Markers[i].SetForeColor(foregroundColor);
                scintilla.Markers[i].SetBackColor(backgroundColor);
            }

            // Configure folding markers with respective symbols
            scintilla.Markers[Marker.Folder].Symbol        = MarkerSymbol.BoxPlus;
            scintilla.Markers[Marker.FolderOpen].Symbol    = MarkerSymbol.BoxMinus;
            scintilla.Markers[Marker.FolderEnd].Symbol     = MarkerSymbol.BoxPlusConnected;
            scintilla.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner;
            scintilla.Markers[Marker.FolderOpenMid].Symbol = MarkerSymbol.BoxMinusConnected;
            scintilla.Markers[Marker.FolderSub].Symbol     = MarkerSymbol.VLine;
            scintilla.Markers[Marker.FolderTail].Symbol    = MarkerSymbol.LCorner;

            // Enable automatic folding
            scintilla.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the lexer for a given Scintilla class instance for the Structured Query Language (SQL).
        /// </summary>
        /// <param name="scintilla">A Scintilla class instance to set the lexer style for.</param>
        /// <param name="lexerColors">A <see cref="LexerColors"/> class instance for the lexer coloring.</param>
        /// <returns>True if the operation was successful; otherwise false.</returns>
        public static bool CreateSqlLexer(Scintilla scintilla, LexerColors.LexerColors lexerColors)
        {
            ClearStyle(scintilla);

            // KEYWORD, fontStyle = 1
            scintilla.Styles[Style.Sql.Word].Bold      = true;
            scintilla.Styles[Style.Sql.Word].ForeColor = lexerColors[LexerType.SQL, "WordFore"];
            scintilla.Styles[Style.Sql.Word].BackColor = lexerColors[LexerType.SQL, "WordBack"];

            // NUMBER, fontStyle = 0
            scintilla.Styles[Style.Sql.Number].ForeColor = lexerColors[LexerType.SQL, "NumberFore"];
            scintilla.Styles[Style.Sql.Number].BackColor = lexerColors[LexerType.SQL, "NumberBack"];

            // STRING, fontStyle = 0
            scintilla.Styles[Style.Sql.String].ForeColor = lexerColors[LexerType.SQL, "StringFore"];
            scintilla.Styles[Style.Sql.String].BackColor = lexerColors[LexerType.SQL, "StringBack"];

            // STRING2, fontStyle = 0
            scintilla.Styles[Style.Sql.Character].ForeColor =
                lexerColors[LexerType.SQL, "CharacterFore"];
            scintilla.Styles[Style.Sql.Character].BackColor =
                lexerColors[LexerType.SQL, "CharacterBack"];

            // OPERATOR, fontStyle = 1
            scintilla.Styles[Style.Sql.Operator].Bold      = true;
            scintilla.Styles[Style.Sql.Operator].ForeColor =
                lexerColors[LexerType.SQL, "OperatorFore"];
            scintilla.Styles[Style.Sql.Operator].BackColor =
                lexerColors[LexerType.SQL, "OperatorBack"];

            // COMMENT, fontStyle = 0
            scintilla.Styles[Style.Sql.Comment].ForeColor = lexerColors[LexerType.SQL, "CommentFore"];
            scintilla.Styles[Style.Sql.Comment].BackColor = lexerColors[LexerType.SQL, "CommentBack"];

            // COMMENT LINE, fontStyle = 0
            scintilla.Styles[Style.Sql.CommentLine].ForeColor =
                lexerColors[LexerType.SQL, "CommentLineFore"];
            scintilla.Styles[Style.Sql.CommentLine].BackColor =
                lexerColors[LexerType.SQL, "CommentLineBack"];

            scintilla.Lexer = Lexer.Sql;

            ScintillaKeyWords.SetKeywords(scintilla, LexerType.SQL);

            LexerFoldProperties.SetScintillaProperties(scintilla, LexerFoldProperties.SqlFolding);

            AddFolding(scintilla);
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the lexer for a given Scintilla class instance for the XML (The eXtensible Markup Language).
        /// </summary>
        /// <param name="scintilla">A Scintilla class instance to set the lexer style for.</param>
        /// <param name="lexerColors">A <see cref="LexerColors"/> class instance for the lexer coloring.</param>
        /// <returns>True if the operation was successful; otherwise false.</returns>
        public static bool CreateXmlLexer(Scintilla scintilla, LexerColors.LexerColors lexerColors)
        {
            ClearStyle(scintilla);

            // XMLSTART, fontStyle = 0
            scintilla.Styles[Style.Xml.XmlStart].ForeColor =
                lexerColors[LexerType.Xml, "XmlStartFore"];
            scintilla.Styles[Style.Xml.XmlStart].BackColor =
                lexerColors[LexerType.Xml, "XmlStartBack"];

            // XMLEND, fontStyle = 0
            scintilla.Styles[Style.Xml.XmlEnd].ForeColor = lexerColors[LexerType.Xml, "XmlEndFore"];
            scintilla.Styles[Style.Xml.XmlEnd].BackColor = lexerColors[LexerType.Xml, "XmlEndBack"];

            // DEFAULT, fontStyle = 1
            scintilla.Styles[Style.Xml.Default].Bold      = true;
            scintilla.Styles[Style.Xml.Default].ForeColor = lexerColors[LexerType.Xml, "DefaultFore"];
            scintilla.Styles[Style.Xml.Default].BackColor = lexerColors[LexerType.Xml, "DefaultBack"];

            // COMMENT, fontStyle = 0
            scintilla.Styles[Style.Xml.Comment].ForeColor = lexerColors[LexerType.Xml, "CommentFore"];
            scintilla.Styles[Style.Xml.Comment].BackColor = lexerColors[LexerType.Xml, "CommentBack"];

            // NUMBER, fontStyle = 0
            scintilla.Styles[Style.Xml.Number].ForeColor = lexerColors[LexerType.Xml, "NumberFore"];
            scintilla.Styles[Style.Xml.Number].BackColor = lexerColors[LexerType.Xml, "NumberBack"];

            // DOUBLESTRING, fontStyle = 1
            scintilla.Styles[Style.Xml.DoubleString].Bold      = true;
            scintilla.Styles[Style.Xml.DoubleString].ForeColor =
                lexerColors[LexerType.Xml, "DoubleStringFore"];
            scintilla.Styles[Style.Xml.DoubleString].BackColor =
                lexerColors[LexerType.Xml, "DoubleStringBack"];

            // SINGLESTRING, fontStyle = 1
            scintilla.Styles[Style.Xml.SingleString].Bold      = true;
            scintilla.Styles[Style.Xml.SingleString].ForeColor =
                lexerColors[LexerType.Xml, "SingleStringFore"];
            scintilla.Styles[Style.Xml.SingleString].BackColor =
                lexerColors[LexerType.Xml, "SingleStringBack"];

            // TAG, fontStyle = 0
            scintilla.Styles[Style.Xml.Tag].ForeColor = lexerColors[LexerType.Xml, "TagFore"];
            scintilla.Styles[Style.Xml.Tag].BackColor = lexerColors[LexerType.Xml, "TagBack"];

            // TAGEND, fontStyle = 0
            scintilla.Styles[Style.Xml.TagEnd].ForeColor = lexerColors[LexerType.Xml, "TagEndFore"];
            scintilla.Styles[Style.Xml.TagEnd].BackColor = lexerColors[LexerType.Xml, "TagEndBack"];

            // TAGUNKNOWN, fontStyle = 0
            scintilla.Styles[Style.Xml.TagUnknown].ForeColor =
                lexerColors[LexerType.Xml, "TagUnknownFore"];
            scintilla.Styles[Style.Xml.TagUnknown].BackColor =
                lexerColors[LexerType.Xml, "TagUnknownBack"];

            // ATTRIBUTE, fontStyle = 0
            scintilla.Styles[Style.Xml.Attribute].ForeColor =
                lexerColors[LexerType.Xml, "AttributeFore"];
            scintilla.Styles[Style.Xml.Attribute].BackColor =
                lexerColors[LexerType.Xml, "AttributeBack"];

            // ATTRIBUTEUNKNOWN, fontStyle = 0
            scintilla.Styles[Style.Xml.AttributeUnknown].ForeColor =
                lexerColors[LexerType.Xml, "AttributeUnknownFore"];
            scintilla.Styles[Style.Xml.AttributeUnknown].BackColor =
                lexerColors[LexerType.Xml, "AttributeUnknownBack"];

            // SGMLDEFAULT, fontStyle = 0
            scintilla.Styles[21].ForeColor = lexerColors[LexerType.Xml, "SgmlDefaultFore"];
            scintilla.Styles[21].BackColor = lexerColors[LexerType.Xml, "SgmlDefaultBack"];

            // CDATA, fontStyle = 0
            scintilla.Styles[Style.Xml.CData].ForeColor = lexerColors[LexerType.Xml, "CDataFore"];
            scintilla.Styles[Style.Xml.CData].BackColor = lexerColors[LexerType.Xml, "CDataBack"];

            // ENTITY, fontStyle = 2
            scintilla.Styles[Style.Xml.Entity].Italic    = true;
            scintilla.Styles[Style.Xml.Entity].ForeColor = lexerColors[LexerType.Xml, "EntityFore"];
            scintilla.Styles[Style.Xml.Entity].BackColor = lexerColors[LexerType.Xml, "EntityBack"];

            scintilla.Lexer = Lexer.Xml;

            // folding for a XML lexer..
            LexerFoldProperties.SetScintillaProperties(scintilla, LexerFoldProperties.XmlFolding);

            AddFolding(scintilla);
            return(true);
        }