Move Execute() to COMMON_CONTROL.

Also fixes other apps coming up in background.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20426
This commit is contained in:
Jeff Young 2025-04-18 19:11:35 +01:00 committed by Seth Hillbrand
parent 920173a197
commit ec6af4a5b4
3 changed files with 94 additions and 57 deletions

View File

@ -42,6 +42,9 @@
#include <dialogs/dialog_configure_paths.h>
#include <eda_doc.h>
#include <wx/msgdlg.h>
#include <executable_names.h>
#include <gestfich.h>
#include <tools/kicad_manager_actions.h>
#define URL_GET_INVOLVED wxS( "https://go.kicad.org/contribute/" )
#define URL_DONATE wxS( "https://go.kicad.org/app-donate" )
@ -188,6 +191,69 @@ int COMMON_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
}
class TERMINATE_HANDLER : public wxProcess
{
public:
TERMINATE_HANDLER( const wxString& appName )
{ }
void OnTerminate( int pid, int status ) override
{
delete this;
}
};
int COMMON_CONTROL::Execute( const wxString& aExecutible, const wxString& aParam )
{
TERMINATE_HANDLER* callback = new TERMINATE_HANDLER( aExecutible );
long pid = ExecuteFile( aExecutible, aParam, callback );
if( pid > 0 )
{
#ifdef __WXMAC__
wxString script;
script.Printf( wxS( "tell application \"System Events\" to tell application process \"%s\"\n"
" set frontmost to true\n"
"end tell" ),
aExecutible );
// This non-parameterized use of wxExecute is fine because script is not derived
// from user input.
wxExecute( wxString::Format( "osascript -e '%s'", script ) );
#endif
}
else
{
delete callback;
}
return 0;
}
int COMMON_CONTROL::Execute( const TOOL_EVENT& aEvent )
{
wxString execFile;
wxString param;
if( aEvent.IsAction( &ACTIONS::showCalculatorTools ) )
execFile = PCB_CALCULATOR_EXE;
else
wxFAIL_MSG( "Execute(): unexpected request" );
if( execFile.IsEmpty() )
return 0;
if( aEvent.Parameter<wxString*>() )
param = *aEvent.Parameter<wxString*>();
return Execute( execFile, param );
}
int COMMON_CONTROL::ShowProjectManager( const TOOL_EVENT& aEvent )
{
// Note: dynamic_cast doesn't work over the Kiway() on MacOS. We have to use static_cast
@ -356,7 +422,7 @@ void COMMON_CONTROL::setTransitions()
Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showSymbolEditor.MakeEvent() );
Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showFootprintBrowser.MakeEvent() );
Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showFootprintEditor.MakeEvent() );
Go( &COMMON_CONTROL::ShowPlayer, ACTIONS::showCalculatorTools.MakeEvent() );
Go( &COMMON_CONTROL::Execute, ACTIONS::showCalculatorTools.MakeEvent() );
Go( &COMMON_CONTROL::ShowProjectManager, ACTIONS::showProjectManager.MakeEvent() );
Go( &COMMON_CONTROL::ShowHelp, ACTIONS::gettingStarted.MakeEvent() );

View File

@ -50,6 +50,7 @@ public:
int ShowLibraryTable( const TOOL_EVENT& aEvent );
int ShowPlayer( const TOOL_EVENT& aEvent );
int Execute( const TOOL_EVENT& aEvent );
int ShowProjectManager( const TOOL_EVENT& aEvent );
int ShowHelp( const TOOL_EVENT& aEvent );
@ -62,6 +63,8 @@ public:
///< Sets up handlers for various events.
void setTransitions() override;
int Execute( const wxString& aExecutible, const wxString& aParam );
private:
///< Pointer to the currently used edit frame.
EDA_BASE_FRAME* m_frame;

View File

@ -36,6 +36,8 @@
#include <settings/kicad_settings.h>
#include <tool/selection.h>
#include <tool/tool_event.h>
#include <tool/tool_manager.h>
#include <tool/common_control.h>
#include <tools/kicad_manager_actions.h>
#include <tools/kicad_manager_control.h>
#include <dialogs/panel_design_block_lib_table.h>
@ -920,19 +922,6 @@ int KICAD_MANAGER_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
}
class TERMINATE_HANDLER : public wxProcess
{
public:
TERMINATE_HANDLER( const wxString& appName )
{ }
void OnTerminate( int pid, int status ) override
{
delete this;
}
};
int KICAD_MANAGER_CONTROL::Execute( const TOOL_EVENT& aEvent )
{
wxString execFile;
@ -963,35 +952,14 @@ int KICAD_MANAGER_CONTROL::Execute( const TOOL_EVENT& aEvent )
else if( aEvent.IsAction( &KICAD_MANAGER_ACTIONS::viewGerbers ) && m_frame->IsProjectActive() )
param = m_frame->Prj().GetProjectPath();
TERMINATE_HANDLER* callback = new TERMINATE_HANDLER( execFile );
long pid = ExecuteFile( execFile, param, callback );
if( pid > 0 )
{
#ifdef __WXMAC__
wxString script = wxString::Format( wxS( "tell application \"System Events\"\n"
" set frontmost of the first process whose unix id is %l to true\n"
"end tell" ), pid );
// This non-parameterized use of wxExecute is fine because script is not derived
// from user input.
wxExecute( wxString::Format( "osascript -e '%s'", script ) );
#endif
}
else
{
delete callback;
}
return 0;
COMMON_CONTROL* commonControl = m_toolMgr->GetTool<COMMON_CONTROL>();
return commonControl->Execute( execFile, param );
}
int KICAD_MANAGER_CONTROL::ShowPluginManager( const TOOL_EVENT& aEvent )
{
if( KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_PCM )
== KIPLATFORM::POLICY::PBOOL::DISABLED )
if( KIPLATFORM::POLICY::GetPolicyBool( POLICY_KEY_PCM ) == KIPLATFORM::POLICY::PBOOL::DISABLED )
{
// policy disables the plugin manager
return 0;
@ -1059,34 +1027,34 @@ void KICAD_MANAGER_CONTROL::setTransitions()
Go( &KICAD_MANAGER_CONTROL::NewProject, KICAD_MANAGER_ACTIONS::newProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::NewFromTemplate, KICAD_MANAGER_ACTIONS::newFromTemplate.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::NewFromRepository, KICAD_MANAGER_ACTIONS::newFromRepository.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::NewJobsetFile, KICAD_MANAGER_ACTIONS::newJobsetFile.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::NewJobsetFile, KICAD_MANAGER_ACTIONS::newJobsetFile.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::OpenDemoProject, KICAD_MANAGER_ACTIONS::openDemoProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::OpenProject, KICAD_MANAGER_ACTIONS::openProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::OpenJobsetFile, KICAD_MANAGER_ACTIONS::openJobsetFile.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::OpenJobsetFile, KICAD_MANAGER_ACTIONS::openJobsetFile.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::CloseProject, KICAD_MANAGER_ACTIONS::closeProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::SaveProjectAs, ACTIONS::saveAs.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::LoadProject, KICAD_MANAGER_ACTIONS::loadProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ViewDroppedViewers, KICAD_MANAGER_ACTIONS::viewDroppedGerbers.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ArchiveProject, KICAD_MANAGER_ACTIONS::archiveProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::UnarchiveProject, KICAD_MANAGER_ACTIONS::unarchiveProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ExploreProject, KICAD_MANAGER_ACTIONS::openProjectDirectory.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ArchiveProject, KICAD_MANAGER_ACTIONS::archiveProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::UnarchiveProject, KICAD_MANAGER_ACTIONS::unarchiveProject.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ExploreProject, KICAD_MANAGER_ACTIONS::openProjectDirectory.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Refresh, ACTIONS::zoomRedraw.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Refresh, ACTIONS::zoomRedraw.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPlayer, KICAD_MANAGER_ACTIONS::editSchematic.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPlayer, KICAD_MANAGER_ACTIONS::editSymbols.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPlayer, KICAD_MANAGER_ACTIONS::editPCB.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPlayer, KICAD_MANAGER_ACTIONS::editFootprints.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::viewGerbers.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::convertImage.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::showCalculator.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::editDrawingSheet.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::openTextEditor.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPlayer, KICAD_MANAGER_ACTIONS::editSchematic.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPlayer, KICAD_MANAGER_ACTIONS::editSymbols.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPlayer, KICAD_MANAGER_ACTIONS::editPCB.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPlayer, KICAD_MANAGER_ACTIONS::editFootprints.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::viewGerbers.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::convertImage.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::showCalculator.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::editDrawingSheet.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::openTextEditor.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::editOtherSch.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::editOtherPCB.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::editOtherSch.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::Execute, KICAD_MANAGER_ACTIONS::editOtherPCB.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPluginManager, KICAD_MANAGER_ACTIONS::showPluginManager.MakeEvent() );
Go( &KICAD_MANAGER_CONTROL::ShowPluginManager, KICAD_MANAGER_ACTIONS::showPluginManager.MakeEvent() );
}