/// <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);
            }
        }
Exemple #2
0
        private void describeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Scintilla scintilla = new Scintilla();

            scintilla.Lexer = Lexer.Cpp;
            MessageBox.Show(scintilla.DescribeKeywordSets());
        }
Exemple #3
0
    private void InitializeScintilla()
    {
        sci.Margins[0].Width = 32;
        sci.Lexer            = Lexer.Cpp;
        sci.Dock             = DockStyle.Fill;
        Console.WriteLine(sci.DescribeKeywordSets());

        sci.Styles[Style.Default].Font = "Consolas";
        sci.Styles[Style.Default].Size = 12;

        // Configure the CPP (C#, javascript) lexer styles
        sci.Styles[Style.Cpp.Default].ForeColor           = Color.Silver;
        sci.Styles[Style.Cpp.Comment].ForeColor           = Color.FromArgb(0, 128, 0);     // Green
        sci.Styles[Style.Cpp.CommentLine].ForeColor       = Color.FromArgb(0, 128, 0);     // Green
        sci.Styles[Style.Cpp.CommentLineDoc].ForeColor    = Color.FromArgb(128, 128, 128); // Gray
        sci.Styles[Style.Cpp.Number].ForeColor            = Color.Olive;
        sci.Styles[Style.Cpp.Word].ForeColor              = Color.Blue;
        sci.Styles[Style.Cpp.Word2].ForeColor             = Color.Blue;
        sci.Styles[Style.Cpp.String].ForeColor            = Color.FromArgb(163, 21, 21); // Red
        sci.Styles[Style.Cpp.Character].ForeColor         = Color.FromArgb(163, 21, 21); // Red
        sci.Styles[Style.Cpp.Verbatim].ForeColor          = Color.FromArgb(163, 21, 21); // Red
        sci.Styles[Style.Cpp.StringEol].BackColor         = Color.Pink;
        sci.Styles[Style.Cpp.Operator].ForeColor          = Color.Purple;
        sci.Styles[Style.Cpp.Preprocessor].ForeColor      = Color.Maroon;
        sci.Styles[Style.Cpp.GlobalClass].ForeColor       = Color.Coral;
        sci.Styles[Style.Cpp.CommentDocKeyword].ForeColor = Color.LightBlue;

        sci.Styles[Style.BraceLight].BackColor = Color.LightGray;
        sci.Styles[Style.BraceLight].ForeColor = Color.BlueViolet;
        sci.Styles[Style.BraceBad].ForeColor   = Color.Red;
        //javascript keywords:  Style: Word
        sci.SetKeywords(0, @"abstract arguments break case catch const continue debugger default delete do
                                        else eval export extends false final finally for function goto if implements
                                        import in instanceof interface let native new null package private protected 
                                        public return short static super switch synchronized this throw throws 
                                        transient true try typeof var void volatile while with yield");

        //javascript secondary keywords (types)  - Style: Word2
        sci.SetKeywords(1, @"boolean byte char class double enum float int long");

        //documentation keywords (for things like doxygen)
        sci.SetKeywords(2, @"author authors brief");

        //javascript global classes and typedef keywords Style: GlobalClass
        sci.SetKeywords(3, @"Array Date eval hasOwnProperty Infinity isFinite isNaN isPrototypeOf length
                                        Math NaN name Number Object prototype String toString undefined valueOf");
        sci.TextChanged += TextWasChanged;
        sci.MarginClick += Scintilla_MarginClick;

        sci.SetProperty("fold", "1");
        sci.SetProperty("fold.compact", "1");

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

        // Set colors for all folding markers
        for (int i = 25; i <= 31; i++)
        {
            sci.Markers[i].SetForeColor(SystemColors.ControlLightLight);
            sci.Markers[i].SetBackColor(SystemColors.ControlDark);
        }

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

        sci.HScrollBar = false;

        // Enable automatic folding
        sci.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change);

        //Configure margins to display bookmarks
        sci.Margins[1].Width     = 16;
        sci.Margins[1].Sensitive = true;
        sci.Margins[1].Type      = MarginType.Symbol;
        //sci.Margins[3].Mask = Marker.MaskAll; //This line messes with the line folding
        sci.Margins[1].Cursor = MarginCursor.Arrow;

        sci.Markers[1].Symbol = MarkerSymbol.Circle;
        sci.Markers[1].SetBackColor(Color.DeepSkyBlue);
        sci.Markers[1].SetForeColor(Color.Black);
    }