I'd like to thank any respondents in advance for the help.
I've been using Code::Blocks for a while now for C code programming and figure it's time I learn't how to extend it.
I've been following the tutorial and I'm having a little trouble getting a menu item to run a function in a Code::blocks plugin. Following the tutorials I have performed the following tasks...
1. Create new plugin project
Using generic project with Create menu entries checked on
2. Define menu entry creation code. (This seems to work OK.)
a) Create a new id for the menu entry
b) Locate the menu position to add the item
c) Insert or append the item
3. Define a member function to do something
4. Define the Event table entry linking the menu item ID to the member function
5. Compile and install the plugin using the plugin manager.
The menu appears, however when I click the entry no action seems to result. My code is below.
#include <sdk.h> // Code::Blocks SDK
#include <configurationpanel.h>
#include "MyTools.h"
namespace
{
PluginRegistrant<MyTools> reg(_T("MyTools"));
}
const int idMyMenuItem = wxNewId();
BEGIN_EVENT_TABLE(MyTools, cbPlugin)
EVT_MENU(idMyMenuItem, MyTools::doSomething)
END_EVENT_TABLE()
MyTools::MyTools()
{
if(!Manager::LoadResource(_T("MyTools.zip")))
{
NotifyMissingFile(_T("MyTools.zip"));
}
}
MyTools::~MyTools()
{
}
void MyTools::OnAttach()
{
}
void MyTools::OnRelease(bool appShutDown)
{
if(m_MyMenu)
{
delete m_MyMenu;
m_MyMenu = NULL;
}
}
void MyTools::BuildMenu(wxMenuBar* menuBar)
{
int ToolsPos = menuBar->FindMenu(_("&Tools"));
if(ToolsPos != wxNOT_FOUND)
{
m_MyMenu = new wxMenu;
menuBar->Insert(ToolsPos,m_MyMenu,wxT("My Tools"));
m_MyMenu->Append(idMyMenuItem, _("Do Something\tShift-F6"));
}
else
{
wxMessageBox(wxT("Menu not found"),wxT("ERROR"), wxOK, NULL);
}
}
void MyTools::doSomething(wxCommandEvent& event)
{
cbMessageBox(_("Do Something!"), _("Message"), wxOK, Manager::Get()->GetAppWindow());
}