Hello,
in a contrib plugin (sdk 1.19.0) , I use 'cbEVT_COMPILER_STARTED'
void cbPre::OnAttach()
{
cbEventFunctor<cbPre, CodeBlocksEvent>* functor = new cbEventFunctor<cbPre, CodeBlocksEvent>(this, &cbPre::OnPrebuild);
Manager::Get()->RegisterEventSink(cbEVT_COMPILER_STARTED, functor);
}
This event is fired triggered by menu items:
- 'Build->Build'
- 'Build->Compille current file'
- 'Build->Run'
- 'Build->Build and Run'
- 'Build->Rebuild'
I want to do different treatment depending on the shooter trigger in
void cbPre::OnPrebuild(CodeBlocksEvent& event) {
// ...
}
How can I find the event shooter trigger ?
Best regards
I solved half the problem.
In
CodeBlocksEvent evt(cbEVT_COMPILER_STARTED, 0, m_pProject, 0, this);
the first two parameters are used to call
: wxCommandEvent(commandType, id) -> wxCommandEvent(cbEVT_COMPILER_STARTED, 0)
we see that the 2nd parameter = 0, simply replace 0 by the identifier of the item in the call menu.
For this purpose in 'CompilerGCC' class :
1- create a private variable: 'int m_IdwxEvent;'
2- in ' Dispatcher(wxCommandEvent& event)' memorize 'm_IdwxEvent = event.GetId();'
3- replace the 2nd parameter '0' in all
'CodeBlocksEvent evt(cbEVT_COMPILER_STARTED, m_IdwxEvent, m_pProject, 0, this);
Recompiling svn10035 with those changes, obtained in
void cbPre::OnPrebuild(CodeBlocksEvent& event) {
int idevent = event.GetId();
}
values 'idevent' only dependent on the used menu item :
- Build -> 1660
- Rebuild -> 1671
- Compile file -> 1668
...
these values are found identical from one cession to another.
Requires access to menus identifiers that are defined in 'compilergcc.cpp' so
int idMenuCompileFromProjectManager = wxNewId();
How to access another plugin? I do not know!
Can you help me ?
Thank you for your advice.
@BlueHazzard
you can register a wxEVT_MENU with the ID of the menu in your plugin
Of course, obviously!
Here is the solution:
void cbPre::BuildMenu(wxMenuBar* menuBar)
{
int pos = menuBar->FindMenu(_("Build"));
if (pos !=-1) {
wxMenu * builder = menuBar->GetMenu(pos);
IdBuild = builder->FindItem(_("Build"));
IdCompile = builder->FindItem(_("Compile current file"));
IdRun = builder->FindItem(_("Run"));
IdBuildRun = builder->FindItem(_("Build and run"));
IdRebuild = builder->FindItem(_("Rebuild"));
IdClean = builder->FindItem(_("Clean"));
}
}
IdBuild, ...are class variables.
void cbPre::OnPrebuild(CodeBlocksEvent& event) {
....
int eventId = event.GetId();
print(_("eventId = ") + wxString()<<eventId);
if (eventId == IdBuild) {
print(Tab + _T("Build->Build"));
.....
}
else
if (eventId == IdCompile) {
...
}
}
@oBFusCATed
you are right, but if you change the menus, you too will change plugin 'CompilerGCC', 'CodeCompletion', ... because it is hard coded, so I would adapt my plugin too.
It is hard and unreliable, so don't do it.
In my case is fast enough :
void cbPre::OnPrebuild(CodeBlocksEvent& event)
{
cbPlugin * plug = event.GetPlugin();
if (plug) {
// -> 4 = ptCompiler soit cbCompilerplugin
PluginType type = plug->GetType() ;
if (type == ptCompiler) {
print(_T("plugin type = ") + (wxString()<<type) ) ;
}
}
}
but to use it, take great care !!
@BlueHazzard
it is worth exploring, but that requires change 'sdk/sdk_events.*', so API 'sdk'. It's too complicated for me for now. This is my first binary plugin.
Modifying 'CompilerGCC', I propose above, highlights a feature of 'CodeBlocksEvent', which was not used, again this is a very minor change.
I will propose a patch when my plugin code will be correct, with a use case.
Thank you again, has both, for your advice.
Note : I have updated the wiki http://wiki.codeblocks.org/index.php?title=Code::Blocks_SDK_events (http://wiki.codeblocks.org/index.php?title=Code::Blocks_SDK_events) with sdk 1.19.0 (13.12), I hope I have not made any mistakes.