2011-12-16 20:12:49 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
2020-11-18 16:54:12 +00:00
|
|
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
2021-06-25 09:06:41 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-16 20:12:49 +00:00
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file gestfich.cpp
|
|
|
|
* @brief Functions for file management
|
|
|
|
*/
|
2020-10-02 16:31:19 +00:00
|
|
|
|
2016-01-02 12:55:38 +00:00
|
|
|
#include <wx/mimetype.h>
|
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/dir.h>
|
2020-10-02 16:31:19 +00:00
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2016-01-02 12:55:38 +00:00
|
|
|
#include <gestfich.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-09-19 13:45:27 +00:00
|
|
|
void QuoteString( wxString& string )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2016-01-01 07:51:50 +00:00
|
|
|
if( !string.StartsWith( wxT( "\"" ) ) )
|
2015-12-31 09:03:47 +00:00
|
|
|
{
|
2015-12-31 10:16:26 +00:00
|
|
|
string.Prepend ( wxT( "\"" ) );
|
|
|
|
string.Append ( wxT( "\"" ) );
|
2015-12-31 09:03:47 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
wxString FindKicadFile( const wxString& shortname )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2014-04-14 18:49:52 +00:00
|
|
|
// Test the presence of the file in the directory shortname of
|
|
|
|
// the KiCad binary path.
|
2014-10-17 17:45:33 +00:00
|
|
|
#ifndef __WXMAC__
|
2014-04-14 18:49:52 +00:00
|
|
|
wxString fullFileName = Pgm().GetExecutablePath() + shortname;
|
2014-10-17 17:45:33 +00:00
|
|
|
#else
|
|
|
|
wxString fullFileName = Pgm().GetExecutablePath() + wxT( "Contents/MacOS/" ) + shortname;
|
|
|
|
#endif
|
2014-04-14 18:49:52 +00:00
|
|
|
if( wxFileExists( fullFileName ) )
|
|
|
|
return fullFileName;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
// Test the presence of the file in the directory shortname
|
|
|
|
// defined by the environment variable KiCad.
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
if( Pgm().IsKicadEnvVariableDefined() )
|
2007-08-18 11:43:59 +00:00
|
|
|
{
|
2014-04-14 18:49:52 +00:00
|
|
|
fullFileName = Pgm().GetKicadEnvVariable() + shortname;
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
if( wxFileExists( fullFileName ) )
|
|
|
|
return fullFileName;
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 00:22:00 +00:00
|
|
|
#if defined( __WINDOWS__ )
|
|
|
|
// kicad can be installed highly portably on Windows, anywhere and concurrently
|
|
|
|
// either the "kicad file" is immediately adjacent to the exe or it's not a valid install
|
|
|
|
return shortname;
|
|
|
|
#endif
|
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
// Path list for KiCad binary files
|
|
|
|
const static wxChar* possibilities[] = {
|
2020-11-19 00:22:00 +00:00
|
|
|
#if defined( __WXMAC__ )
|
2014-10-17 17:45:33 +00:00
|
|
|
// all internal paths are relative to main bundle kicad.app
|
|
|
|
wxT( "Contents/Applications/pcbnew.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/eeschema.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/gerbview.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/bitmap2component.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/pcb_calculator.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/pl_editor.app/Contents/MacOS/" ),
|
2014-04-14 18:49:52 +00:00
|
|
|
#else
|
|
|
|
wxT( "/usr/bin/" ),
|
|
|
|
wxT( "/usr/local/bin/" ),
|
|
|
|
wxT( "/usr/local/kicad/bin/" ),
|
|
|
|
#endif
|
|
|
|
};
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-10-17 17:45:33 +00:00
|
|
|
// find binary file from possibilities list:
|
2019-01-06 16:43:12 +00:00
|
|
|
for( unsigned i=0; i<arrayDim(possibilities); ++i )
|
2014-04-14 18:49:52 +00:00
|
|
|
{
|
2014-10-17 17:45:33 +00:00
|
|
|
#ifndef __WXMAC__
|
2014-04-14 18:49:52 +00:00
|
|
|
fullFileName = possibilities[i] + shortname;
|
2014-10-17 17:45:33 +00:00
|
|
|
#else
|
|
|
|
// make relative paths absolute
|
|
|
|
fullFileName = Pgm().GetExecutablePath() + possibilities[i] + shortname;
|
|
|
|
#endif
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
if( wxFileExists( fullFileName ) )
|
|
|
|
return fullFileName;
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return shortname;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
int ExecuteFile( const wxString& aEditorName, const wxString& aFileName, wxProcess *aCallback )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2021-09-26 14:02:14 +00:00
|
|
|
wxString fullEditorName;
|
|
|
|
wxString param;
|
2021-09-23 12:03:49 +00:00
|
|
|
|
|
|
|
#ifdef __UNIX__
|
2021-09-26 14:02:14 +00:00
|
|
|
int space = aEditorName.Find( ' ' );
|
2021-09-19 13:45:27 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
if( space > 0 && !aEditorName.Contains( "\"" ) && !aEditorName.Contains( "\'" ) )
|
2021-09-19 13:45:27 +00:00
|
|
|
{
|
2021-09-26 14:02:14 +00:00
|
|
|
fullEditorName = FindKicadFile( aEditorName.Mid( 0, space ) );
|
|
|
|
param = aEditorName.Mid( space + 1 );
|
2021-09-19 13:45:27 +00:00
|
|
|
}
|
|
|
|
else
|
2021-09-23 12:03:49 +00:00
|
|
|
#endif
|
2021-09-19 13:45:27 +00:00
|
|
|
{
|
2021-09-26 14:02:14 +00:00
|
|
|
fullEditorName = FindKicadFile( aEditorName );
|
2021-09-19 13:45:27 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
if( wxFileExists( fullEditorName ) )
|
2012-01-26 19:48:45 +00:00
|
|
|
{
|
2021-09-26 14:02:14 +00:00
|
|
|
int i = 0;
|
2021-09-26 16:02:27 +00:00
|
|
|
const wchar_t* args[4];
|
2014-10-17 17:45:33 +00:00
|
|
|
|
2021-09-26 16:02:27 +00:00
|
|
|
args[i++] = fullEditorName.wc_str();
|
2015-12-31 10:16:26 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
if( !param.IsEmpty() )
|
2021-09-26 16:02:27 +00:00
|
|
|
args[i++] = param.wc_str();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2021-09-27 21:56:36 +00:00
|
|
|
if( !aFileName.IsEmpty() )
|
2021-10-02 13:08:36 +00:00
|
|
|
args[i++] = aFileName.wc_str();
|
2021-09-27 21:56:36 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
args[i] = nullptr;
|
|
|
|
|
2021-09-27 21:56:36 +00:00
|
|
|
return wxExecute( const_cast< wchar_t**>( args ), wxEXEC_ASYNC, aCallback );
|
2021-09-19 15:27:32 +00:00
|
|
|
}
|
2021-09-26 14:02:14 +00:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Command '%s' could not be found." ), fullEditorName );
|
|
|
|
DisplayError( nullptr, msg, 20 );
|
|
|
|
return -1;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-31 10:16:26 +00:00
|
|
|
bool OpenPDF( const wxString& file )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2021-09-26 14:02:14 +00:00
|
|
|
wxString msg;
|
2020-11-18 16:54:12 +00:00
|
|
|
wxString filename = file;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
Pgm().ReadPdfBrowserInfos();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
if( Pgm().UseSystemPdfBrowser() )
|
2007-08-18 11:43:59 +00:00
|
|
|
{
|
2020-11-18 16:54:12 +00:00
|
|
|
// wxLaunchDefaultApplication on Unix systems is run as an external process passing
|
2021-06-25 09:06:41 +00:00
|
|
|
// the filename to the appropriate application as a command argument.
|
|
|
|
// depending on wxWidgets version, spaces in the path and/or file name will cause
|
|
|
|
// argument parsing issues so always quote the filename and path.
|
|
|
|
// This is applicable to all Unix platforms with wxWidgets version < 3.1.0.
|
2020-11-18 16:54:12 +00:00
|
|
|
// See https://github.com/wxWidgets/wxWidgets/blob/master/src/unix/utilsx11.cpp#L2654
|
|
|
|
#ifdef __WXGTK__
|
2021-06-25 09:06:41 +00:00
|
|
|
#if !wxCHECK_VERSION( 3, 1, 0 )
|
2021-09-26 14:02:14 +00:00
|
|
|
// Quote in case there are spaces in the path.
|
|
|
|
// Not needed on 3.1.4, but needed in 3.0 versions
|
|
|
|
// Moreover, on Linux, 3.1.4 wx version, adding quotes breaks wxLaunchDefaultApplication
|
|
|
|
QuoteString( filename );
|
2021-06-25 09:06:41 +00:00
|
|
|
#endif
|
2020-11-18 16:54:12 +00:00
|
|
|
#endif
|
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
if( !wxLaunchDefaultApplication( filename ) )
|
2008-06-29 18:51:38 +00:00
|
|
|
{
|
2021-09-26 14:02:14 +00:00
|
|
|
msg.Printf( _( "Unable to find a PDF viewer for '%s'." ), filename );
|
2021-07-15 19:26:35 +00:00
|
|
|
DisplayError( nullptr, msg );
|
2021-09-26 14:02:14 +00:00
|
|
|
return false;
|
2008-06-29 18:51:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-26 16:02:27 +00:00
|
|
|
const wchar_t* args[3];
|
2021-09-26 14:02:14 +00:00
|
|
|
|
2021-09-26 16:02:27 +00:00
|
|
|
args[0] = Pgm().GetPdfBrowserName().wc_str();
|
|
|
|
args[1] = filename.wc_str();
|
2021-09-26 14:02:14 +00:00
|
|
|
args[2] = nullptr;
|
|
|
|
|
2021-09-26 16:02:27 +00:00
|
|
|
if( wxExecute( const_cast<wchar_t**>( args ) ) == -1 )
|
2021-09-26 14:02:14 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "Problem while running the PDF viewer '%s'." ), args[0] );
|
|
|
|
DisplayError( nullptr, msg );
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-29 18:51:38 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
return true;
|
2008-06-29 18:51:38 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
void OpenFile( const wxString& file )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2019-08-28 16:01:06 +00:00
|
|
|
wxFileName fileName( file );
|
|
|
|
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( fileName.GetExt() );
|
|
|
|
|
|
|
|
if( !filetype )
|
|
|
|
return;
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
wxString command;
|
2019-08-28 16:01:06 +00:00
|
|
|
wxFileType::MessageParameters params( file );
|
2007-08-18 11:43:59 +00:00
|
|
|
|
2019-08-28 16:01:06 +00:00
|
|
|
filetype->GetOpenCommand( &command, params );
|
|
|
|
delete filetype;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2019-08-28 16:01:06 +00:00
|
|
|
if( !command.IsEmpty() )
|
2021-09-26 14:02:14 +00:00
|
|
|
wxExecute( command );
|
2019-08-28 16:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-29 20:59:49 +00:00
|
|
|
bool doPrintFile( const wxString& file, bool aDryRun )
|
2019-08-28 16:01:06 +00:00
|
|
|
{
|
2021-09-26 14:02:14 +00:00
|
|
|
wxString ext = wxFileName( file ).GetExt();
|
|
|
|
wxString application;
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
2019-08-28 19:03:50 +00:00
|
|
|
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
if( filetype )
|
|
|
|
{
|
|
|
|
wxString printCommand;
|
|
|
|
wxFileType::MessageParameters params( file );
|
2019-08-28 19:03:50 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
filetype->GetPrintCommand( &printCommand, params );
|
2019-08-28 16:01:06 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
delete filetype;
|
2019-08-28 19:03:50 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
if( !printCommand.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( !aDryRun )
|
|
|
|
wxExecute( printCommand );
|
2019-08-29 20:59:49 +00:00
|
|
|
|
2021-09-26 14:02:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-08-28 19:03:50 +00:00
|
|
|
}
|
2021-09-26 14:02:14 +00:00
|
|
|
#endif
|
2019-08-28 19:03:50 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2019-08-28 16:01:06 +00:00
|
|
|
if( ext == "ps" || ext == "pdf" )
|
|
|
|
application = "Preview";
|
|
|
|
else if( ext == "csv" )
|
|
|
|
application = "Numbers";
|
2019-08-28 19:03:50 +00:00
|
|
|
else if( ext == "txt" || ext == "rpt" || ext == "pos" || ext == "cmp" || ext == "net" )
|
2019-08-28 16:01:06 +00:00
|
|
|
application = "TextEdit";
|
|
|
|
|
|
|
|
if( !application.IsEmpty() )
|
|
|
|
{
|
2021-09-26 14:02:14 +00:00
|
|
|
wxString ascript;
|
|
|
|
ascript.Printf( "osascript -e 'tell application \"%s\"' "
|
|
|
|
"-e ' set srcFileRef to (open POSIX file \"%s\")' "
|
|
|
|
"-e ' activate' "
|
|
|
|
"-e ' print srcFileRef print dialog true' "
|
|
|
|
"-e 'end tell' ",
|
|
|
|
application,
|
|
|
|
file );
|
2019-08-29 20:59:49 +00:00
|
|
|
|
|
|
|
if( !aDryRun )
|
2021-09-26 14:02:14 +00:00
|
|
|
wxExecute( ascript );
|
2019-08-29 20:59:49 +00:00
|
|
|
|
|
|
|
return true;
|
2019-08-28 16:01:06 +00:00
|
|
|
}
|
2019-08-28 19:03:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
if( ext == "ps" || ext == "pdf"
|
|
|
|
|| ext == "csv"
|
|
|
|
|| ext == "txt" || ext == "rpt" || ext == "pos" || ext == "cmp" || ext == "net" )
|
2019-08-28 16:01:06 +00:00
|
|
|
{
|
2019-08-29 20:59:49 +00:00
|
|
|
if( !aDryRun )
|
2021-09-26 14:02:14 +00:00
|
|
|
{
|
2021-09-26 16:02:27 +00:00
|
|
|
const wchar_t* args[3];
|
|
|
|
args[0] = wxT( "lp" );
|
|
|
|
args[1] = file.wc_str();
|
2021-09-26 15:34:32 +00:00
|
|
|
args[2] = nullptr;
|
2021-09-26 14:02:14 +00:00
|
|
|
|
2021-09-26 16:26:56 +00:00
|
|
|
wxExecute( const_cast<wchar_t**>( args ) );
|
2021-09-26 14:26:09 +00:00
|
|
|
}
|
2019-08-29 20:59:49 +00:00
|
|
|
|
|
|
|
return true;
|
2019-08-28 16:01:06 +00:00
|
|
|
}
|
2019-08-28 19:03:50 +00:00
|
|
|
#endif
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2019-09-07 02:13:08 +00:00
|
|
|
if( !aDryRun )
|
|
|
|
{
|
2020-11-18 16:54:12 +00:00
|
|
|
DisplayError( nullptr, wxString::Format( _( "Cannot print '%s'.\n\nUnknown file type." ),
|
2019-09-07 02:13:08 +00:00
|
|
|
file ) );
|
|
|
|
}
|
|
|
|
|
2019-08-29 20:59:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2019-08-29 20:59:49 +00:00
|
|
|
|
|
|
|
void PrintFile( const wxString& file )
|
|
|
|
{
|
|
|
|
doPrintFile( file, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CanPrintFile( const wxString& file )
|
|
|
|
{
|
|
|
|
return doPrintFile( file, true );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2020-10-02 18:36:06 +00:00
|
|
|
void KiCopyFile( const wxString& aSrcPath, const wxString& aDestPath, wxString& aErrors )
|
2019-11-09 19:39:08 +00:00
|
|
|
{
|
|
|
|
if( !wxCopyFile( aSrcPath, aDestPath ) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2019-11-10 08:37:39 +00:00
|
|
|
if( !aErrors.IsEmpty() )
|
2019-11-09 19:39:08 +00:00
|
|
|
aErrors += "\n";
|
|
|
|
|
2021-06-27 23:26:54 +00:00
|
|
|
msg.Printf( _( "Cannot copy file '%s'." ), aDestPath );
|
2019-11-09 19:39:08 +00:00
|
|
|
aErrors += msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString QuoteFullPath( wxFileName& fn, wxPathFormat format )
|
|
|
|
{
|
2010-05-11 14:35:13 +00:00
|
|
|
return wxT( "\"" ) + fn.GetFullPath( format ) + wxT( "\"" );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|