Page 1 of 1

Plugin-writing question - HookPopupMenu

Posted: Tue Aug 23, 2011 7:13 pm
by GlenboLake
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)

Re: Plugin-writing question - HookPopupMenu

Posted: Tue Aug 23, 2011 7:37 pm
by eranif
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:

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);
The second event (wxUpdateUIEventHandler) is where the enable/disable is being done:

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"));
	}
}
The above function enables the menu entry in case it is a file && the file extension is 'erd'

Eran

Re: Plugin-writing question - HookPopupMenu

Posted: Tue Aug 23, 2011 8:21 pm
by GlenboLake
Thanks so much! I was wondering why a search for UpdateUIEvent wasn't turning anything up.