diff --git a/common/tool/common_control.cpp b/common/tool/common_control.cpp index 5601274851..4b6c21619c 100644 --- a/common/tool/common_control.cpp +++ b/common/tool/common_control.cpp @@ -42,6 +42,9 @@ #include #include #include +#include +#include +#include #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() ) + param = *aEvent.Parameter(); + + 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() ); diff --git a/include/tool/common_control.h b/include/tool/common_control.h index 17d4863381..7988f7a61d 100644 --- a/include/tool/common_control.h +++ b/include/tool/common_control.h @@ -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; diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp index 6985b038f9..5461ee1e1f 100644 --- a/kicad/tools/kicad_manager_control.cpp +++ b/kicad/tools/kicad_manager_control.cpp @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include #include #include @@ -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(); + 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() ); }