News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Using 'cbEVT_COMPILER_STARTED'

Started by LETARTARE, January 23, 2015, 06:05:10 PM

Previous topic - Next topic

LETARTARE

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
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

oBFusCATed

(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!]

LETARTARE

#2
shooter = menu item that triggers the event
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

oBFusCATed

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!]

BlueHazzard

Quote from: oBFusCATed on January 23, 2015, 08:41:51 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

LETARTARE

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 .... -> ? ? ? ? ? ->

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-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

LETARTARE

#6
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 ?
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

oBFusCATed

Quote from: LETARTARE on January 24, 2015, 09:25:42 PM
How to access another plugin? I do not know!
It is hard and unreliable, so don't do it.

Quote from: LETARTARE on January 24, 2015, 09:25:42 PM
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!]

BlueHazzard

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)

LETARTARE

#9
Thank you for your advice.
@BlueHazzard
Quoteyou 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) {
      ...
      }
}
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

oBFusCATed

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!]

BlueHazzard

Someone should implement a event CB_PRE_BUILD/ CB_PRE_RUN  that gets fired prior the compiling, and can stop the compiling/run process....

LETARTARE

@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.

QuoteIt 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 with sdk 1.19.0 (13.12), I hope I have not made any mistakes.

CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'

LETARTARE

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.next.codeblocks.org/index.php/topic,20000.new.html#new

Have a nice evening
CB-13834, plugins-sdk-2.25.0 : Collector-2.6.5, AddOnForQt-5.1.2
1- Win7 Business Pack1 64bits : wx-3.2.8, gcc-15.2.0,
2- OpenSuse::Leap-15.6-64bits : wx-3.2.8;gtk3-u, gcc-15.2.0,
=> !! The messages are translated by 'Deepl'