Author Topic: Using 'cbEVT_COMPILER_STARTED'  (Read 11678 times)

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Using 'cbEVT_COMPILER_STARTED'
« 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:
  • '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
Code
void cbPre::OnPrebuild(CodeBlocksEvent& event) {
// ...
}

How can I find the event shooter  trigger ?

Best regards
« Last Edit: January 25, 2015, 10:13:34 am by LETARTARE »
CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #1 on: January 23, 2015, 07:31:26 pm »
What do you mean by shooter?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #2 on: January 23, 2015, 07:35:32 pm »
shooter = menu item that triggers the event
« Last Edit: January 23, 2015, 07:39:59 pm by LETARTARE »
CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #3 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).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #4 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

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #5 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 ?
CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #6 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();
}
    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
Code
int idMenuCompileFromProjectManager                = wxNewId();

How to access another plugin? I do not know!
Can you help me ?
« Last Edit: January 24, 2015, 11:24:26 pm by LETARTARE »
CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #7 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #8 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)

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #9 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) {
      ...
      }
}
« Last Edit: February 09, 2015, 01:32:33 am by LETARTARE »
CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #10 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!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #11 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....

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #12 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 with sdk 1.19.0 (13.12), I hope I have not made any mistakes.

CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Using 'cbEVT_COMPILER_STARTED'
« Reply #13 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

Have a nice evening
CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl