31 #include <wx/mimetype.h> 32 #include <wx/filename.h> 34 #include <wx/filedlg.h> 44 if( !
string.StartsWith( wxT(
"\"" ) ) )
46 string.Prepend ( wxT(
"\"" ) );
47 string.Append ( wxT(
"\"" ) );
53 const wxString& aPath,
54 const wxString& aFileName,
55 const wxString& aExtension,
56 const wxString& aWildcard,
59 const bool aKeepWorkingDirectory,
60 const wxPoint& aPosition,
63 wxString fullfilename;
64 wxString curr_cwd = wxGetCwd();
65 wxString defaultname = aFileName;
66 wxString defaultpath = aPath;
67 wxString dotted_Ext = wxT(
".") + aExtension;
70 defaultname.Replace( wxT(
"/" ), wxT(
"\\" ) );
71 defaultpath.Replace( wxT(
"/" ), wxT(
"\\" ) );
74 if( defaultpath.IsEmpty() )
76 if( aMruPath ==
NULL )
77 defaultpath = wxGetCwd();
79 defaultpath = *aMruPath;
82 wxSetWorkingDirectory( defaultpath );
84 fullfilename = wxFileSelector( aTitle, defaultpath, defaultname,
85 dotted_Ext, aWildcard,
87 aParent, aPosition.x, aPosition.y );
89 if( aKeepWorkingDirectory )
90 wxSetWorkingDirectory( curr_cwd );
92 if( !fullfilename.IsEmpty() && aMruPath )
94 wxFileName fn = fullfilename;
95 *aMruPath = fn.GetPath();
107 wxString fullFileName =
Pgm().GetExecutablePath() + shortname;
109 wxString fullFileName =
Pgm().GetExecutablePath() + wxT(
"Contents/MacOS/" ) + shortname;
111 if( wxFileExists( fullFileName ) )
116 if(
Pgm().IsKicadEnvVariableDefined() )
118 fullFileName =
Pgm().GetKicadEnvVariable() + shortname;
120 if( wxFileExists( fullFileName ) )
124 #if defined( __WINDOWS__ ) 131 const static wxChar* possibilities[] = {
132 #if defined( __WXMAC__ ) 134 wxT(
"Contents/Applications/pcbnew.app/Contents/MacOS/" ),
135 wxT(
"Contents/Applications/eeschema.app/Contents/MacOS/" ),
136 wxT(
"Contents/Applications/gerbview.app/Contents/MacOS/" ),
137 wxT(
"Contents/Applications/bitmap2component.app/Contents/MacOS/" ),
138 wxT(
"Contents/Applications/pcb_calculator.app/Contents/MacOS/" ),
139 wxT(
"Contents/Applications/pl_editor.app/Contents/MacOS/" ),
142 wxT(
"/usr/local/bin/" ),
143 wxT(
"/usr/local/kicad/bin/" ),
148 for(
unsigned i=0; i<
arrayDim(possibilities); ++i )
151 fullFileName = possibilities[i] + shortname;
154 fullFileName =
Pgm().GetExecutablePath() + possibilities[i] + shortname;
157 if( wxFileExists( fullFileName ) )
165 int ExecuteFile( wxWindow* frame,
const wxString& ExecFile,
const wxString& param,
166 wxProcess *callback )
170 if( wxFileExists( fullFileName ) )
172 if( !param.IsEmpty() )
173 fullFileName += wxT(
" " ) + param;
182 if( !param.IsEmpty() )
183 fullFileName += wxT(
" " ) + param;
185 return ProcessExecute( wxT(
"/usr/bin/open -a " ) + fullFileName, wxEXEC_ASYNC, callback );
190 msg.Printf(
_(
"Command \"%s\" could not found" ), fullFileName );
199 wxString filename = file;
201 Pgm().ReadPdfBrowserInfos();
203 if( !
Pgm().UseSystemPdfBrowser() )
207 command =
Pgm().GetPdfBrowserName() + wxT(
" \"" ) + filename + wxT(
"\"" );
209 command =
Pgm().GetPdfBrowserName() + wxT(
" '" ) + filename + wxT(
"'" );
220 filename = wxT(
"\"" ) + filename + wxT(
"\"" );
223 if( wxLaunchDefaultApplication( filename ) )
227 command = wxT(
"/usr/bin/open -a '" ) + file + wxT(
"'" );
233 if( !command.IsEmpty() )
242 msg.Printf(
_(
"Problem while running the PDF viewer\nCommand is \"%s\"" ), command );
249 msg.Printf(
_(
"Unable to find a PDF viewer for \"%s\"" ), file );
259 wxFileName fileName( file );
260 wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( fileName.GetExt() );
266 wxFileType::MessageParameters params( file );
268 filetype->GetOpenCommand( &command, params );
271 if( !command.IsEmpty() )
278 wxFileName fileName( file );
279 wxString ext = fileName.GetExt();
280 wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
285 wxString printCommand;
286 wxString openCommand;
287 wxString application;
289 wxFileType::MessageParameters params( file );
290 filetype->GetPrintCommand( &printCommand, params );
291 filetype->GetOpenCommand( &openCommand, params );
294 if( !printCommand.IsEmpty() )
303 if( ext ==
"ps" || ext ==
"pdf" )
304 application =
"Preview";
305 else if( ext ==
"csv" )
306 application =
"Numbers";
307 else if( ext ==
"txt" || ext ==
"rpt" || ext ==
"pos" || ext ==
"cmp" || ext ==
"net" )
308 application =
"TextEdit";
310 if( !application.IsEmpty() )
312 printCommand.Printf(
"osascript -e 'tell application \"%s\"' " 313 "-e ' set srcFileRef to (open POSIX file \"%s\")' " 315 "-e ' print srcFileRef print dialog true' " 321 system( printCommand.c_str() );
328 if( ext ==
"ps" || ext ==
"pdf" 330 || ext ==
"txt" || ext ==
"rpt" || ext ==
"pos" || ext ==
"cmp" || ext ==
"net" )
332 printCommand.Printf(
"lp \"%s\"", file );
363 void KiCopyFile(
const wxString& aSrcPath,
const wxString& aDestPath, wxString& aErrors )
365 if( !wxCopyFile( aSrcPath, aDestPath ) )
369 if( !aErrors.IsEmpty() )
372 msg.Printf(
_(
"Cannot copy file \"%s\"." ), aDestPath );
380 return wxT(
"\"" ) + fn.GetFullPath( format ) + wxT(
"\"" );
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
int ProcessExecute(const wxString &aCommandLine, int aFlags, wxProcess *callback)
Run a command in a child process.
bool doPrintFile(const wxString &file, bool aDryRun)
This file is part of the common library TODO brief description.
This file is part of the common library.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
A helper function that wraps a call to wxFileSelector.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
void AddDelimiterString(wxString &string)
Add un " to the start and the end of string (if not already done).
wxString FindKicadFile(const wxString &shortname)
Search the executable file shortname in KiCad binary path and return full file name if found or short...
void PrintFile(const wxString &file)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
wxString QuoteFullPath(wxFileName &fn, wxPathFormat format)
Quote return value of wxFileName::GetFullPath().
void OpenFile(const wxString &file)
int ExecuteFile(wxWindow *frame, const wxString &ExecFile, const wxString ¶m, wxProcess *callback)
Call the executable file ExecFile with the command line parameters param.
bool CanPrintFile(const wxString &file)
bool OpenPDF(const wxString &file)
Run the PDF viewer and display a PDF file.