
Proper Way of Adding Items to Project Context Menu
This is the first FlashDevelop Plugin I'm creating.
In this plugin, I would like to extend the context menu of another Plugin, namely the ProjectManager Plugin.
I would like to add further options to the "Add" dropdown menu item.
I actually have already managed to find a way to add items to the "Add" context menu, but I would like to hear your feedback whether my solution is making sense or whether this is a dirty hack.

The way I did this was:
- I have added a reference to the ProjectManager.dll in my plugin project.
- In the Initialize method of my PluginMain class, I register for the EventType.Command event.
Code:
public void Initialize()
{
EventManager.AddEventHandler(this, EventType.Command);
}
- In the HandleEvent method, I check whether the sender is of type ProjectTreeView, to see whether the event was dispatched by updating the ProjectTreeView object. If I understand this correctly after looking at the ProjectManager plugins source code and tracing the events received by my own plugin, the context menu is rebuilt every time I click something in the ProjectManagers tree view.
Code:
switch(e.Type)
{
case EventType.Command:
if(sender is ProjectManager.Controls.TreeView.ProjectTreeView)
{
CreateAddMenuItems(sender as ProjectManager.Controls.TreeView.ProjectTreeView);
}
break;
}
- Finally, in the method I call if the sender actually is the ProjectTreeView, I access the parent of the parent of the PluginTreeView which should be PluginUI object, and retrieve the context menu from there.
Code:
private void CreateAddMenuItems(ProjectManager.Controls.TreeView.ProjectTreeView pluginTreeView)
{
PluginUI pluginUI = pluginTreeView.Parent.Parent as PluginUI;
ToolStripMenuItem AddMenu = pluginUI.Menu.AddMenu;
AddMenu.DropDownItems.Add(new ToolStripSeparator());
}
So, the method above works, I can reliably add items to the "Add" context menu in the ProjectManager panel.
But is this the proper way of doing this? Accessing the parent of the parent of the PluginTreeView and hoping that it actually is the PluginUI feels a little hacked.
Any suggestions for improving this?