Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Project execution event
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.
Pecan:
@LETARTARE
Pseudo Code to listen for specific menu item selection/clicks:
--- Code: ---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;
--- End code ---
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 :
--- Quote ---int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString)
--- End quote ---
Here are the results in 'Addons Log' :
--- Code: ---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(...)
--- End code ---
I will provide the code in another post
LETARTARE:
Here is the code of a method :
--- Code: ---/// 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(...)");
}
--- End code ---
LETARTARE:
and the one of the 2nd :
--- Code: ---// 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(...)");
}
--- End code ---
Macros '_print(wxString)' and 'iToStr(int)' allow to write in 'AddonQt Log
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version