/// <summary> /// Fills context prompt menu. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void editControl1_ContextPromptOpen(object sender, Syncfusion.Windows.Forms.Edit.ContextPromptUpdateEventArgs e) { // First of all we should get lexem(if it is one), // which opens current region that supports context prompt dropping. ILexem lex = GetCurrentContextPromptDropper(); if (lex == null) { // If there is no such lexem, than we should not show context prompt. e.CloseForm = true; return; } IConfigLexem conf = lex.Config.ParentConfig; // If there is no prompts assigned to the found complex lexem, than we should exit. if (!m_MethodPrompts.Contains(conf.ID)) { return; } DictionaryEntry[] prompts = ( DictionaryEntry[] )m_MethodPrompts[conf.ID]; e.List.Clear(); // add prompts foreach (DictionaryEntry entry in prompts) { // Creates new context prompt item and adds it to the list of the prompts. ContextPromptItem itemNew = e.List.Add((string)entry.Key, (string)entry.Value); // Parses subject of the item, splits it to the set of method parameters // and adds every parameter as boldable item to the context prompt item. ParseContectPromptSubject(itemNew); } }
/// <summary> /// Parses contextprompt item's subject and adds all its parameters to the collection of bolded items. /// </summary> /// <param name="item"></param> private void ParseContectPromptSubject(ContextPromptItem item) { // Example: MethodName( int param, string param2 ) // will be matched as : 1) "int param", 2) "string param2" Regex regex = new Regex(@"\(\s*((?<param>[^,]+)\s*\,*\s*)*\s*\)"); Match match = regex.Match(item.Subject); if (match.Success) { foreach (Capture param in match.Groups["param"].Captures) { // Add matches to the list of bolded items. // Every bolded item has such properties: // BoldTextStart - starting index of the bolded substring of the subject // BoldTextLength - length of the bolded substring of the subject // Description - description, that should be shown when you select some bolded item. // Note: bolded items can not be selected automatically, // user should select them while processing ContextPromptUpdate event. ContextPromptBoldTextItem itemBolded = item.BoldedItems.Add(param.Index, param.Length, param.Value); } } }