View unanswered posts | View active topics


Reply to topic  [ 5 posts ] 
Proper Way of Adding Items to Project Context Menu 
Author Message
Member

Joined: Sat May 19, 2012 2:30 pm
Posts: 4
Post 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?


Sat May 19, 2012 3:59 pm
Profile
Member

Joined: Sat May 19, 2012 2:30 pm
Posts: 4
Post Re: Proper Way of Adding Items to Project Context Menu
Well, I've made a little improvement:
I've just found out that you can cast the NotifyEvent to a DataEvent if the EventType is "Command".

So now I'm not checking anymore whether the sender is of type ProjectTreeView, but instead check if the DataEvent.Action property is equal to ProjectManagerEvents.TreeSelectionChanged, which is a little more elegant at least.

Code:
case EventType.Command:
   DataEvent evt = (DataEvent)e;
   TraceManager.Add(evt.Action);
               
   if(evt.Action == ProjectManagerEvents.TreeSelectionChanged)
   {
      ...
   }


Still, has anybody feedback for me when it comes to accessing the AddMenu in the ProjectManagers context menu?


Sun May 20, 2012 12:26 pm
Profile
Member

Joined: Wed Apr 19, 2006 12:39 pm
Posts: 303
Post Re: Proper Way of Adding Items to Project Context Menu
you want to add new file types to the right click>add in the project manager?

If so they are already template files that you can edit.

From FD
Tools>Application Files...
Templates\ProjectFiles

There is a folder for each project type and within the folder is the templates. Is this what your after or something different?


Sun May 20, 2012 7:34 pm
Profile
Member

Joined: Sat May 19, 2012 2:30 pm
Posts: 4
Post Re: Proper Way of Adding Items to Project Context Menu
Ah, okay; I guess I could do it like that.

I want a custom wizard to appear after clicking the menu items, though, but I guess I could listen for the "ProjectManager.CreateNewFile" event in my plugin and then display my wizard like the ASClassWizard does.

On the other hand, I would like to assign the menu items custom icons. Can I do that when I just add a template file to one of the ProjectFiles directories?

Right now, with the icons manually appended to the context menu, it looks like this:
Image
The three icons at the bottom are added by me.


Sun May 20, 2012 8:48 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 10745
Location: Paris, France
Post Re: Proper Way of Adding Items to Project Context Menu
Checking the DataEvent's command and adding items seems correct.

If, as suggested by xMCNUGGETx, you add template files then they will always have a generic icon. But you could just listen to CreateNewFile command. Note that you can set event handling priority to High in your AddEventHandlers method in case if ASClassWizard captures the event before your plugin.


Mon May 21, 2012 9:13 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.