Commit b1298e9b authored by dickelbeck's avatar dickelbeck

mac support fixes

parent 86c7926e
...@@ -33,639 +33,689 @@ ...@@ -33,639 +33,689 @@
// Path list for online help // Path list for online help
static wxString s_HelpPathList[] = { static wxString s_HelpPathList[] = {
#ifdef __WINDOWS__ #ifdef __WINDOWS__
wxT("c:/kicad/help/"), wxT( "c:/kicad/help/" ),
wxT("d:/kicad/help/"), wxT( "d:/kicad/help/" ),
wxT("c:/Program Files/kicad/help/"), wxT( "c:/Program Files/kicad/help/" ),
#else #else
wxT("/usr/share/doc/kicad/"), wxT( "/usr/share/doc/kicad/" ),
wxT("/usr/local/share/doc/kicad/"), wxT( "/usr/local/share/doc/kicad/" ),
wxT("/usr/local/kicad/share/doc/kicad/"), wxT( "/usr/local/kicad/share/doc/kicad/" ),
wxT("/usr/local/kicad/help/"), wxT( "/usr/local/kicad/help/" ),
wxT("/usr/share/doc/kicad/help"), wxT( "/usr/share/doc/kicad/help" ),
#endif #endif
wxT("end_list") // End of list symbol, do not change wxT( "end_list" ) // End of list symbol, do not change
}; };
// Path list for kicad data files // Path list for kicad data files
static wxString s_KicadDataPathList[] = { static wxString s_KicadDataPathList[] = {
#ifdef __WINDOWS__ #ifdef __WINDOWS__
wxT("c:/kicad/"), wxT( "c:/kicad/" ),
wxT("d:/kicad/"), wxT( "d:/kicad/" ),
wxT("c:/Program Files/kicad/"), wxT( "c:/Program Files/kicad/" ),
#else #else
wxT("/usr/share/kicad/"), wxT( "/usr/share/kicad/" ),
wxT("/usr/local/share/kicad/"), wxT( "/usr/local/share/kicad/" ),
wxT("/usr/local/kicad/share/kicad/"), wxT( "/usr/local/kicad/share/kicad/" ),
wxT("/usr/local/kicad/"), wxT( "/usr/local/kicad/" ),
#endif #endif
wxT("end_list") // End of list symbol, do not change wxT( "end_list" ) // End of list symbol, do not change
}; };
// Path list for kicad binary files // Path list for kicad binary files
static wxString s_KicadBinaryPathList[] = { static wxString s_KicadBinaryPathList[] = {
#ifdef __WINDOWS__ #ifdef __WINDOWS__
wxT("c:/kicad/winexe/"), wxT( "c:/kicad/winexe/" ),
wxT("d:/kicad/winexe/"), wxT( "d:/kicad/winexe/" ),
#else #else
wxT("/usr/bin/"), wxT( "/usr/bin/" ),
wxT("/usr/local/bin/"), wxT( "/usr/local/bin/" ),
wxT("/usr/local/kicad/bin/"), wxT( "/usr/local/kicad/bin/" ),
wxT("/usr/local/kicad/linux/"), wxT( "/usr/local/kicad/linux/" ),
#endif #endif
wxT("end_list") // End of list symbol, do not change wxT( "end_list" ) // End of list symbol, do not change
}; };
extern WinEDA_App * EDA_Appl; extern WinEDA_App* EDA_Appl;
/***************************************************************************/ /***************************************************************************/
wxString MakeReducedFileName( const wxString & fullfilename, wxString MakeReducedFileName( const wxString& fullfilename,
const wxString & default_path, const wxString& default_path,
const wxString & default_ext) const wxString& default_ext )
/***************************************************************************/ /***************************************************************************/
/* Calcule le nom "reduit" d'un fichier d'apres les chaines /* Calcule le nom "reduit" d'un fichier d'apres les chaines
fullfilename = nom complet * fullfilename = nom complet
default_path = prefixe (chemin) par defaut * default_path = prefixe (chemin) par defaut
default_ext = extension par defaut * default_ext = extension par defaut
*
retourne le nom reduit, c'est a dire: * retourne le nom reduit, c'est a dire:
sans le chemin si le chemin est default_path * sans le chemin si le chemin est default_path
avec ./ si si le chemin est le chemin courant * avec ./ si si le chemin est le chemin courant
sans l'extension si l'extension est default_ext * sans l'extension si l'extension est default_ext
*
Renvoie un chemin en notation unix ('/' en separateur de repertoire) * Renvoie un chemin en notation unix ('/' en separateur de repertoire)
*/ */
{ {
wxString reduced_filename = fullfilename; wxString reduced_filename = fullfilename;
wxString Cwd, ext, path; wxString Cwd, ext, path;
Cwd = default_path; Cwd = default_path;
ext = default_ext; ext = default_ext;
path = wxPathOnly(reduced_filename) + UNIX_STRING_DIR_SEP; path = wxPathOnly( reduced_filename ) + UNIX_STRING_DIR_SEP;
reduced_filename.Replace(WIN_STRING_DIR_SEP,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); Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
if ( Cwd.Last() != '/' ) Cwd += UNIX_STRING_DIR_SEP; if( Cwd.Last() != '/' )
path.Replace(WIN_STRING_DIR_SEP,UNIX_STRING_DIR_SEP); Cwd += UNIX_STRING_DIR_SEP;
path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
#ifdef __WINDOWS__ #ifdef __WINDOWS__
path.MakeLower(); path.MakeLower();
Cwd.MakeLower(); Cwd.MakeLower();
ext.MakeLower(); ext.MakeLower();
#endif #endif
// Si le fichier est dans chemin par defaut -> suppression du chemin par defaut // Si le fichier est dans chemin par defaut -> suppression du chemin par defaut
wxString root_path = path.Left(Cwd.Length()); wxString root_path = path.Left( Cwd.Length() );
if ( root_path == Cwd ) if( root_path == Cwd )
{ {
reduced_filename.Remove(0, Cwd.Length()); reduced_filename.Remove( 0, Cwd.Length() );
} }
else // Si fichier dans repertoire courant -> chemin = ./ else // Si fichier dans repertoire courant -> chemin = ./
{ {
Cwd = wxGetCwd() + UNIX_STRING_DIR_SEP; Cwd = wxGetCwd() + UNIX_STRING_DIR_SEP;
#ifdef __WINDOWS__ #ifdef __WINDOWS__
Cwd.MakeLower(); Cwd.MakeLower();
#endif #endif
Cwd.Replace(WIN_STRING_DIR_SEP,UNIX_STRING_DIR_SEP); Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
if ( path == Cwd ) if( path == Cwd )
{ // lib est dans rpertoire courant -> Chemin = "./" { // lib est dans rpertoire courant -> Chemin = "./"
reduced_filename.Remove(0, Cwd.Length()); reduced_filename.Remove( 0, Cwd.Length() );
wxString tmp = wxT("./") + reduced_filename; wxString tmp = wxT( "./" ) + reduced_filename;
reduced_filename = tmp; reduced_filename = tmp;
} }
} }
// Suppression extension standard: // Suppression extension standard:
if ( !ext.IsEmpty() && reduced_filename.Contains(ext) ) if( !ext.IsEmpty() && reduced_filename.Contains( ext ) )
reduced_filename.Truncate(reduced_filename.Length() - ext.Length()); reduced_filename.Truncate( reduced_filename.Length() - ext.Length() );
return(reduced_filename); return reduced_filename;
} }
/***************************************************************************/ /***************************************************************************/
wxString MakeFileName( const wxString & dir, wxString MakeFileName( const wxString& dir,
const wxString & shortname, const wxString & ext) const wxString& shortname, const wxString& ext )
/***************************************************************************/ /***************************************************************************/
/* Calcule le nom complet d'un fichier d'apres les chaines /* Calcule le nom complet d'un fichier d'apres les chaines
dir = prefixe (chemin) (peut etre "") * dir = prefixe (chemin) (peut etre "")
shortname = nom avec ou sans chemin ou extension * shortname = nom avec ou sans chemin ou extension
ext = extension (peut etre "") * ext = extension (peut etre "")
*
si shortname possede deja un chemin ou une extension, elles * si shortname possede deja un chemin ou une extension, elles
ne seront pas modifiees * ne seront pas modifiees
*
retourne la chaine calculee * retourne la chaine calculee
*/ */
{ {
wxString fullfilename; wxString fullfilename;
int ii; int ii;
if ( ! dir.IsEmpty() ) if( !dir.IsEmpty() )
{ {
if( ! shortname.Contains( UNIX_STRING_DIR_SEP ) && ! shortname.Contains( WIN_STRING_DIR_SEP) if( !shortname.Contains( UNIX_STRING_DIR_SEP ) && !shortname.Contains( WIN_STRING_DIR_SEP )
&& ! shortname.Contains( wxT(":") ) ) && !shortname.Contains( wxT( ":" ) ) )
{ /* aucun chemin n'est donne */ { /* aucun chemin n'est donne */
fullfilename = dir; fullfilename = dir;
} }
} }
fullfilename += shortname; fullfilename += shortname;
fullfilename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); fullfilename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
/* Placement de l'extension s'il n'y en a pas deja une */ /* Placement de l'extension s'il n'y en a pas deja une */
if( ext.IsEmpty() ) return(fullfilename); if( ext.IsEmpty() )
return fullfilename;
/* Recherche d'une eventuelle extension */
ii = fullfilename.Length(); /* Pointe la fin du texte */ /* Recherche d'une eventuelle extension */
for ( ; ii >= 0 ; ii-- ) ii = fullfilename.Length(); /* Pointe la fin du texte */
{ for( ; ii >= 0; ii-- )
if ( fullfilename.GetChar(ii) == '/' ) {
{ if( fullfilename.GetChar( ii ) == '/' )
/* Pas d'extension: placement de l'extension standard */ {
fullfilename += ext; /* Pas d'extension: placement de l'extension standard */
break; fullfilename += ext;
} break;
if ( fullfilename.GetChar(ii) == '.' ) /* extension trouvee */ }
break; if( fullfilename.GetChar( ii ) == '.' ) /* extension trouvee */
} break;
}
return(fullfilename);
return fullfilename;
} }
/*************************************************************************/ /*************************************************************************/
void ChangeFileNameExt( wxString & FullFileName, const wxString & NewExt ) void ChangeFileNameExt( wxString& FullFileName, const wxString& NewExt )
/**************************************************************************/ /**************************************************************************/
/* Change l'extension du "filename FullFileName" en NewExt. /* Change l'extension du "filename FullFileName" en NewExt.
*/ */
{ {
wxString FileName; wxString FileName;
FileName = FullFileName.BeforeLast('.'); FileName = FullFileName.BeforeLast( '.' );
if ( !FileName.IsEmpty() ) FileName += NewExt; if( !FileName.IsEmpty() )
else FileName = FullFileName + NewExt; FileName += NewExt;
else
FileName = FullFileName + NewExt;
if ( FileName.StartsWith( wxT("\"")) && ( FileName.Last() != '"' ) ) if( FileName.StartsWith( wxT( "\"" ) ) && ( FileName.Last() != '"' ) )
FileName += wxT("\""); FileName += wxT( "\"" );
FullFileName = FileName; FullFileName = FileName;
} }
/*******************************************/ /*******************************************/
void AddDelimiterString( wxString & string ) void AddDelimiterString( wxString& string )
/*******************************************/ /*******************************************/
/* ajoute un " en debut et fin de string s'il n'y en a pas deja. /* ajoute un " en debut et fin de string s'il n'y en a pas deja.
*/ */
{ {
wxString text; wxString text;
if ( ! string.StartsWith( wxT("\"")) ) text = wxT("\""); if( !string.StartsWith( wxT( "\"" ) ) )
text += string; text = wxT( "\"" );
if( (text.Last() != '"' ) || (text.length() <= 1) ) text += wxT("\""); text += string;
string = text; if( (text.Last() != '"' ) || (text.length() <= 1) )
text += wxT( "\"" );
string = text;
} }
/*************************************/
/* Fonction de selection de Repertoires */
/*************************************/
/*************************************/ bool EDA_DirectorySelector( const wxString& Title, /* Titre de la fenetre */
/* Fonction de selection de Repertoires */ wxString& Path, /* Chemin par defaut */
/*************************************/ int flag, /* reserve */
wxWindow* Frame, /* parent frame */
bool EDA_DirectorySelector(const wxString & Title, /* Titre de la fenetre */ const wxPoint& Pos )
wxString & Path, /* Chemin par defaut */
int flag, /* reserve */
wxWindow * Frame, /* parent frame */
const wxPoint & Pos)
{ {
int ii; int ii;
bool selected = FALSE; bool selected = FALSE;
wxDirDialog * DirFrame = new wxDirDialog( wxDirDialog* DirFrame = new wxDirDialog(
Frame, Frame,
wxString(Title), wxString( Title ),
Path, /* Chemin par defaut */ Path, /* Chemin par defaut */
flag, flag,
Pos ); Pos );
ii = DirFrame->ShowModal(); ii = DirFrame->ShowModal();
if ( ii == wxID_OK ) if( ii == wxID_OK )
{ {
Path = DirFrame->GetPath(); Path = DirFrame->GetPath();
selected = TRUE; selected = TRUE;
} }
DirFrame->Destroy(); DirFrame->Destroy();
return selected; return selected;
} }
/******************************/
/* Selection file dialog box: */ /******************************/
/******************************/ /* Selection file dialog box: */
/******************************/
wxString EDA_FileSelector(const wxString & Title, /* Dialog title */
const wxString & Path, /* Default path */ wxString EDA_FileSelector( const wxString& Title, /* Dialog title */
const wxString &FileName, /* default filename */ const wxString& Path, /* Default path */
const wxString & Ext, /* default filename extension */ const wxString& FileName, /* default filename */
const wxString & Mask, /* filter for filename list */ const wxString& Ext, /* default filename extension */
wxWindow * Frame, /* parent frame */ const wxString& Mask, /* filter for filename list */
int flag, /* wxFD_SAVE, wxFD_OPEN ..*/ wxWindow* Frame, /* parent frame */
const bool keep_working_directory, /* true = keep the current path */ int flag, /* wxFD_SAVE, wxFD_OPEN ..*/
const wxPoint & Pos) const bool keep_working_directory, /* true = keep the current path */
const wxPoint& Pos )
{ {
wxString fullfilename; wxString fullfilename;
wxString curr_cwd = wxGetCwd(); wxString curr_cwd = wxGetCwd();
wxString defaultname = FileName; wxString defaultname = FileName;
wxString defaultpath = Path; wxString defaultpath = Path;
defaultname.Replace(wxT("/"), STRING_DIR_SEP); defaultname.Replace( wxT( "/" ), STRING_DIR_SEP );
defaultpath.Replace(wxT("/"), STRING_DIR_SEP); defaultpath.Replace( wxT( "/" ), STRING_DIR_SEP );
if ( defaultpath.IsEmpty() ) defaultpath = wxGetCwd(); if( defaultpath.IsEmpty() )
defaultpath = wxGetCwd();
wxSetWorkingDirectory( defaultpath ); wxSetWorkingDirectory( defaultpath );
fullfilename = wxFileSelector( wxString(Title), fullfilename = wxFileSelector( wxString( Title ),
defaultpath, defaultpath,
defaultname, defaultname,
Ext, Ext,
Mask, Mask,
flag, /* options d'affichage (wxFD_OPEN, wxFD_SAVE .. */ flag,/* options d'affichage (wxFD_OPEN, wxFD_SAVE .. */
Frame, Frame,
Pos.x, Pos.y ); Pos.x, Pos.y );
if ( keep_working_directory ) wxSetWorkingDirectory(curr_cwd); if( keep_working_directory )
wxSetWorkingDirectory( curr_cwd );
return fullfilename; return fullfilename;
} }
/********************************************************/ /********************************************************/
wxString FindKicadHelpPath(void) wxString FindKicadHelpPath( void )
/********************************************************/ /********************************************************/
/* Find absolute path for kicad/help (or kicad/help/<language>) */ /* Find absolute path for kicad/help (or kicad/help/<language>) */
/* Find path kicad/help/xx/ ou kicad/help/: /* Find path kicad/help/xx/ ou kicad/help/:
from BinDir * from BinDir
else from environment variable KICAD * else from environment variable KICAD
else from one of s_HelpPathList * else from one of s_HelpPathList
typically c:\kicad\help or /usr/local/kicad/help or /usr/share/doc/kicad * typically c:\kicad\help or /usr/local/kicad/help or /usr/share/doc/kicad
(must have kicad in path name) * (must have kicad in path name)
*
xx = iso639-1 language id (2 letters (generic) or 4 letters): * xx = iso639-1 language id (2 letters (generic) or 4 letters):
fr = french (or fr_FR) * fr = french (or fr_FR)
en = English (or en_GB or en_US ...) * en = English (or en_GB or en_US ...)
de = deutch * de = deutch
es = spanish * es = spanish
pt = portuguese (or pt_BR ...) * pt = portuguese (or pt_BR ...)
*
default = en (if not found = fr) * default = en (if not found = fr)
*
*/ */
{ {
wxString FullPath, LangFullPath, tmp; wxString FullPath, LangFullPath, tmp;
wxString LocaleString; wxString LocaleString;
bool PathFound = FALSE; bool PathFound = FALSE;
/* find kicad/help/ */ /* find kicad/help/ */
tmp = EDA_Appl->m_BinDir; tmp = EDA_Appl->m_BinDir;
if ( tmp.Last() == '/' ) tmp.RemoveLast(); if( tmp.Last() == '/' )
FullPath = tmp.BeforeLast('/'); // Idem cd .. tmp.RemoveLast();
FullPath += wxT("/help/"); FullPath = tmp.BeforeLast( '/' ); // Idem cd ..
LocaleString = EDA_Appl->m_Locale->GetCanonicalName(); FullPath += wxT( "/help/" );
LocaleString = EDA_Appl->m_Locale->GetCanonicalName();
wxString path_tmp = FullPath;
wxString path_tmp = FullPath;
#ifdef __WINDOWS__ #ifdef __WINDOWS__
path_tmp.MakeLower(); path_tmp.MakeLower();
#endif #endif
if ( path_tmp.Contains( wxT("kicad")) ) if( path_tmp.Contains( wxT( "kicad" ) ) )
{ {
if ( wxDirExists(FullPath) ) PathFound = TRUE; if( wxDirExists( FullPath ) )
} PathFound = TRUE;
}
/* find kicad/help/ from environment variable KICAD */
if ( ! PathFound && EDA_Appl->m_Env_Defined ) /* find kicad/help/ from environment variable KICAD */
{ if( !PathFound && EDA_Appl->m_Env_Defined )
FullPath = EDA_Appl->m_KicadEnv + wxT("/help/"); {
if ( wxDirExists(FullPath) ) PathFound = TRUE; FullPath = EDA_Appl->m_KicadEnv + wxT( "/help/" );
} if( wxDirExists( FullPath ) )
PathFound = TRUE;
/* find kicad/help/ from default path list: }
/usr/local/kicad/help or c:/kicad/help
(see s_HelpPathList) */ /* find kicad/help/ from default path list:
int ii = 0; * /usr/local/kicad/help or c:/kicad/help
while ( ! PathFound ) * (see s_HelpPathList) */
{ int ii = 0;
FullPath = s_HelpPathList[ii++]; while( !PathFound )
if ( FullPath == wxT("end_list") ) break; {
if ( wxDirExists(FullPath) ) PathFound = TRUE; FullPath = s_HelpPathList[ii++];
} if( FullPath == wxT( "end_list" ) )
break;
if( wxDirExists( FullPath ) )
if ( PathFound ) PathFound = TRUE;
{ }
LangFullPath = FullPath + LocaleString + UNIX_STRING_DIR_SEP;
if ( wxDirExists(LangFullPath) ) return LangFullPath; if( PathFound )
{
LangFullPath = FullPath + LocaleString.Left(2) + UNIX_STRING_DIR_SEP; LangFullPath = FullPath + LocaleString + UNIX_STRING_DIR_SEP;
if ( wxDirExists(LangFullPath) ) return LangFullPath;
if( wxDirExists( LangFullPath ) )
LangFullPath = FullPath + wxT("en/"); return LangFullPath;
if ( wxDirExists(LangFullPath) ) return LangFullPath;
else LangFullPath = FullPath + LocaleString.Left( 2 ) + UNIX_STRING_DIR_SEP;
{ if( wxDirExists( LangFullPath ) )
LangFullPath = FullPath + wxT("fr/"); return LangFullPath;
if ( wxDirExists(LangFullPath) ) return LangFullPath;
} LangFullPath = FullPath + wxT( "en/" );
return FullPath; if( wxDirExists( LangFullPath ) )
} return LangFullPath;
return wxEmptyString; else
{
LangFullPath = FullPath + wxT( "fr/" );
if( wxDirExists( LangFullPath ) )
return LangFullPath;
}
return FullPath;
}
return wxEmptyString;
} }
/********************************************************/ /********************************************************/
wxString FindKicadFile(const wxString & shortname) wxString FindKicadFile( const wxString& shortname )
/********************************************************/ /********************************************************/
/* Search the executable file shortname in kicad binary path /* Search the executable file shortname in kicad binary path
and return full file name if found or shortname * and return full file name if found or shortname
kicad binary path is * kicad binary path is
kicad/winexe or kicad/linux * kicad/winexe or kicad/linux
*
kicad binary path is found from: * kicad binary path is found from:
BinDir * BinDir
or environment variable KICAD * or environment variable KICAD
or (default) c:\kicad ou /usr/local/kicad * or (default) c:\kicad ou /usr/local/kicad
or default binary path * or default binary path
*/ */
{ {
wxString FullFileName; wxString FullFileName;
/* test de la presence du fichier shortname dans le repertoire de /* test de la presence du fichier shortname dans le repertoire de
des binaires de kicad */ * des binaires de kicad */
FullFileName = EDA_Appl->m_BinDir + shortname; FullFileName = EDA_Appl->m_BinDir + shortname;
if ( wxFileExists(FullFileName) ) return FullFileName; if( wxFileExists( FullFileName ) )
return FullFileName;
/* test de la presence du fichier shortname dans le repertoire
defini par la variable d'environnement KICAD */ /* test de la presence du fichier shortname dans le repertoire
if ( EDA_Appl->m_Env_Defined ) * defini par la variable d'environnement KICAD */
{ if( EDA_Appl->m_Env_Defined )
FullFileName = EDA_Appl->m_KicadEnv + shortname; {
if ( wxFileExists(FullFileName) ) return FullFileName; FullFileName = EDA_Appl->m_KicadEnv + shortname;
} if( wxFileExists( FullFileName ) )
return FullFileName;
/* find binary file from default path list: }
/usr/local/kicad/linux or c:/kicad/winexe
(see s_KicadDataPathList) */ /* find binary file from default path list:
int ii = 0; * /usr/local/kicad/linux or c:/kicad/winexe
while ( 1 ) * (see s_KicadDataPathList) */
{ int ii = 0;
if ( s_KicadBinaryPathList[ii] == wxT("end_list") ) break; while( 1 )
FullFileName = s_KicadBinaryPathList[ii++] + shortname; {
if ( wxFileExists(FullFileName) ) return FullFileName; if( s_KicadBinaryPathList[ii] == wxT( "end_list" ) )
} break;
FullFileName = s_KicadBinaryPathList[ii++] + shortname;
return shortname; if( wxFileExists( FullFileName ) )
return FullFileName;
}
return shortname;
} }
/***********************************************************************************/ /***********************************************************************************/
int ExecuteFile(wxWindow * frame, const wxString & ExecFile, const wxString & param) int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param )
/***********************************************************************************/ /***********************************************************************************/
/* Call the executable file "ExecFile", with params "param" /* Call the executable file "ExecFile", with params "param"
*/ */
{ {
wxString FullFileName; wxString FullFileName;
#ifdef __WXMAC__ #ifdef __WXMAC__
// Mac part
wxGetEnv("HOME", &FullFileName); // Mac part
FullFileName += wxString("/bin/") + newExecFile; wxGetEnv( "HOME", &FullFileName );
if (! wxFileExists(FullFileName) ) FullFileName += wxString( "/bin/" ) + ExecFile;
{ if( !wxFileExists( FullFileName ) )
FullFileName = FindKicadFile(ExecFile); {
} FullFileName = FindKicadFile( ExecFile );
}
#else #else
FullFileName = FindKicadFile(ExecFile); FullFileName = FindKicadFile( ExecFile );
#endif #endif
if ( wxFileExists(FullFileName) ) if( wxFileExists( FullFileName ) )
{ {
if( !param.IsEmpty() ) FullFileName += wxT(" ") + param; if( !param.IsEmpty() )
wxExecute(FullFileName); FullFileName += wxT( " " ) + param;
return 0; wxExecute( FullFileName );
} return 0;
}
wxString msg;
msg.Printf( wxT("Command file <%s> not found"), FullFileName.GetData() ); wxString msg;
DisplayError(frame, msg, 20); msg.Printf( wxT( "Command file <%s> not found" ), FullFileName.GetData() );
return -1; DisplayError( frame, msg, 20 );
return -1;
} }
/****************************************************/ /****************************************************/
void SetRealLibraryPath(const wxString & shortlibname) void SetRealLibraryPath( const wxString& shortlibname )
/****************************************************/ /****************************************************/
/* met a jour le chemin des librairies g_RealLibDirBuffer (global) /* met a jour le chemin des librairies g_RealLibDirBuffer (global)
a partir de UserLibDirBuffer (global): * a partir de UserLibDirBuffer (global):
Si UserLibDirBuffer non vide g_RealLibDirBuffer = g_UserLibDirBuffer. * Si UserLibDirBuffer non vide g_RealLibDirBuffer = g_UserLibDirBuffer.
Sinon si variable d'environnement KICAD definie (KICAD = chemin pour kicad), * Sinon si variable d'environnement KICAD definie (KICAD = chemin pour kicad),
g_UserLibDirBuffer = <KICAD>/shortlibname; * g_UserLibDirBuffer = <KICAD>/shortlibname;
Sinon g_UserLibDirBuffer = <Chemin des binaires>../shortlibname/ * Sinon g_UserLibDirBuffer = <Chemin des binaires>../shortlibname/
Sinon g_UserLibDirBuffer = /usr/share/kicad/shortlibname/ * Sinon g_UserLibDirBuffer = /usr/share/kicad/shortlibname/
*
Remarque: * Remarque:
Les \ sont remplacs par / (a la mode Unix) * Les \ sont remplacs par / (a la mode Unix)
*/ */
{ {
bool PathFound = FALSE; bool PathFound = FALSE;
if ( ! g_UserLibDirBuffer.IsEmpty() ) // Chemin impose par la configuration if( !g_UserLibDirBuffer.IsEmpty() ) // Chemin impose par la configuration
{ {
g_RealLibDirBuffer = g_UserLibDirBuffer; g_RealLibDirBuffer = g_UserLibDirBuffer;
PathFound = TRUE; PathFound = TRUE;
} }
else
else {
{ g_RealLibDirBuffer = ReturnKicadDatasPath();
g_RealLibDirBuffer = ReturnKicadDatasPath(); if( EDA_Appl->m_Env_Defined ) // Chemin impose par la variable d'environnement
if ( EDA_Appl->m_Env_Defined ) // Chemin impose par la variable d'environnement {
{ PathFound = TRUE;
PathFound = TRUE; }
} g_RealLibDirBuffer += shortlibname;
g_RealLibDirBuffer += shortlibname; if( wxDirExists( g_RealLibDirBuffer ) )
if ( wxDirExists(g_RealLibDirBuffer) ) PathFound = TRUE; PathFound = TRUE;
} }
g_RealLibDirBuffer.Replace(WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP); g_RealLibDirBuffer.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
if ( g_RealLibDirBuffer.Last() != '/' ) g_RealLibDirBuffer += UNIX_STRING_DIR_SEP; if( g_RealLibDirBuffer.Last() != '/' )
g_RealLibDirBuffer += UNIX_STRING_DIR_SEP;
} }
/***********************************/ /***********************************/
wxString ReturnKicadDatasPath(void) wxString ReturnKicadDatasPath( void )
/***********************************/ /***********************************/
/* Retourne le chemin des donnees communes de kicad. /* Retourne le chemin des donnees communes de kicad.
Si variable d'environnement KICAD definie (KICAD = chemin pour kicad), * Si variable d'environnement KICAD definie (KICAD = chemin pour kicad),
retourne <KICAD>/; * retourne <KICAD>/;
Sinon retourne <Chemin des binaires>/ (si "kicad" est dans le nom du chemin) * Sinon retourne <Chemin des binaires>/ (si "kicad" est dans le nom du chemin)
Sinon retourne /usr/share/kicad/ * Sinon retourne /usr/share/kicad/
*
Remarque: * Remarque:
Les \ sont remplacs par / (a la mode Unix) * Les \ sont remplacs par / (a la mode Unix)
*/ */
{ {
bool PathFound = FALSE; bool PathFound = FALSE;
wxString data_path; wxString data_path;
if ( EDA_Appl->m_Env_Defined ) // Chemin impose par la variable d'environnement if( EDA_Appl->m_Env_Defined ) // Chemin impose par la variable d'environnement
{ {
data_path = EDA_Appl->m_KicadEnv; data_path = EDA_Appl->m_KicadEnv;
PathFound = TRUE; PathFound = TRUE;
} }
else // Chemin cherche par le chemin des executables else // Chemin cherche par le chemin des executables
{ // le chemin est bindir../ {
wxString tmp = EDA_Appl->m_BinDir; // le chemin est bindir../
wxString tmp = EDA_Appl->m_BinDir;
#ifdef __WINDOWS__ #ifdef __WINDOWS__
tmp.MakeLower(); tmp.MakeLower();
#endif #endif
if ( tmp.Contains( wxT("kicad") ) ) if( tmp.Contains( wxT( "kicad" ) ) )
{ {
#ifdef __WINDOWS__ #ifdef __WINDOWS__
tmp = EDA_Appl->m_BinDir; tmp = EDA_Appl->m_BinDir;
#endif #endif
if ( tmp.Last() == '/' ) tmp.RemoveLast(); if( tmp.Last() == '/' )
data_path = tmp.BeforeLast('/'); // id cd ../ tmp.RemoveLast();
data_path += UNIX_STRING_DIR_SEP; data_path = tmp.BeforeLast( '/' ); // id cd ../
if ( wxDirExists(data_path) ) PathFound = TRUE; data_path += UNIX_STRING_DIR_SEP;
} if( wxDirExists( data_path ) )
} PathFound = TRUE;
}
/* find kicad from default path list: }
/usr/local/kicad/ or c:/kicad/
(see s_KicadDataPathList) */ /* find kicad from default path list:
int ii = 0; * /usr/local/kicad/ or c:/kicad/
while ( ! PathFound ) * (see s_KicadDataPathList) */
{ int ii = 0;
if ( s_KicadDataPathList[ii] == wxT("end_list") ) break; while( !PathFound )
data_path = s_KicadDataPathList[ii++]; {
if ( wxDirExists(data_path) ) PathFound = TRUE; if( s_KicadDataPathList[ii] == wxT( "end_list" ) )
} break;
data_path = s_KicadDataPathList[ii++];
if ( PathFound ) if( wxDirExists( data_path ) )
{ PathFound = TRUE;
data_path.Replace(WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP); }
if ( data_path.Last() != '/' ) data_path += UNIX_STRING_DIR_SEP;
} if( PathFound )
{
else data_path.Empty(); data_path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
if( data_path.Last() != '/' )
return data_path; data_path += UNIX_STRING_DIR_SEP;
}
else
data_path.Empty();
return data_path;
} }
/***************************/ /***************************/
wxString GetEditorName(void) wxString GetEditorName( void )
/***************************/ /***************************/
/* Return the prefered editor name /* Return the prefered editor name
*/ */
{ {
wxString editorname = g_EditorName; wxString editorname = g_EditorName;
if ( editorname.IsEmpty() ) // We get the prefered editor name from environment variable if( editorname.IsEmpty() ) // We get the prefered editor name from environment variable
{ {
wxGetEnv(wxT("EDITOR"), &editorname); wxGetEnv( wxT( "EDITOR" ), &editorname );
} }
if ( editorname.IsEmpty() ) // We must get a prefered editor name if( editorname.IsEmpty() ) // We must get a prefered editor name
{ {
DisplayInfo(NULL, _("No default editor found, you must choose it") ); DisplayInfo( NULL, _( "No default editor found, you must choose it" ) );
wxString mask(wxT("*")); wxString mask( wxT( "*" ) );
#ifdef __WINDOWS__ #ifdef __WINDOWS__
mask += wxT(".exe"); mask += wxT( ".exe" );
#endif #endif
editorname = EDA_FileSelector(_("Prefered Editor:"), editorname = EDA_FileSelector( _( "Prefered Editor:" ),
wxEmptyString, /* Default path */ wxEmptyString, /* Default path */
wxEmptyString, /* default filename */ wxEmptyString, /* default filename */
wxEmptyString, /* default filename extension */ wxEmptyString, /* default filename extension */
mask, /* filter for filename list */ mask, /* filter for filename list */
NULL, /* parent frame */ NULL, /* parent frame */
wxFD_OPEN, /* wxFD_SAVE, wxFD_OPEN ..*/ wxFD_OPEN, /* wxFD_SAVE, wxFD_OPEN ..*/
TRUE /* true = keep the current path */ TRUE /* true = keep the current path */
); );
} }
if ( (!editorname.IsEmpty()) && EDA_Appl->m_EDA_CommonConfig) if( ( !editorname.IsEmpty() ) && EDA_Appl->m_EDA_CommonConfig )
{ {
g_EditorName = editorname; g_EditorName = editorname;
EDA_Appl->m_EDA_CommonConfig->Write( wxT("Editor"), g_EditorName); EDA_Appl->m_EDA_CommonConfig->Write( wxT( "Editor" ), g_EditorName );
} }
return g_EditorName; return g_EditorName;
} }
void OpenPDF( const wxString & file )
void OpenPDF( const wxString& file )
{ {
wxString command; wxString command;
wxString filename = file; wxString filename = file;
wxString type; wxString type;
EDA_Appl->ReadPdfBrowserInfos(); EDA_Appl->ReadPdfBrowserInfos();
if ( !EDA_Appl->m_PdfBrowserIsDefault ) if( !EDA_Appl->m_PdfBrowserIsDefault )
{ {
AddDelimiterString(filename); AddDelimiterString( filename );
command = EDA_Appl->m_PdfBrowser + filename; command = EDA_Appl->m_PdfBrowser + filename;
} }
else else
{ {
bool success = false; bool success = false;
wxFileType * filetype = NULL; wxFileType* filetype = NULL;
wxFileType::MessageParameters params(filename, type); wxFileType::MessageParameters params( filename, type );
filetype = wxTheMimeTypesManager->GetFileTypeFromExtension(wxT(".pdf"));
if (filetype ) success = filetype->GetOpenCommand( &command, params); filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( ".pdf" ) );
delete filetype; if( filetype )
success = filetype->GetOpenCommand( &command, params );
if (!success) delete filetype;
{
AddDelimiterString(filename); if( !success )
command.Empty(); {
wxString tries[] = AddDelimiterString( filename );
{ command.Empty();
wxT("/usr/bin/evince"), wxString tries[] =
wxT("/usr/bin/xpdf"), {
wxT("/usr/bin/konqueror"), wxT( "/usr/bin/evince" ),
wxT("/usr/bin/gpdf"), wxT( "/usr/bin/xpdf" ),
wxT(""), wxT( "/usr/bin/konqueror" ),
}; wxT( "/usr/bin/gpdf" ),
for ( int i = 0;; i++ ) wxT( "" ),
{ };
if (tries[i].IsEmpty()) break; for( int i = 0; ; i++ )
if (wxFileExists(tries[i])) {
{ if( tries[i].IsEmpty() )
command = tries[i] + wxT(" ") + filename; break;
} if( wxFileExists( tries[i] ) )
} {
} command = tries[i] + wxT( " " ) + filename;
} }
}
if (!command.IsEmpty()) wxExecute(command); }
}
if( !command.IsEmpty() )
wxExecute( command );
} }
void OpenFile( const wxString & file ) void OpenFile( const wxString& file )
{ {
wxString command; wxString command;
wxString filename = file; wxString filename = file;
wxFileName CurrentFileName( filename );
wxString ext, type;
wxFileName CurrentFileName(filename); ext = CurrentFileName.GetExt();
wxString ext, type; wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
ext = CurrentFileName.GetExt();
wxFileType * filetype = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
bool success = false; bool success = false;
wxFileType::MessageParameters params(filename, type); wxFileType::MessageParameters params( filename, type );
if (filetype) success = filetype->GetOpenCommand( &command, params); if( filetype )
delete filetype; success = filetype->GetOpenCommand( &command, params );
delete filetype;
if (success && !command.IsEmpty()) wxExecute(command); if( success && !command.IsEmpty() )
wxExecute( command );
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment