Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: LETARTARE on January 23, 2015, 06:05:10 pm

Title: Using 'cbEVT_COMPILER_STARTED'
Post by: LETARTARE on January 23, 2015, 06:05:10 pm
Hello,
in a contrib plugin (sdk 1.19.0) , I use 'cbEVT_COMPILER_STARTED'
Code
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:
I want to do different treatment depending on the shooter  trigger in
Code
void cbPre::OnPrebuild(CodeBlocksEvent& event) {
// ...
}

How can I find the event shooter  trigger ?

Best regards
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: oBFusCATed on January 23, 2015, 07:31:26 pm
What do you mean by shooter?
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: LETARTARE on January 23, 2015, 07:35:32 pm
shooter = menu item that triggers the event
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: oBFusCATed on January 23, 2015, 08:41:51 pm
Why would you care?
And it is probably not a menu that triggers it, but the internals of the compiler plugin (this is just a guess, that I've not verified by looking at the code).
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: BlueHazzard on January 23, 2015, 10:52:23 pm
And it is probably not a menu that triggers it, but the internals of the compiler plugin (this is just a guess, that I've not verified by looking at the code).
exactly
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: LETARTARE on January 24, 2015, 09:34:01 am
Thank you for the reply.
Well, I misspoke, you have right , of course.
The menu item 'Build-> Build' is the origin of the triggered by the event's compiler plugin 'cbEVT_COMPILER_STARTED'.

Quote
'Build->Build'  or  'Build->Run'  or .... -> ? ? ? ? ? ->
Code
CompilerGCC::DoPrepareQueue(bool clearLog) {
....
CodeBlocksEvent evt(cbEVT_COMPILER_STARTED, 0, m_pProject, 0, this);
Manager::Get()->ProcessEvent(evt);
....
}

'CompilerGCC::DoPrepareQueue' is the only place where one generates this event.

I seek to know the origin (Build, Run, Rebuild, Compile current file).
Is this possible?
If so, how ?
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: LETARTARE on January 24, 2015, 09:25:42 pm
I solved half the problem.
In
Code
CodeBlocksEvent evt(cbEVT_COMPILER_STARTED, 0, m_pProject, 0, this);
the first two parameters are used to call
Code
: 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
Code
'CodeBlocksEvent evt(cbEVT_COMPILER_STARTED, m_IdwxEvent, m_pProject, 0, this);

Recompiling svn10035 with those changes, obtained in
Code
void cbPre::OnPrebuild(CodeBlocksEvent& event) {
         int idevent = event.GetId();
}
these values ​​are found identical from one cession to another.

Requires access to menus identifiers that are defined in 'compilergcc.cpp' so
Code
int idMenuCompileFromProjectManager                = wxNewId();

How to access another plugin? I do not know!
Can you help me ?
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: oBFusCATed on January 24, 2015, 09:58:56 pm
How to access another plugin? I do not know!
It is hard and unreliable, so don't do it.

Can you help me ?
Nope because you're not telling us what you want to do.

Keep in mind that you'll have to give a use case for a possible patch you make, if you want it to be included in repo.
So better start early and don't waste precious time.
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: BlueHazzard on January 24, 2015, 11:12:44 pm
My be you can register a wxEVT_MENU with the ID of the menu in your plugin, but i don't know if this is working (it should be possible with some fiddeling, but there is for sure a better way)
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: LETARTARE on January 25, 2015, 02:09:37 am
Thank you for your advice.
@BlueHazzard
Quote
you can register a wxEVT_MENU with the ID of the menu in your plugin
Of course, obviously!

Here is the solution:
Code
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.

Code
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) {
      ...
      }
}
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: oBFusCATed on January 25, 2015, 02:33:56 am
Still this is hardly a reliable implementation, every time we decide to change the menu items, your plugin will break!
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: BlueHazzard on January 25, 2015, 04:15:57 am
Someone should implement a event CB_PRE_BUILD/ CB_PRE_RUN  that gets fired prior the compiling, and can stop the compiling/run process....
Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: LETARTARE on January 25, 2015, 09:40:09 am
@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.

Quote
It is hard and unreliable, so don't do it.
In my case is fast enough :
Code
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.

Title: Re: Using 'cbEVT_COMPILER_STARTED'
Post by: LETARTARE on February 10, 2015, 06:23:21 pm
Hello,
I would like to thank @BlueHazzard and @oBFusCATed who gave me good advice and allowed me to provide a plugin 'QtPregenForCB'.
Now,with your help,  I will try to modify it to make it more reliable. Inter alia, I can develop only under Win32 ' and that's a shame.

Here is the result : http://forums.codeblocks.org/index.php/topic,20000.new.html#new (http://forums.codeblocks.org/index.php/topic,20000.new.html#new)

Have a nice evening