Factor out utility to launch a given file or folder

This commit is contained in:
Jon Evans 2020-02-20 20:10:49 -05:00
parent e8e3b4f11e
commit dc75c2b800
4 changed files with 77 additions and 15 deletions

View File

@ -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

42
common/launch_ext.cpp Normal file
View File

@ -0,0 +1,42 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* 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 <http://www.gnu.org/licenses/>.
*/
#include <gestfich.h>
#include <launch_ext.h>
#include <wx/wx.h>
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
}

32
include/launch_ext.h Normal file
View File

@ -0,0 +1,32 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* 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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -34,6 +34,7 @@
#include <kiway.h>
#include <kiway_express.h>
#include <kiway_player.h>
#include <launch_ext.h>
#include <panel_hotkeys_editor.h>
#include <settings/common_settings.h>
#include <tool/action_toolbar.h>
@ -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() );
}