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());
}
The event table is declared in the private section of the header file,
The OS is windows 7 64 bit.
Codeblocks 10.05
wxWidgets 2.8.12
The full file project is attached.
Here is the article I am working with. Once I know what I'm doing I'd be interested in helping bring the documentation up to date.
http://wiki.codeblocks.org/index.php?title=Creating_a_Plug-in_which_modifies_CB%27s_Menus (http://wiki.codeblocks.org/index.php?title=Creating_a_Plug-in_which_modifies_CB%27s_Menus)
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <cbplugin.h> // for "class cbPlugin"
class MyTools : public cbPlugin
{
public:
MyTools();
virtual ~MyTools();
virtual void BuildMenu(wxMenuBar* menuBar);
virtual void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0){}
virtual bool BuildToolBar(wxToolBar* toolBar){ return false; }
virtual int Execute();
protected:
virtual void OnAttach();
virtual void OnRelease(bool appShutDown);
private:
wxMenu* m_MyMenu;
void doSomething(wxCommandEvent& event);
DECLARE_EVENT_TABLE();
};
#endif // MYTOOLS_H_INCLUDED