In a plugin that I'm writing, I want the File View / File context menu to add an option based on the type of file that was clicked. I'm trying to use the wxformbuilder plugin's source as guidance for how to do this, but there's one thing I'm stuck on.
In the method wxFormBuilder::HookPopupMenu, the "Open with wxFormBuilder..." menu item is added to the FileView_File menu, and that's simple and clear. What I can't find, however, is where this item is enabled and disabled. It is only enabled when the clicked item was a .fbp file, which is similar to the behavior I'll want from my plugin, and I don't see where this is defined in the program.
I would greatly appreciate a nudge in the right direction
OS: Ubuntu 11.04 x64
CodeLite: Revision 5011 (self-compliled with the addition of the plugin I'm in the middle of writing)
Plugin-writing question - HookPopupMenu
-
- CodeLite Enthusiast
- Posts: 10
- Joined: Tue Aug 23, 2011 6:59 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Plugin-writing question - HookPopupMenu
CodeLite Revision 5011, compiled on my machine
64-bit Ubuntu 11.04
64-bit Ubuntu 11.04
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Plugin-writing question - HookPopupMenu
I just had a quick look at the source of wxformbuilder plugin and I noticed that this part was hacked into the core IDE code..
So don't take an example from wxFB plugin regarding the update-ui event.
You should however have a look at DatabaseExplorer plugin (databaseexplorer.cpp) and see how it should be done:
In the constructor this plugin registers two events for the 'Open with DatabseExplorer' menu item:
The second event (wxUpdateUIEventHandler) is where the enable/disable is being done:
The above function enables the menu entry in case it is a file && the file extension is 'erd'
Eran
So don't take an example from wxFB plugin regarding the update-ui event.
You should however have a look at DatabaseExplorer plugin (databaseexplorer.cpp) and see how it should be done:
In the constructor this plugin registers two events for the 'Open with DatabseExplorer' menu item:
Code: Select all
m_mgr->GetTheApp()->Connect(XRCID("erd_open"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(DatabaseExplorer::OnOpenWithDBE), NULL, this);
m_mgr->GetTheApp()->Connect(XRCID("erd_open"), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(DatabaseExplorer::OnUpdateOpenWithDBE), NULL, this);
Code: Select all
void DatabaseExplorer::OnUpdateOpenWithDBE(wxUpdateUIEvent& e) {
TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo( TreeFileView );
if ( item.m_item.IsOk() && item.m_itemType == ProjectItem::TypeFile ) {
e.Enable(item.m_fileName.GetExt() == wxT("erd"));
}
}
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Enthusiast
- Posts: 10
- Joined: Tue Aug 23, 2011 6:59 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Plugin-writing question - HookPopupMenu
Thanks so much! I was wondering why a search for UpdateUIEvent wasn't turning anything up.
CodeLite Revision 5011, compiled on my machine
64-bit Ubuntu 11.04
64-bit Ubuntu 11.04