Articles in this section
Category / Section

How to populate Intellisence popup in EditControl from Assemblies?

3 mins read

In Microsoft Visual Studio TextEditor Intellisense popup items will be configured from assemblies loaded in sample application. As like it, EditControl Intellisense popup can also be configured from user defined assemblies.

 

For example

 

This article will guide you to configure the same.

 

Step 1: Choose the required assembly from “Syncfusion\Essential Studio\[Installed Version]\precompiledassemblies\[Installed Version]\4.0\”

 

Step 2: Implement a Dialog window to display the list of Public class available in selected assembly.

 

C#

/// <summary>
/// Summary description for TypeSelectionDialog.
/// </summary>
public class ClassTypeSelectionDialog : System.Windows.Forms.Form
{
private System.Windows.Forms.Button bOK;
private System.Windows.Forms.Button bCancel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ListBox typeList;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
 
public ClassTypeSelectionDialog()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
 
//
// TODO: Add any constructor code after InitializeComponent call
//
}
 
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
 
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.typeList = new System.Windows.Forms.ListBox();
this.bOK = new System.Windows.Forms.Button();
this.bCancel = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// typeList
//
this.typeList.Location = new System.Drawing.Point(0, 64);
this.typeList.Name = "typeList";
this.typeList.Size = new System.Drawing.Size(296, 147);
this.typeList.TabIndex = 0;
this.typeList.DoubleClick += new System.EventHandler(this.typeList_DoubleClick);
this.typeList.SelectedIndexChanged += new System.EventHandler(this.typeList_SelectedIndexChanged);
//
// bOK
//
this.bOK.Enabled = false;
this.bOK.Location = new System.Drawing.Point(128, 232);
this.bOK.Name = "bOK";
this.bOK.TabIndex = 1;
this.bOK.Text = "OK";
this.bOK.Click += new System.EventHandler(this.bOK_Click);
//
// bCancel
//
this.bCancel.Location = new System.Drawing.Point(208, 232);
this.bCancel.Name = "bCancel";
this.bCancel.TabIndex = 2;
this.bCancel.Text = "Cancel";
this.bCancel.Click += new System.EventHandler(this.bCancel_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(280, 32);
this.label1.TabIndex = 3;
this.label1.Text = "Select the Control type to trace";
//
// TypeSelectionDialog
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.bCancel,
this.bOK,
this.typeList});
this.Name = "TypeSelectionDialog";
this.Text = "Public Classes";
this.ResumeLayout(false);
 
}
#endregion
 
Assembly assembly;
public Assembly Assembly
{
set
{
assembly = value;
PopulateTypeList();
}
}
 
void PopulateTypeList()
{
typeList.Items.Clear();
 
foreach (Module module in assembly.GetModules())
{
foreach (Type type in module.GetTypes())
{
if (type.IsSubclassOf(typeof(Control)))
{
typeList.Items.Add(type.FullName);
}
}
}
}
 
string selectedType;
 
public string SelectedType
{
get
{
return selectedType;
}
}
 
private void typeList_DoubleClick(object sender, System.EventArgs e)
{
selectedType = (string)typeList.SelectedItem;
DialogResult = DialogResult.OK;
}
 
private void bCancel_Click(object sender, System.EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
 
private void bOK_Click(object sender, System.EventArgs e)
{
selectedType = (string)typeList.SelectedItem;
DialogResult = DialogResult.OK;
}
 
private void typeList_SelectedIndexChanged(object sender, System.EventArgs e)
{
bOK.Enabled = true;
}
}

 

Step 3: Need to add all the public Properties and Functions of selected class in dialog window.

 

C#   

 
OpenFileDialog openFileDialog = new OpenFileDialog();
 
openFileDialog.Filter = ".net assemblies (*.exe, *.dll)|*.dll;*.exe|All files (*.*)|*.*";
 
openFileDialog.FilterIndex = 1;
 
openFileDialog.RestoreDirectory = true;
 
string selectedClass = null;
 
PropertyList.Clear();
 
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
assembly = Assembly.LoadFrom(openFileDialog.FileName);
}
catch (Exception)
{
MessageBox.Show("This is not a valid assembly");
return;
}
 
//For Selecting Class file
ClassTypeSelectionDialog typeSelectionDialog = new ClassTypeSelectionDialog();
 
//Add all Class file for selected assembly
typeSelectionDialog.Assembly = assembly;
 
if (typeSelectionDialog.ShowDialog() == DialogResult.OK)
{
string[] tokens = typeSelectionDialog.SelectedType.Split('.');
selectedClass = tokens.Last();
}
}
 
if (assembly != null)
{
foreach (Module module in assembly.GetModules())
{
foreach (Type type in module.GetTypes())
{
if (type.IsSubclassOf(typeof(Control)) && type.Name == selectedClass)
{
foreach (PropertyInfo item in type.GetProperties())
{
if (item.PropertyType.IsPublic)
{
 
if (PropertyList.Count < 15)
{
PropertyList.Add(item.Name);
}
else
break;
}
}
foreach (MethodInfo item in type.GetMethods())
{
if (item.IsPublic)
{
if (FunctionList.Count < 15)
{
FunctionList.Add(new FunctionInformation(item.Name, item.GetParameters()));
}
else
break;
}
}
}
}
}
}
else
{
MessageBox.Show("Please select the dll");
}
    

    

Step 4: Populate all Properties and Functions information in Context Choice Popup.    

    

This requirement can be achieved by handling ContextChoiceOpen, ContextChoiceBeforeOpen, ContextPromptOpen events in EditControl. The following code demonstrates the same.        

 

C#    

    
// Occurs before Function Parameter opens
private void EditControl1_ContextPromptOpen(object sender, Syncfusion.Windows.Forms.Edit.ContextPromptUpdateEventArgs e)
{
 
this.contextPromptLexem = e.LexemBeforeDropper.Text;
 
PopulateContextPromptItems(e);
 
}
 
// Occurs after Context choice open
private void EditControl1_ContextChoiceOpen(IContextChoiceController controller)
{
 
if (assembly == null)
{
 
controller.Items.Add("Chat", "This is Chat");
 
controller.Items.Add("Database", "This is Database");
 
controller.Items.Add("NewFile", "This is NewFile");
 
controller.Items.Add("Find", "This is Find");
 
controller.Items.Add("Home", "This is Home");
 
controller.Items.Add("PieChart", "This is PieChart");
 
controller.Items.Add("Tools", "This is Tools");
 
}
 
else
{
 
foreach (string item in this.PropertyList)
{
 
controller.Items.Add(item, "This is " + item);
 
}
 
foreach (FunctionInformation item in this.FunctionList)
{
 
controller.Items.Add(item.FunctionName);
 
}
}
}
 
// Occurs before Context Choice close
private void EditControl1_ContextChoiceClose(IContextChoiceController controller, DialogResult dialogresult)
{
 
controller.Items.Clear();
 
}
 
// Occurs before Content Choice popup is displayed
private void EditControl1_ContextChoiceBeforeOpen(object sender, CancelEventArgs e)
{
 
ILexem lex;
 
ILexemLine lexemLine = this.editControl1.GetLine(this.editControl1.CurrentLine);
 
//Gets the index of the current word in that line
 
int ind = GetContextChoiceCharIndex(lexemLine);
 
if (ind <= 0)
{
 
e.Cancel = true;
 
return;
 
}
 
lex = lexemLine.LineLexems[ind - 1] as ILexem;
 
// If the count is less than '2', do not show the ContextChoice popup
 
if (lexemLine.LineLexems.Count < 2)
 
e.Cancel = true;
 
else
{
 
// Display ContextChoice popup if the lexem used to invoke them is "this" or "me" only
 
if ((lex.Text == "this") || (lex.Text == "me"))
{
 
e.Cancel = false;
 
}
else
{
 
e.Cancel = true;
 
}
}
}
 
// Method that populates the context prompt list based on the lexem invoking it
private void PopulateContextPromptItems(ContextPromptUpdateEventArgs e)
{
 
if (assembly == null)
{
 
switch (this.contextPromptLexem)
{
 
case "Chat":
 
e.List.Clear();
 
e.AddPrompt("Chat(string chatText, int senderID, int receiverID, int 
connectionID)", "Specify the chat text, the sender information, the receiver information and the connection ID");
 
e.AddPrompt("Chat(string chatText, int senderID, bool isBroadCast)", "Specify the chat text, the sender information, and if its a broadcast");
 
break;
 
case "Database":
 
e.List.Clear();
 
e.AddPrompt("Database()", "Create a new database");
 
e.AddPrompt("Database(string dataBaseName)", "Create a new database with the specified name");
 
break;
 
case "NewFile":
 
e.List.Clear();
 
e.AddPrompt("NewFile()", "Create a new file");
 
e.AddPrompt("NewFile(string fileName)", "Create a new file with the specified name");
 
break;
 
case "Find":
 
e.List.Clear();
 
e.AddPrompt("Find()", "Display the Find dialog");
 
e.AddPrompt("Find(string searchText)", "Find occurences of the specified search text");
 
e.AddPrompt("Find(string searchText, bool searchUp)", "Find occurences of the specified search text and search up if specified");
 
break;
 
case "Home":
 
e.List.Clear();
 
e.AddPrompt("Home()", "Go to the initial application form");
 
break;
 
case "PieChart":
 
e.List.Clear();
 
e.AddPrompt("PieChart()", "Create an empty Pie-chart");
 
e.AddPrompt("PieChart(string[] sectionNames, int[] sectionAngles)", "Create a Pie-chart 
containing the specified sections with the specified angles information");
 
e.AddPrompt("PieChart(string[] sectionNames, int[] sectionAngles, Color[] sectionColors)", "Create a Pie-chart containing the specified sections with the specified angles and color information");
 
break;
 
case "Tools":
 
e.List.Clear();
 
e.AddPrompt("Tools()", "Display the Tools dialog");
 
e.AddPrompt("Tools(int ToolID)", "Display the Tools dialog and select the specified 
Tool");
 
break;
 
}
}
else
{
 
foreach (FunctionInformation item in this.FunctionList)
{
 
if (this.contextPromptLexem.ToLower() == item.FunctionName.ToLower())
{
 
e.AddPrompt(item.FunctionName, "This is " + item.FunctionName);
 
foreach (ParameterInfo param in item.Parameters)
{
 
e.AddPrompt(item.FunctionName + "(" + param.Name + ")", param.Name);
 
}
}
}
}
}
    

 

Screenshot

 

Showing assemblies

Figure 1: Choose any Syncfusion assembly.

 

Select public class file of selected assembly

Figure 2: Select public Class file of selected assembly.

 

Public properties in selected class will be listed in EditControl

Figure 3: Public Properties in selected class will be listed in EditControl Intellisense popup. 

 

Public functions with parameter information in selected class listed in EditControl

Figure 4: Public Functions with Parameter information in selected class will be listed in EditControl Intellisense popup.

    

Samples:

 

C#: EditControlExample    

 

VB: EditControlSample

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied