2007-05-06 16:03:28 +00:00
|
|
|
|
/************************************************/
|
|
|
|
|
/* MODULE: gestfich.cpp */
|
|
|
|
|
/* ROLE: fonctions de gestion de fichiers */
|
|
|
|
|
/************************************************/
|
|
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
2008-12-08 15:27:13 +00:00
|
|
|
|
#include "fctsys.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
|
#include "wx/mimetype.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
|
#include <dir.h>
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
2008-02-20 19:12:36 +00:00
|
|
|
|
#include "macros.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2008-03-30 15:12:08 +00:00
|
|
|
|
/* List of default paths used to locate help files and kicad library files.
|
|
|
|
|
*
|
|
|
|
|
* Under windows, kicad search its files from the binary path file (first argument when running "main")
|
|
|
|
|
* So for a standard install, default paths are not mandatory, but they exist, just in case.
|
|
|
|
|
* kicad is often installed in c:/Program Files/kicad or c:/kicad (or d: or e: ... )
|
|
|
|
|
* and the directory "share" has no meaning under windows.
|
|
|
|
|
*
|
|
|
|
|
* Under linux, the problem is more complex.
|
|
|
|
|
* In fact there are 3 cases:
|
|
|
|
|
* 1 - When released in a distribution:
|
|
|
|
|
* binaries are in /usr/bin, kicad libs in /usr/share/kicad/ and doc in /usr/share/doc/kicad/
|
|
|
|
|
* 2 - When compiled by an user:
|
|
|
|
|
* binaries also can be in /usr/local/bin, kicad libs in /usr/local/share/kicad/ and doc in /usr/local/share/doc/kicad/
|
|
|
|
|
* 3 - When in an "universal tarball" or build for a server:
|
|
|
|
|
* all files are in /usr/local/kicad
|
|
|
|
|
* This is mandatory when kicad is installed on a server (in a school for instance) because one can export /usr/local/kicad
|
|
|
|
|
* and obviously the others paths cannot be used
|
|
|
|
|
* (cannot be mounted by the client, because they are already used).
|
|
|
|
|
*
|
|
|
|
|
* in cases 1 and 2 kicad files cannot be found from the binary path.
|
|
|
|
|
* in case 3 kicad files can be found from the binary path only if this is a kicad binary file which is launched.
|
|
|
|
|
* But if an user creates a symbolic link to the actual binary file to run kicad, the binary path is not good
|
|
|
|
|
* and the defaults paths must be used
|
|
|
|
|
*
|
|
|
|
|
* Note:
|
|
|
|
|
* kicad uses first the bin path lo locace kicad tree.
|
|
|
|
|
* if not found kicad uses the environment variable KICAD to find its files
|
|
|
|
|
* and at last kicad uses the default paths.
|
|
|
|
|
* So we can export (linux and windows) the variable KICAD:
|
|
|
|
|
* like export KICAD=/my_path/kicad if /my_path/kicad is not a default path
|
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
// Path list for online help
|
2007-08-18 11:43:59 +00:00
|
|
|
|
static wxString s_HelpPathList[] = {
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2008-03-06 19:57:06 +00:00
|
|
|
|
wxT( "c:/kicad/doc/help/" ),
|
|
|
|
|
wxT( "d:/kicad/doc/help/" ),
|
|
|
|
|
wxT( "c:/Program Files/kicad/doc/help/" ),
|
|
|
|
|
wxT( "d:/Program Files/kicad/doc/help/" ),
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#else
|
2008-03-06 19:57:06 +00:00
|
|
|
|
wxT( "/usr/share/doc/kicad/help/" ),
|
|
|
|
|
wxT( "/usr/local/share/doc/kicad/help/" ),
|
2008-12-08 15:27:13 +00:00
|
|
|
|
wxT( "/usr/local/kicad/doc/help/" ), // default install for "universal tarballs" and build for a server (new)
|
|
|
|
|
wxT( "/usr/local/kicad/help/" ), // default install for "universal tarballs" and build for a server (old)
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#endif
|
2008-03-30 15:12:08 +00:00
|
|
|
|
wxT( "end_list" ) // End of list symbol, do not change
|
2007-05-06 16:03:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Path list for kicad data files
|
2007-08-18 11:43:59 +00:00
|
|
|
|
static wxString s_KicadDataPathList[] = {
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2008-03-05 07:16:43 +00:00
|
|
|
|
wxT( "c:/kicad/share/" ),
|
|
|
|
|
wxT( "d:/kicad/share/" ),
|
2008-06-22 08:54:05 +00:00
|
|
|
|
wxT( "c:/kicad/" ),
|
|
|
|
|
wxT( "d:/kicad/" ),
|
2008-03-06 19:57:06 +00:00
|
|
|
|
wxT( "c:/Program Files/kicad/share/" ),
|
|
|
|
|
wxT( "d:/Program Files/kicad/share/" ),
|
2008-06-22 08:54:05 +00:00
|
|
|
|
wxT( "c:/Program Files/kicad/" ),
|
|
|
|
|
wxT( "d:/Program Files/kicad/" ),
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#else
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxT( "/usr/share/kicad/" ),
|
|
|
|
|
wxT( "/usr/local/share/kicad/" ),
|
2008-06-22 08:59:38 +00:00
|
|
|
|
wxT( "/usr/local/kicad/share/" ), // default data path for "universal tarballs" and build for a server (new)
|
|
|
|
|
wxT( "/usr/local/kicad/" ), // default data path for "universal tarballs" and build for a server (old)
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#endif
|
2008-03-30 15:12:08 +00:00
|
|
|
|
wxT( "end_list" ) // End of list symbol, do not change
|
2007-05-06 16:03:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Path list for kicad binary files
|
2007-08-18 11:43:59 +00:00
|
|
|
|
static wxString s_KicadBinaryPathList[] = {
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2008-03-05 07:16:43 +00:00
|
|
|
|
wxT( "c:/kicad/bin/" ),
|
|
|
|
|
wxT( "d:/kicad/bin/" ),
|
2008-03-06 19:57:06 +00:00
|
|
|
|
wxT( "c:/Program Files/kicad/bin/" ),
|
|
|
|
|
wxT( "d:/Program Files/kicad/bin/" ),
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#else
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxT( "/usr/bin/" ),
|
|
|
|
|
wxT( "/usr/local/bin/" ),
|
|
|
|
|
wxT( "/usr/local/kicad/bin/" ),
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#endif
|
2008-03-30 15:12:08 +00:00
|
|
|
|
wxT( "end_list" ) // End of list symbol, do not change
|
2007-05-06 16:03:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString MakeReducedFileName( const wxString& fullfilename,
|
|
|
|
|
const wxString& default_path,
|
|
|
|
|
const wxString& default_ext )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/** Function MakeReducedFileName
|
|
|
|
|
* Calculate the "reduced" filename from
|
|
|
|
|
* @param fullfilename = full filename
|
|
|
|
|
* @param default_path = default path
|
|
|
|
|
* @param default_ext = default extension
|
2008-02-20 19:12:36 +00:00
|
|
|
|
*
|
2007-11-02 17:17:44 +00:00
|
|
|
|
* @return the "reduced" filename, i.e.:
|
|
|
|
|
* without path if it is default_path
|
|
|
|
|
* wiht ./ if the path is the current path
|
|
|
|
|
* without extension if extension is default_ext
|
2008-02-20 19:12:36 +00:00
|
|
|
|
*
|
2007-11-02 17:17:44 +00:00
|
|
|
|
* the new flename is in unix like notation ('/' as path separator)
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString reduced_filename = fullfilename;
|
|
|
|
|
wxString Cwd, ext, path;
|
|
|
|
|
|
|
|
|
|
Cwd = default_path;
|
|
|
|
|
ext = default_ext;
|
|
|
|
|
path = wxPathOnly( reduced_filename ) + UNIX_STRING_DIR_SEP;
|
|
|
|
|
reduced_filename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
if( Cwd.Last() != '/' )
|
|
|
|
|
Cwd += UNIX_STRING_DIR_SEP;
|
|
|
|
|
path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
2008-03-30 15:12:08 +00:00
|
|
|
|
|
2008-02-20 19:12:36 +00:00
|
|
|
|
// names are case insensitive under windows
|
2007-08-18 11:43:59 +00:00
|
|
|
|
path.MakeLower();
|
|
|
|
|
Cwd.MakeLower();
|
|
|
|
|
ext.MakeLower();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
// if the path is "default_path" -> remove it
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString root_path = path.Left( Cwd.Length() );
|
|
|
|
|
if( root_path == Cwd )
|
|
|
|
|
{
|
|
|
|
|
reduced_filename.Remove( 0, Cwd.Length() );
|
|
|
|
|
}
|
2007-11-02 17:17:44 +00:00
|
|
|
|
else // if the path is the current path -> change path to ./
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
|
|
|
|
Cwd = wxGetCwd() + UNIX_STRING_DIR_SEP;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2007-08-18 11:43:59 +00:00
|
|
|
|
Cwd.MakeLower();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
|
Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
if( path == Cwd )
|
2007-11-02 17:17:44 +00:00
|
|
|
|
{ // the path is the current path -> path = "./"
|
2007-08-18 11:43:59 +00:00
|
|
|
|
reduced_filename.Remove( 0, Cwd.Length() );
|
|
|
|
|
wxString tmp = wxT( "./" ) + reduced_filename;
|
|
|
|
|
reduced_filename = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
// remove extension if == default_ext:
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( !ext.IsEmpty() && reduced_filename.Contains( ext ) )
|
|
|
|
|
reduced_filename.Truncate( reduced_filename.Length() - ext.Length() );
|
|
|
|
|
|
|
|
|
|
return reduced_filename;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString MakeFileName( const wxString& dir,
|
|
|
|
|
const wxString& shortname, const wxString& ext )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/** Function MakeFileName
|
|
|
|
|
* Calculate the full file name from dir, shortname and ext
|
|
|
|
|
* @param dir = path (can be empty)
|
|
|
|
|
* @param shortname = filename with or without path and/or extension
|
|
|
|
|
* @param ext = extension (can be empty)
|
2007-11-05 19:54:48 +00:00
|
|
|
|
* If shortname has an absolute path, or a path starts by ./ or ../,
|
|
|
|
|
* the path will not be modified
|
2007-11-02 17:17:44 +00:00
|
|
|
|
* If shortname has an extension, it will not be modified
|
|
|
|
|
* @return full filename
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString fullfilename;
|
|
|
|
|
int ii;
|
|
|
|
|
|
|
|
|
|
if( !dir.IsEmpty() )
|
|
|
|
|
{
|
2008-02-20 19:12:36 +00:00
|
|
|
|
if( !wxIsAbsolutePath( shortname ) )
|
|
|
|
|
{
|
2008-03-30 15:12:08 +00:00
|
|
|
|
if( !shortname.StartsWith( wxT( "./" ) ) && !shortname.StartsWith( wxT( "../" ) ) )
|
2008-12-08 15:27:13 +00:00
|
|
|
|
{ /* no absolute path in shortname, add dir to shortname */
|
2008-02-20 19:12:36 +00:00
|
|
|
|
fullfilename = dir;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-18 11:43:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-03-30 15:12:08 +00:00
|
|
|
|
fullfilename += shortname; // Add shortname to dir or use shortname only
|
2007-11-05 19:54:48 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
fullfilename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/* Add an extension if shortname has no extension */
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( ext.IsEmpty() )
|
|
|
|
|
return fullfilename;
|
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/* search for an extension */
|
|
|
|
|
ii = fullfilename.Length(); /* Get the end of name */
|
2007-08-18 11:43:59 +00:00
|
|
|
|
for( ; ii >= 0; ii-- )
|
|
|
|
|
{
|
|
|
|
|
if( fullfilename.GetChar( ii ) == '/' )
|
|
|
|
|
{
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/* not extension: add ext */
|
2007-08-18 11:43:59 +00:00
|
|
|
|
fullfilename += ext;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-03-30 15:12:08 +00:00
|
|
|
|
if( fullfilename.GetChar( ii ) == '.' ) /* extension exists, do nothing */
|
2007-08-18 11:43:59 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fullfilename;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
void ChangeFileNameExt( wxString& FullFileName, const wxString& NewExt )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/**************************************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/** Function ChangeFileNameExt
|
|
|
|
|
* change the extension of FullFileName to NewExt.
|
|
|
|
|
* @param FullFileName = filename to modify
|
|
|
|
|
* @param NewExt = new extension for FullFileName
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString FileName;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
FileName = FullFileName.BeforeLast( '.' );
|
|
|
|
|
if( !FileName.IsEmpty() )
|
|
|
|
|
FileName += NewExt;
|
|
|
|
|
else
|
|
|
|
|
FileName = FullFileName + NewExt;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( FileName.StartsWith( wxT( "\"" ) ) && ( FileName.Last() != '"' ) )
|
|
|
|
|
FileName += wxT( "\"" );
|
|
|
|
|
FullFileName = FileName;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/*******************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
void AddDelimiterString( wxString& string )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/*******************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/** Function AddDelimiterString
|
|
|
|
|
* Add un " to the start and the end of string (if not already done).
|
|
|
|
|
* @param string = string to modify
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString text;
|
|
|
|
|
|
|
|
|
|
if( !string.StartsWith( wxT( "\"" ) ) )
|
|
|
|
|
text = wxT( "\"" );
|
|
|
|
|
text += string;
|
|
|
|
|
if( (text.Last() != '"' ) || (text.length() <= 1) )
|
|
|
|
|
text += wxT( "\"" );
|
|
|
|
|
string = text;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/***********************************/
|
|
|
|
|
/* Selection Directory dialog box: */
|
|
|
|
|
/***********************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
bool EDA_DirectorySelector( const wxString& Title, /* Titre de la fenetre */
|
|
|
|
|
wxString& Path, /* Chemin par defaut */
|
|
|
|
|
int flag, /* reserve */
|
|
|
|
|
wxWindow* Frame, /* parent frame */
|
|
|
|
|
const wxPoint& Pos )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
int ii;
|
|
|
|
|
bool selected = FALSE;
|
|
|
|
|
|
|
|
|
|
wxDirDialog* DirFrame = new wxDirDialog(
|
|
|
|
|
Frame,
|
|
|
|
|
wxString( Title ),
|
|
|
|
|
Path, /* Chemin par defaut */
|
|
|
|
|
flag,
|
|
|
|
|
Pos );
|
|
|
|
|
|
|
|
|
|
ii = DirFrame->ShowModal();
|
|
|
|
|
if( ii == wxID_OK )
|
|
|
|
|
{
|
|
|
|
|
Path = DirFrame->GetPath();
|
|
|
|
|
selected = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DirFrame->Destroy();
|
|
|
|
|
return selected;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
|
|
|
|
/******************************/
|
|
|
|
|
/* Selection file dialog box: */
|
|
|
|
|
/******************************/
|
|
|
|
|
|
|
|
|
|
wxString EDA_FileSelector( const wxString& Title, /* Dialog title */
|
|
|
|
|
const wxString& Path, /* Default path */
|
|
|
|
|
const wxString& FileName, /* default filename */
|
|
|
|
|
const wxString& Ext, /* default filename extension */
|
|
|
|
|
const wxString& Mask, /* filter for filename list */
|
|
|
|
|
wxWindow* Frame, /* parent frame */
|
|
|
|
|
int flag, /* wxFD_SAVE, wxFD_OPEN ..*/
|
|
|
|
|
const bool keep_working_directory, /* true = keep the current path */
|
|
|
|
|
const wxPoint& Pos )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString fullfilename;
|
|
|
|
|
wxString curr_cwd = wxGetCwd();
|
|
|
|
|
wxString defaultname = FileName;
|
|
|
|
|
wxString defaultpath = Path;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
defaultname.Replace( wxT( "/" ), STRING_DIR_SEP );
|
|
|
|
|
defaultpath.Replace( wxT( "/" ), STRING_DIR_SEP );
|
|
|
|
|
if( defaultpath.IsEmpty() )
|
|
|
|
|
defaultpath = wxGetCwd();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
wxSetWorkingDirectory( defaultpath );
|
|
|
|
|
|
2008-03-30 15:12:08 +00:00
|
|
|
|
#if 0 && defined (DEBUG)
|
|
|
|
|
printf(
|
|
|
|
|
"defaultpath=\"%s\" defaultname=\"%s\" Ext=\"%s\" Mask=\"%s\" flag=%d keep_working_directory=%d\n",
|
|
|
|
|
CONV_TO_UTF8( defaultpath ),
|
|
|
|
|
CONV_TO_UTF8( defaultname ),
|
|
|
|
|
CONV_TO_UTF8( Ext ),
|
|
|
|
|
CONV_TO_UTF8( Mask ),
|
|
|
|
|
flag,
|
|
|
|
|
keep_working_directory
|
|
|
|
|
);
|
2008-02-20 19:12:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
fullfilename = wxFileSelector( wxString( Title ),
|
2008-12-08 15:27:13 +00:00
|
|
|
|
defaultpath,
|
|
|
|
|
defaultname,
|
|
|
|
|
Ext,
|
|
|
|
|
Mask,
|
|
|
|
|
flag, /* open mode wxFD_OPEN, wxFD_SAVE .. */
|
|
|
|
|
Frame,
|
|
|
|
|
Pos.x, Pos.y );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( keep_working_directory )
|
|
|
|
|
wxSetWorkingDirectory( curr_cwd );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
return fullfilename;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/********************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
|
wxString FindKicadHelpPath()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/********************************************************/
|
2008-03-30 15:12:08 +00:00
|
|
|
|
|
2007-11-02 17:17:44 +00:00
|
|
|
|
/** Function FindKicadHelpPath
|
2008-03-04 17:14:58 +00:00
|
|
|
|
* Find an absolute path for KiCad "help" (or "help/<language>")
|
2008-03-05 07:16:43 +00:00
|
|
|
|
* Find path kicad/doc/help/xx/ or kicad/doc/help/:
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* from BinDir
|
|
|
|
|
* else from environment variable KICAD
|
|
|
|
|
* else from one of s_HelpPathList
|
2008-06-11 10:33:13 +00:00
|
|
|
|
* typically c:\kicad\doc\help or /usr/share/kicad/help
|
|
|
|
|
* or /usr/local/share/kicad/help
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* (must have kicad in path name)
|
2008-02-20 19:12:36 +00:00
|
|
|
|
*
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* xx = iso639-1 language id (2 letters (generic) or 4 letters):
|
|
|
|
|
* fr = french (or fr_FR)
|
|
|
|
|
* en = English (or en_GB or en_US ...)
|
|
|
|
|
* de = deutch
|
|
|
|
|
* es = spanish
|
|
|
|
|
* pt = portuguese (or pt_BR ...)
|
2008-02-20 19:12:36 +00:00
|
|
|
|
*
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* default = en (if not found = fr)
|
2008-02-20 19:12:36 +00:00
|
|
|
|
*
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString FullPath, LangFullPath, tmp;
|
|
|
|
|
wxString LocaleString;
|
|
|
|
|
bool PathFound = FALSE;
|
2008-03-30 15:12:08 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
/* find kicad/help/ */
|
2008-12-08 15:27:13 +00:00
|
|
|
|
tmp = wxGetApp().m_BinDir;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( tmp.Last() == '/' )
|
|
|
|
|
tmp.RemoveLast();
|
2008-03-06 19:57:06 +00:00
|
|
|
|
FullPath = tmp.BeforeLast( '/' ); // cd ..
|
2008-06-11 10:33:13 +00:00
|
|
|
|
FullPath += wxT( "/doc/help/" );
|
2008-12-08 15:27:13 +00:00
|
|
|
|
LocaleString = wxGetApp().m_Locale->GetCanonicalName();
|
2008-03-30 15:12:08 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString path_tmp = FullPath;
|
2007-07-09 09:29:53 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2007-08-18 11:43:59 +00:00
|
|
|
|
path_tmp.MakeLower();
|
2007-07-09 09:29:53 +00:00
|
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( path_tmp.Contains( wxT( "kicad" ) ) )
|
|
|
|
|
{
|
|
|
|
|
if( wxDirExists( FullPath ) )
|
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* find kicad/help/ from environment variable KICAD */
|
2008-12-08 15:27:13 +00:00
|
|
|
|
if( !PathFound && wxGetApp().m_Env_Defined )
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
|
FullPath = wxGetApp().m_KicadEnv + wxT( "/doc/help/" );
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( wxDirExists( FullPath ) )
|
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-06 19:57:06 +00:00
|
|
|
|
/* find kicad/help/ from "s_HelpPathList" */
|
2007-08-18 11:43:59 +00:00
|
|
|
|
int ii = 0;
|
|
|
|
|
while( !PathFound )
|
|
|
|
|
{
|
|
|
|
|
FullPath = s_HelpPathList[ii++];
|
|
|
|
|
if( FullPath == wxT( "end_list" ) )
|
|
|
|
|
break;
|
|
|
|
|
if( wxDirExists( FullPath ) )
|
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( PathFound )
|
|
|
|
|
{
|
|
|
|
|
LangFullPath = FullPath + LocaleString + UNIX_STRING_DIR_SEP;
|
|
|
|
|
if( wxDirExists( LangFullPath ) )
|
|
|
|
|
return LangFullPath;
|
|
|
|
|
|
|
|
|
|
LangFullPath = FullPath + LocaleString.Left( 2 ) + UNIX_STRING_DIR_SEP;
|
|
|
|
|
if( wxDirExists( LangFullPath ) )
|
|
|
|
|
return LangFullPath;
|
|
|
|
|
|
|
|
|
|
LangFullPath = FullPath + wxT( "en/" );
|
|
|
|
|
if( wxDirExists( LangFullPath ) )
|
|
|
|
|
return LangFullPath;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LangFullPath = FullPath + wxT( "fr/" );
|
|
|
|
|
if( wxDirExists( LangFullPath ) )
|
|
|
|
|
return LangFullPath;
|
|
|
|
|
}
|
|
|
|
|
return FullPath;
|
|
|
|
|
}
|
|
|
|
|
return wxEmptyString;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/********************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString FindKicadFile( const wxString& shortname )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/********************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/* Search the executable file shortname in kicad binary path
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* and return full file name if found or shortname
|
|
|
|
|
* kicad binary path is
|
2008-06-22 08:54:05 +00:00
|
|
|
|
* kicad/bin
|
2008-02-20 19:12:36 +00:00
|
|
|
|
*
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* kicad binary path is found from:
|
|
|
|
|
* BinDir
|
|
|
|
|
* or environment variable KICAD
|
|
|
|
|
* or (default) c:\kicad ou /usr/local/kicad
|
|
|
|
|
* or default binary path
|
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString FullFileName;
|
|
|
|
|
|
|
|
|
|
/* test de la presence du fichier shortname dans le repertoire de
|
|
|
|
|
* des binaires de kicad */
|
2008-12-08 15:27:13 +00:00
|
|
|
|
FullFileName = wxGetApp().m_BinDir + shortname;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( wxFileExists( FullFileName ) )
|
|
|
|
|
return FullFileName;
|
|
|
|
|
|
|
|
|
|
/* test de la presence du fichier shortname dans le repertoire
|
|
|
|
|
* defini par la variable d'environnement KICAD */
|
2008-12-08 15:27:13 +00:00
|
|
|
|
if( wxGetApp().m_Env_Defined )
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
|
FullFileName = wxGetApp().m_KicadEnv + shortname;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( wxFileExists( FullFileName ) )
|
|
|
|
|
return FullFileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* find binary file from default path list:
|
|
|
|
|
* /usr/local/kicad/linux or c:/kicad/winexe
|
|
|
|
|
* (see s_KicadDataPathList) */
|
|
|
|
|
int ii = 0;
|
|
|
|
|
while( 1 )
|
|
|
|
|
{
|
|
|
|
|
if( s_KicadBinaryPathList[ii] == wxT( "end_list" ) )
|
|
|
|
|
break;
|
|
|
|
|
FullFileName = s_KicadBinaryPathList[ii++] + shortname;
|
|
|
|
|
if( wxFileExists( FullFileName ) )
|
|
|
|
|
return FullFileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return shortname;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***********************************************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***********************************************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
/* Call the executable file "ExecFile", with params "param"
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString FullFileName;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
FullFileName = FindKicadFile( ExecFile );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( wxFileExists( FullFileName ) )
|
|
|
|
|
{
|
|
|
|
|
if( !param.IsEmpty() )
|
|
|
|
|
FullFileName += wxT( " " ) + param;
|
2008-04-24 16:55:35 +00:00
|
|
|
|
ProcessExecute( FullFileName );
|
2007-08-18 11:43:59 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
msg.Printf( wxT( "Command file <%s> not found" ), FullFileName.GetData() );
|
|
|
|
|
DisplayError( frame, msg, 20 );
|
|
|
|
|
return -1;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
void SetRealLibraryPath( const wxString& shortlibname )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/****************************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/* met a jour le chemin des librairies g_RealLibDirBuffer (global)
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* a partir de UserLibDirBuffer (global):
|
|
|
|
|
* Si UserLibDirBuffer non vide g_RealLibDirBuffer = g_UserLibDirBuffer.
|
|
|
|
|
* Sinon si variable d'environnement KICAD definie (KICAD = chemin pour kicad),
|
|
|
|
|
* g_UserLibDirBuffer = <KICAD>/shortlibname;
|
|
|
|
|
* Sinon g_UserLibDirBuffer = <Chemin des binaires>../shortlibname/
|
|
|
|
|
* Sinon g_UserLibDirBuffer = /usr/share/kicad/shortlibname/
|
2008-02-20 19:12:36 +00:00
|
|
|
|
*
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* Remarque:
|
2008-06-22 08:54:05 +00:00
|
|
|
|
* Les \ sont remplaces par / (a la mode Unix)
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
bool PathFound = FALSE;
|
|
|
|
|
|
|
|
|
|
if( !g_UserLibDirBuffer.IsEmpty() ) // Chemin impose par la configuration
|
|
|
|
|
{
|
|
|
|
|
g_RealLibDirBuffer = g_UserLibDirBuffer;
|
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_RealLibDirBuffer = ReturnKicadDatasPath();
|
2008-12-08 15:27:13 +00:00
|
|
|
|
if( wxGetApp().m_Env_Defined ) // Chemin impose par la variable d'environnement
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
g_RealLibDirBuffer += shortlibname;
|
|
|
|
|
if( wxDirExists( g_RealLibDirBuffer ) )
|
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_RealLibDirBuffer.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
if( g_RealLibDirBuffer.Last() != '/' )
|
|
|
|
|
g_RealLibDirBuffer += UNIX_STRING_DIR_SEP;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***********************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
|
wxString ReturnKicadDatasPath()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***********************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/* Retourne le chemin des donnees communes de kicad.
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* Si variable d'environnement KICAD definie (KICAD = chemin pour kicad),
|
|
|
|
|
* retourne <KICAD>/;
|
|
|
|
|
* Sinon retourne <Chemin des binaires>/ (si "kicad" est dans le nom du chemin)
|
|
|
|
|
* Sinon retourne /usr/share/kicad/
|
2008-02-20 19:12:36 +00:00
|
|
|
|
*
|
2007-08-18 11:43:59 +00:00
|
|
|
|
* Remarque:
|
2008-02-12 21:12:46 +00:00
|
|
|
|
* Les \ sont remplac<EFBFBD>s par / (a la mode Unix)
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
bool PathFound = FALSE;
|
|
|
|
|
wxString data_path;
|
|
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
|
if( wxGetApp().m_Env_Defined ) // Chemin impose par la variable d'environnement
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
|
data_path = wxGetApp().m_KicadEnv;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else // Chemin cherche par le chemin des executables
|
|
|
|
|
{
|
2008-03-30 15:12:08 +00:00
|
|
|
|
// le chemin est bindir../
|
2008-12-08 15:27:13 +00:00
|
|
|
|
wxString tmp = wxGetApp().m_BinDir;
|
2007-07-09 09:29:53 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2007-08-18 11:43:59 +00:00
|
|
|
|
tmp.MakeLower();
|
2007-07-09 09:29:53 +00:00
|
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( tmp.Contains( wxT( "kicad" ) ) )
|
|
|
|
|
{
|
2007-07-09 09:29:53 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2008-12-08 15:27:13 +00:00
|
|
|
|
tmp = wxGetApp().m_BinDir;
|
2007-07-09 09:29:53 +00:00
|
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( tmp.Last() == '/' )
|
|
|
|
|
tmp.RemoveLast();
|
|
|
|
|
data_path = tmp.BeforeLast( '/' ); // id cd ../
|
|
|
|
|
data_path += UNIX_STRING_DIR_SEP;
|
2008-12-08 15:27:13 +00:00
|
|
|
|
|
2008-06-22 08:54:05 +00:00
|
|
|
|
// Old versions of kicad use kicad/ as default for data
|
|
|
|
|
// and last versions kicad/share/
|
|
|
|
|
// So we search for kicad/share/ first
|
|
|
|
|
wxString old_path = data_path;
|
2008-12-08 15:27:13 +00:00
|
|
|
|
data_path += wxT( "share/" );
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( wxDirExists( data_path ) )
|
|
|
|
|
PathFound = TRUE;
|
2008-12-08 15:27:13 +00:00
|
|
|
|
else if( wxDirExists( old_path ) )
|
2008-06-22 08:54:05 +00:00
|
|
|
|
{
|
|
|
|
|
data_path = old_path;
|
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
2007-08-18 11:43:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* find kicad from default path list:
|
|
|
|
|
* /usr/local/kicad/ or c:/kicad/
|
|
|
|
|
* (see s_KicadDataPathList) */
|
|
|
|
|
int ii = 0;
|
|
|
|
|
while( !PathFound )
|
|
|
|
|
{
|
|
|
|
|
if( s_KicadDataPathList[ii] == wxT( "end_list" ) )
|
|
|
|
|
break;
|
|
|
|
|
data_path = s_KicadDataPathList[ii++];
|
|
|
|
|
if( wxDirExists( data_path ) )
|
|
|
|
|
PathFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( PathFound )
|
|
|
|
|
{
|
|
|
|
|
data_path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
if( data_path.Last() != '/' )
|
|
|
|
|
data_path += UNIX_STRING_DIR_SEP;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
data_path.Empty();
|
|
|
|
|
|
|
|
|
|
return data_path;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
|
wxString GetEditorName()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/* Return the prefered editor name
|
2007-08-18 11:43:59 +00:00
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString editorname = g_EditorName;
|
|
|
|
|
|
|
|
|
|
if( editorname.IsEmpty() ) // We get the prefered editor name from environment variable
|
|
|
|
|
{
|
|
|
|
|
wxGetEnv( wxT( "EDITOR" ), &editorname );
|
|
|
|
|
}
|
|
|
|
|
if( editorname.IsEmpty() ) // We must get a prefered editor name
|
|
|
|
|
{
|
|
|
|
|
DisplayInfo( NULL, _( "No default editor found, you must choose it" ) );
|
|
|
|
|
wxString mask( wxT( "*" ) );
|
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#ifdef __WINDOWS__
|
2007-08-18 11:43:59 +00:00
|
|
|
|
mask += wxT( ".exe" );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
|
editorname = EDA_FileSelector( _( "Prefered Editor:" ),
|
2008-12-08 15:27:13 +00:00
|
|
|
|
wxEmptyString, /* Default path */
|
|
|
|
|
wxEmptyString, /* default filename */
|
|
|
|
|
wxEmptyString, /* default filename extension */
|
|
|
|
|
mask, /* filter for filename list */
|
|
|
|
|
NULL, /* parent frame */
|
|
|
|
|
wxFD_OPEN, /* wxFD_SAVE, wxFD_OPEN ..*/
|
|
|
|
|
TRUE /* true = keep the current path */
|
|
|
|
|
);
|
2007-08-18 11:43:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
|
if( ( !editorname.IsEmpty() ) && wxGetApp().m_EDA_CommonConfig )
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
|
|
|
|
g_EditorName = editorname;
|
2008-12-08 15:27:13 +00:00
|
|
|
|
wxGetApp().m_EDA_CommonConfig->Write( wxT( "Editor" ), g_EditorName );
|
2007-08-18 11:43:59 +00:00
|
|
|
|
}
|
|
|
|
|
return g_EditorName;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
/***********************************/
|
|
|
|
|
bool OpenPDF( const wxString& file )
|
|
|
|
|
/***********************************/
|
2008-12-08 15:27:13 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
/** Function OpenPDF
|
|
|
|
|
* run the PDF viewer and display a PDF file
|
|
|
|
|
* @param file = PDF file to open
|
|
|
|
|
* @return true is success, false if no PDF viewer found
|
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString command;
|
|
|
|
|
wxString filename = file;
|
|
|
|
|
wxString type;
|
2008-12-08 15:27:13 +00:00
|
|
|
|
bool success = false;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
|
wxGetApp().ReadPdfBrowserInfos();
|
|
|
|
|
if( !wxGetApp().m_PdfBrowserIsDefault ) // Run the prefered PDF Browser
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
|
|
|
|
AddDelimiterString( filename );
|
2008-12-08 15:27:13 +00:00
|
|
|
|
command = wxGetApp().m_PdfBrowser + wxT( " " ) + filename;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
wxFileType* filetype = NULL;
|
|
|
|
|
wxFileType::MessageParameters params( filename, type );
|
2008-06-29 18:51:38 +00:00
|
|
|
|
filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) );
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( filetype )
|
|
|
|
|
success = filetype->GetOpenCommand( &command, params );
|
|
|
|
|
delete filetype;
|
2008-06-29 18:51:38 +00:00
|
|
|
|
#ifndef __WINDOWS__
|
2008-12-08 15:27:13 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
// Bug ? under linux wxWidgets returns acroread as PDF viewer,even it not exists
|
2008-12-08 15:27:13 +00:00
|
|
|
|
if( command.StartsWith( wxT( "acroread" ) ) ) // Workaround
|
2008-06-29 18:51:38 +00:00
|
|
|
|
success = false;
|
|
|
|
|
#endif
|
|
|
|
|
if( success && !command.IsEmpty() )
|
|
|
|
|
{
|
|
|
|
|
success = ProcessExecute( command );
|
2008-12-08 15:27:13 +00:00
|
|
|
|
if( success )
|
2008-07-08 18:45:06 +00:00
|
|
|
|
return success;
|
2008-06-29 18:51:38 +00:00
|
|
|
|
}
|
2008-07-08 18:45:06 +00:00
|
|
|
|
|
|
|
|
|
success = false;
|
|
|
|
|
command.Empty();
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
|
|
|
|
if( !success )
|
|
|
|
|
{
|
2008-06-29 18:51:38 +00:00
|
|
|
|
#ifndef __WINDOWS__
|
|
|
|
|
AddDelimiterString( filename );
|
|
|
|
|
/* here is a list of PDF viewers candidates */
|
2008-01-01 07:51:54 +00:00
|
|
|
|
const static wxString tries[] =
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
|
|
|
|
wxT( "/usr/bin/evince" ),
|
|
|
|
|
wxT( "/usr/bin/gpdf" ),
|
2008-06-29 18:51:38 +00:00
|
|
|
|
wxT( "/usr/bin/konqueror" ),
|
|
|
|
|
wxT( "/usr/bin/kpdf" ),
|
|
|
|
|
wxT( "/usr/bin/xpdf" ),
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxT( "" ),
|
|
|
|
|
};
|
2008-02-20 19:12:36 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
for( int ii = 0; ; ii++ )
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
2008-06-29 18:51:38 +00:00
|
|
|
|
if( tries[ii].IsEmpty() )
|
2007-08-18 11:43:59 +00:00
|
|
|
|
break;
|
2008-02-20 19:12:36 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
if( wxFileExists( tries[ii] ) )
|
2007-08-18 11:43:59 +00:00
|
|
|
|
{
|
2008-06-29 18:51:38 +00:00
|
|
|
|
command = tries[ii] + wxT( " " ) + filename;
|
|
|
|
|
break;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !command.IsEmpty() )
|
2008-06-29 18:51:38 +00:00
|
|
|
|
{
|
|
|
|
|
success = ProcessExecute( command );
|
2008-12-08 15:27:13 +00:00
|
|
|
|
if( !success )
|
2008-06-29 18:51:38 +00:00
|
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
|
wxString msg = _( "Problem while running the PDF viewer" );
|
|
|
|
|
msg << _( "\n command is " ) << command;
|
2008-06-29 18:51:38 +00:00
|
|
|
|
DisplayError( NULL, msg );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
|
wxString msg = _( "Unable to find a PDF viewer for" );
|
|
|
|
|
msg << wxT( " " ) << filename;
|
2008-06-29 18:51:38 +00:00
|
|
|
|
DisplayError( NULL, msg );
|
|
|
|
|
success = false;
|
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
return success;
|
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
|
|
2008-06-29 18:51:38 +00:00
|
|
|
|
/*************************************/
|
2007-08-18 11:43:59 +00:00
|
|
|
|
void OpenFile( const wxString& file )
|
2008-06-29 18:51:38 +00:00
|
|
|
|
/*************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxString command;
|
|
|
|
|
wxString filename = file;
|
|
|
|
|
|
|
|
|
|
wxFileName CurrentFileName( filename );
|
|
|
|
|
wxString ext, type;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
ext = CurrentFileName.GetExt();
|
|
|
|
|
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
bool success = false;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
wxFileType::MessageParameters params( filename, type );
|
|
|
|
|
if( filetype )
|
|
|
|
|
success = filetype->GetOpenCommand( &command, params );
|
|
|
|
|
delete filetype;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
|
if( success && !command.IsEmpty() )
|
2008-04-24 16:55:35 +00:00
|
|
|
|
ProcessExecute( command );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
}
|