News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Project execution event

Started by LETARTARE, May 02, 2023, 11:39:12 AM

Previous topic - Next topic

LETARTARE

I am a third party plugin (AddonForQt :https://forums.next.codeblocks.org/index.php/topic,20000.msg172194.html#msg172194
Is there a CB event that would be generated at the beginning of a project's execution that I could intercept ?
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'

Miguel Gimenez

I do not think so. The complete list of events is here

LETARTARE

Thank you.
We could create in 'sdk_event' a 'cbEVT_COMPILER_PROJECT_LAUNCHED' event, but where should we fire it ?

1- 'int CompilerGCC::Run(ProjectBuildTarget* target)' just before 'return 0'

2- or 'int CompilerGCC::DoRunQueue()' after
    'process.PID = process.pProcess->Launch(cmd->command, flags);'
but here you have to wait for the command corresponding to the launch of the current project.

Is this possible ?

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'

Miguel Gimenez

Adding events used to require a solid reason, I do not know if this will be accepted.

Pecan

#4
Quote from: Miguel Gimenez on May 03, 2023, 02:54:02 PM
Adding events used to require a solid reason, I do not know if this will be accepted.

I've done this before, but I used the main menu events to do it by intercepting the event id for "Run" and "Build and run".
The event id(s) were obtained and bindings were set at the "OnAppStartupDone()" event. If you set your own  bindings (connects) during this event, you'll get called before the sdk does.
Be sure to "event.Skip()", else the the sdk will stall.

LETARTARE

Thanks to both of you.
@Michel Gimenez
So far I don't have a solid reason!
@Pecan
I'll try your lead, even though I didn't get it all.
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'

Pecan

#6
@LETARTARE

Pseudo Code to listen for specific menu item selection/clicks:

In OnAttach()
    Manager* pMgr = Manager::Get();
    pMgr->RegisterEventSink(cbEVT_APP_STARTUP_DONE, new cbEventFunctor<className>, CodeBlocksEvent>(this, &<className>::OnAppStartupDone));
        //Do not attempt to capture the menu items ID here. Other plugins might change the menu structure.
        // when being attached.

In OnAppStartUpDone()
    // int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString)
    // in <wx/utils.h>
    int m_RunMenuItemID = wxFindMenuItemId(pAppFrame, _("Build"), _("Run"));
    int m_BuildAndRunMenuItemID = wxFindMenuItemId(pAppFrame, _("Build"), _("Build and run"));
    if (m_RunMenuItemID !=  wxNOT_FOUND)
        Bind(wxEVT_COMMAND_MENU_SELECTED, &<classname>::SetRunEventOccured, this, runMenuItemID);
    // do like binding for buildAndRunMenuItemId or any other id's you're listening for.

In SetRunEventOccured(wxCommandEvent& event)
    event.Skip(); <--- don't forget this !!!
    // Do anything else you'd like here but remember that a
    // call back or an AddPendingEvent() is better than blocking the event processing.
    if (event.GetId() == m_RunMenuItemID)
        // do something (like set a OnCompilerFinished() event etc)
    else if (event.GtId() == m_BuildAnd RunMenuItemId)
        // do something
    else
        return;



I found that these events did not necessarily have all the info I needed (like the return code from the build). But there is a way of scraping the logs to find out.
Let me know if you need that kind of info.

LETARTARE

Good day, I am absent.

Many thanks for this efficient and elegant solution.
I didn't know this feature existed :
       
Quoteint wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString)

Here are the results in 'Addons Log' :
Plateforme : 'Linux-64'-'fr_FR', sdk => '2.24.0',   'extrasforQt' version : '3.6.1', construit le '12/05/2023::19:07:47'
    ==> Begin AddOnForQt::OnAppStartupDone(...)
        m_RunMenuItemID = -2484
        m_BuildAndRunMenuItemID = -2483
        m_AbortMenuID = -2485
    <= End AddOnForQt::OnAppStartupDone(...)


I will provide the code in another post
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

Here is the code of a method :
/// called by
///     1. 'cbEVT_APP_STARTUP_DONE'
void AddOnForQt::OnAppStartupDone(CodeBlocksEvent& _event)
{
_print("    ==> Begin AddOnForQt::OnAppStartupDone(...)");
    // int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString)
    // in <wx/utils.h>
    if (!m_pAppFrame)
    {
        _event.Skip();
        return;
    }
//
    m_RunMenuItemID = wxFindMenuItemId(m_pAppFrame, _("&Build"), _("&Run"));
_printWarn("        m_RunMenuItemID = " + iToStr(m_RunMenuItemID) );
    m_BuildAndRunMenuItemID = wxFindMenuItemId(m_pAppFrame, _("&Build"), _("Build and run"));
_printWarn("        m_BuildAndRunMenuItemID = " + iToStr(m_BuildAndRunMenuItemID) );
    m_AbortMenuID = wxFindMenuItemId(m_pAppFrame, _("&Build"), _("&Abort"));
_printWarn("        m_AbortMenuID = " + iToStr(m_AbortMenuID) );
    if (m_RunMenuItemID !=  wxNOT_FOUND)
        Bind(wxEVT_COMMAND_MENU_SELECTED, &AddOnForQt::onRunEventOccured, this, m_RunMenuItemID);
    if (m_BuildAndRunMenuItemID !=  wxNOT_FOUND)
        Bind(wxEVT_COMMAND_MENU_SELECTED, &AddOnForQt::onRunEventOccured, this, m_BuildAndRunMenuItemID);
    if (m_AbortMenuID != wxNOT_FOUND)
        Bind(wxEVT_COMMAND_MENU_SELECTED, &AddOnForQt::onRunEventOccured, this, m_AbortMenuID);
    // do like binding for buildAndRunMenuItemId or any other id's you're listening for.
/// The event processing system continues searching
_event.Skip();

_print("    <= End AddOnForQt::OnAppStartupDone(...)");
}
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

#9
and the one of the 2nd :
// called by :
//    AddOnForQt::OnAppStartupDone(CodeBlocksEvent& _event):1, 
void AddOnForQt::onRunEventOccured(wxCommandEvent& _event)
{
_print("    ==> Begin AddOnForQt::onRunEventOccured(" + iToStr(_event.GetId()) + ")");
/// The event processing system continues searching
     _event.Skip();

    const int id = _event.GetId() ;
    if (id == m_RunMenuItemID)
// do something (like set a OnCompilerFinished() event etc)
        _printError("       m_RunMenuItemID => " + iToStr(m_RunMenuItemID) );
    else
    if (id == m_BuildAndRunMenuItemID)
        _printError("       m_BuildAndRunMenuItemID => " + iToStr(m_BuildAndRunMenuItemID) );
    else
    if (id == m_AbortMenuID)
        _printError("       m_AbortMenuID = " + iToStr(m_AbortMenuID) );

_print("    <= End AddOnForQt::onRunEventOccured(...)");
}


Macros '_print(wxString)' and 'iToStr(int)' allow to write in 'AddonQt Log
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'

Pecan

@Letartare
Glad it helped you.
Good work.