From dc75c2b8003267d699e7f42542ae899a9519cf3f Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Thu, 20 Feb 2020 20:10:49 -0500 Subject: [PATCH] Factor out utility to launch a given file or folder --- common/CMakeLists.txt | 1 + common/launch_ext.cpp | 42 +++++++++++++++++++++++++++++++++++ include/launch_ext.h | 32 ++++++++++++++++++++++++++ kicad/kicad_manager_frame.cpp | 17 ++------------ 4 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 common/launch_ext.cpp create mode 100644 include/launch_ext.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 4f8c8deb02..b762335174 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -309,6 +309,7 @@ set( COMMON_SRCS kiway_holder.cpp kiway_player.cpp languages_menu.cpp + launch_ext.cpp lib_id.cpp lib_table_base.cpp lib_tree_model.cpp diff --git a/common/launch_ext.cpp b/common/launch_ext.cpp new file mode 100644 index 0000000000..fcebb335cc --- /dev/null +++ b/common/launch_ext.cpp @@ -0,0 +1,42 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jon Evans + * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include +#include + + +void LaunchExternal( const wxString& aPath ) +{ +#ifdef __WXMAC__ + wxString msg; + + // Quote in case there are spaces in the path. + msg.Printf( "open \"%s\"", aPath ); + + system( msg.c_str() ); +#else + wxString path( aPath ); + // Quote in case there are spaces in the path. + AddDelimiterString( path ); + + wxLaunchDefaultApplication( path ); +#endif +} diff --git a/include/launch_ext.h b/include/launch_ext.h new file mode 100644 index 0000000000..4d223d7668 --- /dev/null +++ b/include/launch_ext.h @@ -0,0 +1,32 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Jon Evans + * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef LAUNCH_EXT_H +#define LAUNCH_EXT_H + +class wxString; + +/** + * Launches the given file or folder in the host OS + * @param aPath is a path to a file or folder + */ +void LaunchExternal( const wxString& aPath ); + +#endif diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 7a5e392536..6e41080458 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -434,21 +435,7 @@ void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnBrowseInFileExplorer( wxCommandEvent& event ) { // open project directory in host OS's file explorer - wxString project_dir = Prj().GetProjectPath(); - -#ifdef __WXMAC__ - wxString msg; - - // Quote in case there are spaces in the path. - msg.Printf( "open \"%s\"", project_dir ); - - system( msg.c_str() ); -#else - // Quote in case there are spaces in the path. - AddDelimiterString( project_dir ); - - wxLaunchDefaultApplication( project_dir ); -#endif + LaunchExternal( Prj().GetProjectPath() ); }