Beispiel #1
0
        /// <summary>
        /// Looks for the configuration with given name in the specified container.
        /// </summary>
        /// <param name="container"></param>
        /// <param name="lexemStart"></param>
        /// <returns></returns>
        private ConfigLexem GetConfigLexem(IConfigLexem container, string lexemStart)
        {
            ConfigLexem lexem = null;

            // Searches configuration.
            foreach (IConfigLexem lexemTemp in container.SubLexems)
            {
                if (lexemTemp.IsEqualToBegin(lexemStart))
                {
                    lexem = lexemTemp as ConfigLexem;
                    break;
                }
            }

            // If it was not found, then create new one.
            if (lexem == null)
            {
                lexem = new ConfigLexem(lexemStart, "", FormatType.Text, false);
                container.SubLexems.Add(lexem);

                // ParentConfig will be updated in ResetCaches, but the newly created configuration cannot be used without ParentConfig being set.
                lexem.ParentConfig = container;
            }

            return(lexem);
        }
Beispiel #2
0
        /// <summary>
        /// Creates and initiallizes form.
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            this.AutoScaleMode = AutoScaleMode.Font;
            try
            {
                System.Drawing.Icon ico = new System.Drawing.Icon(GetIconFile(GetIconFile(@"..\\..\\\logo.ico")));
                this.Icon = ico;
            }
            catch { }
            Customization();
            // Creates new file using C# language configuration.
            editControl1.NewFile(editControl1.Configurator["C#"]);

            // Creates format for methods coloring.
            ISnippetFormat formatMethod = editControl1.Language.Add("Method", "Text");

            formatMethod.FontColor = Color.HotPink;

            // Creates format for properties coloring.
            ISnippetFormat formatProperty = editControl1.Language.Add("Property", "Text");

            formatProperty.FontColor = Color.Goldenrod;

            // Disables ContextChoiceList dropping after dot in global context.
            ConfigLexem lexemDot_ = GetConfigLexem((IConfigLexem)editControl1.Language, ".");

            lexemDot_.DropContextChoiceList = false;

            // Adds "this" word processing for global context.
            ConfigLexem lexemThis = GetConfigLexem((IConfigLexem)editControl1.Language, "this");

            lexemThis.Type = FormatType.String;
            // "this" starts it`s own context. It does not have EndBlock specified, so the first unprocessed token will force parser to exit from "this"'s context.
            lexemThis.IsComplex = true;

            // Adds "." processing for "this" context: if "this" is followed by "." then the dot will
            // have "lexemDot" configuration.
            ConfigLexem lexemDot = GetConfigLexem((IConfigLexem)lexemThis, ".");

            lexemDot.Type = FormatType.Operator;
            // "." can drop context choice list
            lexemDot.DropContextChoiceList = true;
            lexemDot.IsComplex             = true;

            // Add configuration for "Property1"
            ConfigLexem this_Property1 = GetConfigLexem((IConfigLexem)lexemDot, "Property1");

            this_Property1.Type      = FormatType.Custom; this_Property1.FormatName = "Property";
            this_Property1.IsComplex = true;

            // Add configuration for "." after "Property1"
            ConfigLexem propertyDot = GetConfigLexem((IConfigLexem)this_Property1, ".");

            propertyDot.Type = FormatType.Operator;
            propertyDot.DropContextChoiceList = true;
            propertyDot.IsComplex             = true;
            propertyDot.Priority = 10;

            // Add "Method1" configuration after "this.Property1."
            ConfigLexem property_Method1 = GetConfigLexem((IConfigLexem)propertyDot, "Method1");

            property_Method1.Type      = FormatType.Custom; property_Method1.FormatName = "Method";
            property_Method1.IsComplex = true;

            // Add "Method2" configuration after "this.Property1."
            ConfigLexem property_Method2 = GetConfigLexem((IConfigLexem)propertyDot, "Method2");

            property_Method2.Type      = FormatType.Custom; property_Method2.FormatName = "Method";
            property_Method2.IsComplex = true;

            // Add "TestMethod" configuration after "this."
            ConfigLexem this_Method1 = GetConfigLexem((IConfigLexem)lexemDot, "TestMethod");

            this_Method1.Type = FormatType.Custom; this_Method1.FormatName = "Method";
            // needed for processing "(" and ")" next.
            this_Method1.IsComplex = true;

            // Add "GenerateMap" configuration after "this."
            ConfigLexem this_Method2 = GetConfigLexem((IConfigLexem)lexemDot, "GenerateMap");

            this_Method2.Type = FormatType.Custom; this_Method2.FormatName = "Method";
            // needed for processing "(" and ")" next.
            this_Method2.IsComplex = true;

            // Adds processing of the "(" after "this.Property1.Method1"
            ConfigLexem this_Method1_Braces = GetConfigLexem((IConfigLexem)this_Method1, "(");

            //Processing is done until ")" is found.
            this_Method1_Braces.EndBlock = ")";
            this_Method1_Braces.Type     = FormatType.Operator;
            // Lexem with this config starts it`s own context.
            this_Method1_Braces.IsComplex = true;
            // ContextPrompt is dropped after entering "("
            this_Method1_Braces.DropContextPrompt = true;
            // Needed to override "(" from the global context.
            this_Method1_Braces.Priority = 10;

            ConfigLexem this_Method2_Braces = GetConfigLexem((IConfigLexem)this_Method2, "(");

            this_Method2_Braces.EndBlock          = ")";
            this_Method2_Braces.Type              = FormatType.Operator;
            this_Method2_Braces.IsComplex         = true;
            this_Method2_Braces.DropContextPrompt = true;
            this_Method2_Braces.Priority          = 10;

            // ResetCaches needed for resetting all configuration caches. Without ResetCaches user changes will not be used.
            editControl1.Language.ResetCaches();

            // Fills collection of descriptions for lexemes with different configurations.
            m_MethodComments[this_Method1.ID]     = "Test description";
            m_MethodComments[this_Method2.ID]     = "Generates Some Specific Map....or just tests descriptions in context choice list";
            m_MethodComments[this_Property1.ID]   = "The only one property\nIt has multiline description";
            m_MethodComments[property_Method1.ID] = "Method 1";
            m_MethodComments[property_Method2.ID] = "Method 2";

            // Fills collection of prompts, assigned to different lexeme configurations.
            m_MethodPrompts[this_Method1.ID] = new DictionaryEntry[]
            {
                new DictionaryEntry(this_Method1.BeginBlock + "()", m_MethodComments[this_Method1.ID]),
                new DictionaryEntry(this_Method1.BeginBlock + "( int testData )",
                                    (string)m_MethodComments[this_Method1.ID] + "\ntestData should be specified"),
                new DictionaryEntry(this_Method1.BeginBlock + "( int testData, string testParam )",
                                    (string)m_MethodComments[this_Method1.ID] + "\ntestData and testParam should be specified")
            };

            m_MethodPrompts[this_Method2.ID] = new DictionaryEntry[]
            {
                new DictionaryEntry(this_Method2.BeginBlock + "()", m_MethodComments[this_Method2.ID])
            };

            // Sets text to be displayed.
            editControl1.Text = @"/* To see how the Context Choice list works, type ""this."" or ""this.Property1."" (if you have closed the popup window, you can re-open it with CTRL+Space shortcut)

To see how the Context ToolTip works move the mouse over some text and you will see information tooltip about text under cursor and description, if available.

To see how the Context Prompt feature works, type ""this.TestMethod("" and you will see list of the overloaded implementations of ""TestMethod"" methods. */

// Examples:  
this. //<- Press CTRL+Space to display the context choice list.

this.TestMethod( //<- Press CTRL+SHIFT+Space after ""("" to display the contextprompt items.

this.GenerateMap(); // Move the mouse over ""GenerateMap"" to see the context tooltip.
";

            // Resets undo buffer, so the user cannot undo setting of the text.
            editControl1.ResetUndoInfo();
        }