2009-01-18 10:15:10 +00:00
|
|
|
/***************/
|
|
|
|
/* edaappl.cpp */
|
|
|
|
/***************/
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2008-12-29 11:26:15 +00:00
|
|
|
/***
|
|
|
|
* @file edaapl.cpp
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
|
|
|
* @brief For the main application: init functions, and language selection
|
|
|
|
* (locale handling)
|
2008-12-29 11:26:15 +00:00
|
|
|
***/
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
2009-01-07 15:59:49 +00:00
|
|
|
# include <pyhandler.h>
|
2007-05-28 18:09:49 +00:00
|
|
|
#endif
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "fctsys.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "wx/html/htmlwin.h"
|
|
|
|
#include "wx/fs_zip.h"
|
2009-01-17 20:31:19 +00:00
|
|
|
#include <wx/dir.h>
|
2009-01-07 15:59:49 +00:00
|
|
|
#include <wx/filename.h>
|
2009-01-17 20:31:19 +00:00
|
|
|
#include <wx/stdpaths.h>
|
|
|
|
#include <wx/apptrait.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
#include <wx/snglinst.h>
|
2009-04-18 14:14:40 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "common.h"
|
2009-03-28 20:02:34 +00:00
|
|
|
#include "param_config.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "worksheet.h"
|
|
|
|
#include "id.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "build_version.h"
|
2007-09-06 11:52:26 +00:00
|
|
|
#include "hotkeys_basic.h"
|
2007-11-05 07:07:00 +00:00
|
|
|
#include "macros.h"
|
2008-06-11 10:33:13 +00:00
|
|
|
#include "online_help.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "bitmaps.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "gestfich.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
static const wxChar* CommonConfigPath = wxT( "kicad_common" );
|
|
|
|
|
|
|
|
|
2008-12-29 11:26:15 +00:00
|
|
|
#ifdef __UNIX__
|
2009-01-07 15:59:49 +00:00
|
|
|
# define TMP_FILE "/tmp/kicad.tmp"
|
2008-12-29 11:26:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Just add new languages to the list. This macro will properly recalculate
|
|
|
|
* the size of the array. */
|
|
|
|
#define LANGUAGE_DESCR_COUNT ( sizeof( s_Language_List ) / \
|
2009-04-18 14:14:40 +00:00
|
|
|
sizeof( struct LANGUAGE_DESCR ) )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-29 11:26:15 +00:00
|
|
|
/* Default font size */
|
|
|
|
#define FONT_DEFAULT_SIZE 10 /* Default font size. */
|
|
|
|
|
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* The real font size will be computed at run time
|
2009-04-05 20:49:15 +00:00
|
|
|
* A small class to handle the list on existing translations.
|
2008-12-29 11:26:15 +00:00
|
|
|
* the locale translation is automatic.
|
2009-04-05 20:49:15 +00:00
|
|
|
* the selection of languages is mainly for maintainer's convenience
|
|
|
|
* To add a support to a new translation:
|
|
|
|
* create a new icon (flag of the country) (see Lang_Fr.xpm as an example)
|
2008-12-29 11:26:15 +00:00
|
|
|
* add a new item to s_Language_List[LANGUAGE_DESCR_COUNT]
|
|
|
|
* and set LANGUAGE_DESCR_COUNT to the new value
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
struct LANGUAGE_DESCR
|
2008-04-18 13:28:56 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
/* wxWidgets locale identifier (See wxWidgets doc) */
|
|
|
|
int m_WX_Lang_Identifier;
|
|
|
|
|
|
|
|
/* KiCad identifier used in menu selection (See id.h) */
|
|
|
|
int m_KI_Lang_Identifier;
|
|
|
|
|
|
|
|
/* The menu language icons */
|
|
|
|
const char** m_Lang_Icon;
|
|
|
|
|
|
|
|
/* Labels used in menus */
|
|
|
|
const wxChar* m_Lang_Label;
|
|
|
|
|
|
|
|
/* Set to true if the m_Lang_Label must not be translated */
|
|
|
|
bool m_DoNotTranslate;
|
2008-04-18 13:28:56 +00:00
|
|
|
};
|
|
|
|
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* Language list struct
|
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
static struct LANGUAGE_DESCR s_Language_List[] =
|
2008-04-18 13:28:56 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
/* Default language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_DEFAULT,
|
|
|
|
ID_LANGUAGE_DEFAULT,
|
|
|
|
lang_def_xpm,
|
|
|
|
_( "Default" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* English language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_ENGLISH,
|
|
|
|
ID_LANGUAGE_ENGLISH,
|
|
|
|
lang_en_xpm,
|
|
|
|
wxT( "English" ),
|
|
|
|
true
|
|
|
|
},
|
|
|
|
|
|
|
|
/* French language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_FRENCH,
|
|
|
|
ID_LANGUAGE_FRENCH,
|
|
|
|
lang_fr_xpm,
|
|
|
|
_( "French" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Spanish language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_SPANISH,
|
|
|
|
ID_LANGUAGE_SPANISH,
|
|
|
|
lang_es_xpm,
|
|
|
|
_( "Spanish" )
|
|
|
|
},
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Portuguese language */
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
|
|
|
wxLANGUAGE_PORTUGUESE,
|
|
|
|
ID_LANGUAGE_PORTUGUESE,
|
|
|
|
lang_pt_xpm,
|
|
|
|
_( "Portuguese" )
|
2008-04-18 13:28:56 +00:00
|
|
|
},
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
/* Italian language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_ITALIAN,
|
|
|
|
ID_LANGUAGE_ITALIAN,
|
|
|
|
lang_it_xpm,
|
|
|
|
_( "Italian" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* German language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_GERMAN,
|
|
|
|
ID_LANGUAGE_GERMAN,
|
|
|
|
lang_de_xpm,
|
|
|
|
_( "German" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Slovenian language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_SLOVENIAN,
|
|
|
|
ID_LANGUAGE_SLOVENIAN,
|
|
|
|
lang_sl_xpm,
|
|
|
|
_( "Slovenian" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Hungarian language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_HUNGARIAN,
|
|
|
|
ID_LANGUAGE_HUNGARIAN,
|
|
|
|
lang_hu_xpm,
|
|
|
|
_( "Hungarian" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Polish language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_POLISH,
|
|
|
|
ID_LANGUAGE_POLISH,
|
|
|
|
lang_pl_xpm,
|
|
|
|
_( "Polish" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Czech language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_CZECH,
|
|
|
|
ID_LANGUAGE_CZECH,
|
|
|
|
lang_cs_xpm,
|
|
|
|
_( "Czech" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Russian language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_RUSSIAN,
|
|
|
|
ID_LANGUAGE_RUSSIAN,
|
|
|
|
lang_ru_xpm,
|
|
|
|
_( "Russian" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Korean language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_KOREAN,
|
|
|
|
ID_LANGUAGE_KOREAN,
|
|
|
|
lang_ko_xpm,
|
|
|
|
_( "Korean" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Chinese simplified */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_CHINESE_SIMPLIFIED,
|
|
|
|
ID_LANGUAGE_CHINESE_SIMPLIFIED,
|
|
|
|
lang_chinese_xpm,
|
|
|
|
_( "Chinese simplified" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Catalan language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_CATALAN,
|
|
|
|
ID_LANGUAGE_CATALAN,
|
|
|
|
lang_catalan_xpm,
|
|
|
|
_( "Catalan" )
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Dutch language */
|
|
|
|
{
|
|
|
|
wxLANGUAGE_DUTCH,
|
|
|
|
ID_LANGUAGE_DUTCH,
|
|
|
|
lang_nl_xpm,
|
|
|
|
_( "Dutch" )
|
|
|
|
}
|
2008-12-29 11:26:15 +00:00
|
|
|
};
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* WinEDA_App Constructor
|
|
|
|
*/
|
2007-09-13 11:55:46 +00:00
|
|
|
WinEDA_App::WinEDA_App()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
m_Checker = NULL;
|
|
|
|
m_HtmlCtrl = NULL;
|
2009-02-03 20:33:34 +00:00
|
|
|
m_EDA_Config = NULL;
|
|
|
|
m_Env_Defined = FALSE;
|
|
|
|
m_LanguageId = wxLANGUAGE_DEFAULT;
|
2009-01-07 15:59:49 +00:00
|
|
|
m_PdfBrowserIsDefault = TRUE;
|
2009-01-29 14:26:20 +00:00
|
|
|
m_Locale = NULL;
|
2009-04-18 14:14:40 +00:00
|
|
|
m_ProjectConfig = NULL;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_EDA_CommonConfig = NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-22 18:58:47 +00:00
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* WinEDA_App Destructor
|
|
|
|
*/
|
2007-09-13 11:55:46 +00:00
|
|
|
WinEDA_App::~WinEDA_App()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
SaveSettings();
|
|
|
|
|
|
|
|
/* delete user datas */
|
2009-04-05 20:49:15 +00:00
|
|
|
if( m_ProjectConfig )
|
|
|
|
delete m_ProjectConfig;
|
|
|
|
if( m_EDA_CommonConfig )
|
|
|
|
delete m_EDA_CommonConfig;
|
2009-01-07 15:59:49 +00:00
|
|
|
delete m_EDA_Config;
|
|
|
|
delete g_DialogFont;
|
|
|
|
delete g_FixedFont;
|
|
|
|
if( m_Checker )
|
|
|
|
delete m_Checker;
|
|
|
|
delete m_Locale;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
/** Function InitEDA_Appl
|
|
|
|
* initialise some general parameters
|
|
|
|
* - Default paths (help, libs, bin)and configuration flies names
|
|
|
|
* - Language and locale
|
|
|
|
* - fonts
|
|
|
|
* @param aName : used as paths in configuration files
|
|
|
|
* @param aId = flag : APP_TYPE_EESCHEMA, APP_TYPE_PCBNEW..
|
|
|
|
* used to choose what default library path must be used
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-04-12 14:39:54 +00:00
|
|
|
void WinEDA_App::InitEDA_Appl( const wxString& aName, id_app_type aId )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
wxString EnvLang;
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
m_Id = aId;
|
|
|
|
m_Checker = new wxSingleInstanceChecker( aName.Lower() + wxT( "-" ) +
|
2009-04-18 14:14:40 +00:00
|
|
|
wxGetUserId() );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
/* Init kicad environment
|
|
|
|
* the environment variable KICAD (if exists) gives the kicad path:
|
|
|
|
* something like set KICAD=d:\kicad
|
|
|
|
*/
|
|
|
|
m_Env_Defined = wxGetEnv( wxT( "KICAD" ), &m_KicadEnv );
|
|
|
|
if( m_Env_Defined ) // ensure m_KicadEnv ends by "/"
|
|
|
|
{
|
|
|
|
m_KicadEnv.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
if( m_KicadEnv.Last() != '/' )
|
|
|
|
m_KicadEnv += UNIX_STRING_DIR_SEP;
|
|
|
|
}
|
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
/* Prepare On Line Help. Use only lower case for help file names, in order to
|
|
|
|
* avoid problems with upper/lower case file names under windows and unix */
|
2008-06-11 10:33:13 +00:00
|
|
|
#if defined ONLINE_HELP_FILES_FORMAT_IS_HTML
|
2009-04-12 14:39:54 +00:00
|
|
|
m_HelpFileName = aName.Lower() + wxT( ".html" );
|
2008-06-11 10:33:13 +00:00
|
|
|
#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
|
2009-04-12 14:39:54 +00:00
|
|
|
m_HelpFileName = aName.Lower() + wxT( ".pdf" );
|
2008-06-11 10:33:13 +00:00
|
|
|
#else
|
2009-01-07 15:59:49 +00:00
|
|
|
#error Help files format not defined
|
2008-06-11 10:33:13 +00:00
|
|
|
#endif
|
2007-10-22 18:58:47 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
/* Init parameters for configuration */
|
|
|
|
SetVendorName( wxT( "kicad" ) );
|
2009-04-12 14:39:54 +00:00
|
|
|
SetAppName( aName.Lower() );
|
|
|
|
SetTitle( aName );
|
2009-04-18 14:14:40 +00:00
|
|
|
m_EDA_Config = new wxConfig();
|
2009-04-05 20:49:15 +00:00
|
|
|
wxASSERT( m_EDA_Config != NULL );
|
|
|
|
m_EDA_CommonConfig = new wxConfig( CommonConfigPath );
|
|
|
|
wxASSERT( m_EDA_CommonConfig != NULL );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
/* Create the fonts used in dialogs and messages */
|
|
|
|
g_DialogFontPointSize = FONT_DEFAULT_SIZE;
|
|
|
|
g_FixedFontPointSize = FONT_DEFAULT_SIZE;
|
|
|
|
|
|
|
|
g_DialogFont = new wxFont( g_DialogFontPointSize, wxFONTFAMILY_ROMAN,
|
|
|
|
wxNORMAL, wxNORMAL );
|
|
|
|
|
|
|
|
g_FixedFont = new wxFont( g_FixedFontPointSize, wxFONTFAMILY_MODERN,
|
|
|
|
wxNORMAL, wxNORMAL );
|
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
/* Install some image handlers, mainly for help */
|
2009-01-07 15:59:49 +00:00
|
|
|
wxImage::AddHandler( new wxPNGHandler );
|
|
|
|
wxImage::AddHandler( new wxGIFHandler );
|
|
|
|
wxImage::AddHandler( new wxJPEGHandler );
|
|
|
|
wxFileSystem::AddHandler( new wxZipFSHandler );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Analise the command line & init binary path
|
2009-01-07 15:59:49 +00:00
|
|
|
SetBinDir();
|
2009-01-17 20:31:19 +00:00
|
|
|
SetDefaultSearchPaths();
|
2009-01-29 14:26:20 +00:00
|
|
|
SetLanguagePath();
|
2009-01-07 15:59:49 +00:00
|
|
|
ReadPdfBrowserInfos();
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Internationalization: loading the kicad suitable Dictionary
|
2009-01-07 15:59:49 +00:00
|
|
|
m_EDA_CommonConfig->Read( wxT( "Language" ), &m_LanguageId,
|
|
|
|
wxLANGUAGE_DEFAULT );
|
|
|
|
|
|
|
|
bool succes = SetLanguage( TRUE );
|
|
|
|
if( !succes )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set locale option for separator used in float numbers */
|
|
|
|
SetLocaleTo_Default();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
2009-01-07 15:59:49 +00:00
|
|
|
PyHandler::GetInstance()->SetAppName( name );
|
2007-05-28 18:09:49 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* Init online help
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2008-12-29 11:26:15 +00:00
|
|
|
* @return none
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
void WinEDA_App::InitOnLineHelp()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
wxString fullfilename = FindKicadHelpPath();
|
2007-10-22 18:58:47 +00:00
|
|
|
|
2008-06-11 10:33:13 +00:00
|
|
|
#if defined ONLINE_HELP_FILES_FORMAT_IS_HTML
|
2009-01-07 15:59:49 +00:00
|
|
|
m_HelpFileName = fullfilename + wxT( ".html" );
|
|
|
|
fullfilename += wxT( "kicad.hhp" );
|
|
|
|
|
|
|
|
if( wxFileExists( fullfilename ) )
|
|
|
|
{
|
|
|
|
m_HtmlCtrl = new wxHtmlHelpController( wxHF_TOOLBAR | wxHF_CONTENTS |
|
|
|
|
wxHF_PRINT | wxHF_OPEN_FILES
|
|
|
|
/*| wxHF_SEARCH */ );
|
|
|
|
m_HtmlCtrl->UseConfig( m_EDA_CommonConfig );
|
|
|
|
m_HtmlCtrl->SetTitleFormat( wxT( "Kicad Help" ) );
|
|
|
|
m_HtmlCtrl->AddBook( fullfilename );
|
|
|
|
}
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2008-06-11 10:33:13 +00:00
|
|
|
#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
|
2009-01-07 15:59:49 +00:00
|
|
|
m_HtmlCtrl = NULL;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2008-06-11 10:33:13 +00:00
|
|
|
#else
|
2009-01-07 15:59:49 +00:00
|
|
|
#error Help files format not defined
|
2008-06-11 10:33:13 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* Find the path to the executable and store it in WinEDA_App::m_BinDir
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2008-12-29 11:26:15 +00:00
|
|
|
* @return TODO
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
bool WinEDA_App::SetBinDir()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-29 11:26:15 +00:00
|
|
|
/* Apple MacOSx */
|
2007-10-28 17:45:36 +00:00
|
|
|
#ifdef __APPLE__
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
/* Derive path from location of the app bundle */
|
|
|
|
CFBundleRef mainBundle = CFBundleGetMainBundle();
|
|
|
|
if( mainBundle == NULL )
|
|
|
|
return false;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
CFURLRef urlref = CFBundleCopyBundleURL( mainBundle );
|
|
|
|
if( urlref == NULL )
|
|
|
|
return false;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
CFStringRef str = CFURLCopyFileSystemPath( urlref, kCFURLPOSIXPathStyle );
|
|
|
|
if( str == NULL )
|
|
|
|
return false;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
char* native_str = NULL;
|
|
|
|
int len = CFStringGetMaximumSizeForEncoding( CFStringGetLength( str ),
|
|
|
|
kCFStringEncodingUTF8 ) + 1;
|
|
|
|
native_str = new char[len];
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
CFStringGetCString( str, native_str, len, kCFStringEncodingUTF8 );
|
|
|
|
m_BinDir = CONV_FROM_UTF8( native_str );
|
|
|
|
delete[] native_str;
|
2008-12-29 11:26:15 +00:00
|
|
|
|
|
|
|
/* Linux and Unix */
|
2009-02-03 20:33:34 +00:00
|
|
|
#elif defined(__UNIX__)
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
// Under Linux, if argv[0] doesn't the complete path to the executable,
|
|
|
|
// it's necessary to obtain it using "which <filename>".
|
|
|
|
FILE* ftmp;
|
|
|
|
|
|
|
|
char Line[1024];
|
|
|
|
char FileName[1024];
|
|
|
|
wxString str_arg0;
|
|
|
|
int ii;
|
|
|
|
|
|
|
|
FileName[0] = 0;
|
|
|
|
str_arg0 = argv[0];
|
|
|
|
if( strchr( (const char*) argv[0], '/' ) == NULL ) // no path
|
|
|
|
{
|
|
|
|
sprintf( FileName, "which %s > %s", CONV_TO_UTF8( str_arg0 ), TMP_FILE );
|
|
|
|
ii = system( FileName );
|
|
|
|
|
|
|
|
if( ( ftmp = fopen( TMP_FILE, "rt" ) ) != NULL )
|
|
|
|
{
|
|
|
|
fgets( Line, 1000, ftmp );
|
|
|
|
fclose( ftmp );
|
|
|
|
remove( TMP_FILE );
|
|
|
|
}
|
|
|
|
m_BinDir = CONV_FROM_UTF8( Line );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_BinDir = argv[0];
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#else
|
2009-01-07 15:59:49 +00:00
|
|
|
m_BinDir = argv[0];
|
2008-12-29 11:26:15 +00:00
|
|
|
#endif /* __UNIX__ */
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-09 20:17:06 +00:00
|
|
|
/* Use unix notation for paths. I am not sure this is a good idea,
|
|
|
|
* but it simplify compatibility between Windows and Unices
|
|
|
|
* However it is a potential problem in path handling under Windows
|
2009-04-18 14:14:40 +00:00
|
|
|
*/
|
2009-02-09 20:17:06 +00:00
|
|
|
m_BinDir.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
// Remove file name form command line:
|
2009-02-10 13:46:10 +00:00
|
|
|
while( m_BinDir.Last() != '/' && !m_BinDir.IsEmpty() )
|
2009-02-10 12:37:12 +00:00
|
|
|
m_BinDir.RemoveLast();
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
wxFileName pfn( wxT( "/posix/path/specification" ), wxT( "filename" ) );
|
|
|
|
wxFileName wfn( wxT( "\\windows\\path\\specification" ), wxT( "filename" ) );
|
|
|
|
wxLogDebug( wxT( "Posix path: " ) + pfn.GetFullPath() );
|
|
|
|
wxLogDebug( wxT( "Windows path: " ) + wfn.GetFullPath() );
|
2009-01-17 20:31:19 +00:00
|
|
|
wxLogDebug( wxT( "Executable path the Kicad way: " ) + m_BinDir );
|
|
|
|
wxLogDebug( wxT( "Executable path the wxWidgets way: " ) +
|
2009-04-18 14:14:40 +00:00
|
|
|
GetTraits()->GetStandardPaths().GetExecutablePath() );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
return TRUE;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 20:33:34 +00:00
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
/**
|
|
|
|
* Set search paths for libraries, modules, internationalization files, etc.
|
|
|
|
*/
|
|
|
|
void WinEDA_App::SetDefaultSearchPaths( void )
|
|
|
|
{
|
2009-02-03 20:33:34 +00:00
|
|
|
size_t i;
|
2009-02-09 20:17:06 +00:00
|
|
|
wxString path = m_BinDir;
|
2009-04-15 19:53:41 +00:00
|
|
|
wxPathList tmp;
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
m_searchPaths.Clear();
|
|
|
|
|
2009-02-09 20:17:06 +00:00
|
|
|
#ifdef __WINDOWS__
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* m_BinDir path is in unix notation.
|
2009-02-09 20:17:06 +00:00
|
|
|
* But wxFileName expect (to work fine) native notation
|
2009-04-05 20:49:15 +00:00
|
|
|
* specifically when using a path including a server, like
|
|
|
|
* \\myserver\local_path .
|
|
|
|
*/
|
2009-02-09 20:17:06 +00:00
|
|
|
path.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
wxFileName fn( path, wxEmptyString );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* User environment variable path is the first search path. Chances are
|
2009-01-29 14:26:20 +00:00
|
|
|
* if the user is savvy enough to set an environment variable they know
|
|
|
|
* what they are doing. */
|
|
|
|
if( ::wxGetEnv( wxT( "KICAD" ), NULL ) )
|
|
|
|
m_searchPaths.AddEnvList( wxT( "KICAD" ) );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
/* Add the user's home path. */
|
|
|
|
m_searchPaths.Add( GetTraits()->GetStandardPaths().GetUserDataDir() );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
|
|
|
/* Standard application data path if it is different from the binary
|
|
|
|
* path. */
|
|
|
|
if( fn.GetPath() != GetTraits()->GetStandardPaths().GetDataDir() )
|
2009-02-09 20:17:06 +00:00
|
|
|
{
|
2009-01-17 20:31:19 +00:00
|
|
|
m_searchPaths.Add( GetTraits()->GetStandardPaths().GetDataDir() );
|
2009-02-09 20:17:06 +00:00
|
|
|
}
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Up one level relative to binary path with "share" appended for Windows. */
|
2009-01-17 20:31:19 +00:00
|
|
|
fn.RemoveLastDir();
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.AppendDir( wxT( "share" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.AppendDir( wxT( "kicad" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
/* The normal OS program file install paths allow for binary to be
|
2009-04-18 14:14:40 +00:00
|
|
|
* installed in a different path from the library files. This is
|
|
|
|
* useful for development purposes so the library and documentation
|
|
|
|
* files do not need to be installed separately. If someone can
|
|
|
|
* figure out a way to implement this without #ifdef, please do. */
|
2009-04-15 19:53:41 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
tmp.AddEnvList( wxT( "PROGRAMFILES" ) );
|
|
|
|
#else
|
|
|
|
tmp.AddEnvList( wxT( "PATH" ) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for( i = 0; i < tmp.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
fn = wxFileName( tmp[i], wxEmptyString );
|
|
|
|
|
|
|
|
if( fn.GetPath().AfterLast( fn.GetPathSeparator() ) == wxT( "bin" ) )
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.AppendDir( wxT( "kicad" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.AppendDir( wxT( "share" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.AppendDir( wxT( "share" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
fn.AppendDir( wxT( "kicad" ) );
|
|
|
|
m_searchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Remove all non-existent paths from the list. */
|
2009-01-17 20:31:19 +00:00
|
|
|
for( i = 0; i < m_searchPaths.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
if( !wxFileName::IsDirReadable( m_searchPaths[i] ) )
|
|
|
|
{
|
2009-04-15 19:53:41 +00:00
|
|
|
wxLogDebug( wxT( "Removing <" ) + m_searchPaths[i] +
|
2009-04-18 14:14:40 +00:00
|
|
|
wxT( "> from search path list." ) );
|
2009-01-17 20:31:19 +00:00
|
|
|
m_searchPaths.RemoveAt( i );
|
|
|
|
i -= 1;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fn.Clear();
|
|
|
|
fn.SetPath( m_searchPaths[i] );
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
/* Add schematic library file path to search path list.
|
2009-04-18 14:14:40 +00:00
|
|
|
* we must add <kicad path>/library and <kicad path>/library/doc
|
|
|
|
*/
|
|
|
|
if( m_Id == APP_TYPE_EESCHEMA )
|
2009-04-06 18:54:57 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.AppendDir( wxT( "library" ) );
|
2009-04-12 14:39:54 +00:00
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
2009-04-15 19:53:41 +00:00
|
|
|
wxLogDebug( wxT( "Adding <%s> to search path list" ),
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.GetPath().c_str() );
|
2009-04-12 14:39:54 +00:00
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add schematic doc file path (library/doc)to search path list. */
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.AppendDir( wxT( "doc" ) );
|
2009-04-12 14:39:54 +00:00
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
2009-04-15 19:53:41 +00:00
|
|
|
wxLogDebug( wxT( "Adding <%s> to search path list" ),
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.GetPath().c_str() );
|
2009-04-12 14:39:54 +00:00
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir(); // point to <kicad path>
|
2009-04-07 15:54:40 +00:00
|
|
|
}
|
|
|
|
|
2009-04-12 14:39:54 +00:00
|
|
|
/* Add PCB library file path to search path list. */
|
2009-04-18 14:14:40 +00:00
|
|
|
if( ( m_Id == APP_TYPE_PCBNEW ) || ( m_Id == APP_TYPE_CVPCB ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-04-12 14:39:54 +00:00
|
|
|
fn.AppendDir( wxT( "modules" ) );
|
|
|
|
|
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "Adding <%s> to library search path list" ),
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.GetPath().c_str() );
|
2009-04-12 14:39:54 +00:00
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add 3D module library file path to search path list. */
|
|
|
|
fn.AppendDir( wxT( "packages3d" ) );
|
|
|
|
|
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
2009-04-15 19:53:41 +00:00
|
|
|
wxLogDebug( wxT( "Adding <%s> to search path list" ),
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.GetPath().c_str() );
|
2009-04-12 14:39:54 +00:00
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
2009-04-19 15:03:48 +00:00
|
|
|
fn.RemoveLastDir();
|
|
|
|
fn.RemoveLastDir(); // point to <kicad path>
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-04-19 15:03:48 +00:00
|
|
|
/* Add kicad template file path to search path list. */
|
|
|
|
fn.AppendDir( wxT( "template" ) );
|
|
|
|
|
|
|
|
if( fn.IsDirReadable() )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "Adding <%s> to search path list" ),
|
|
|
|
fn.GetPath().c_str() );
|
|
|
|
m_libSearchPaths.Add( fn.GetPath() );
|
|
|
|
}
|
|
|
|
fn.RemoveLastDir();
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-01-17 20:31:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* Get application settings
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2008-12-29 11:26:15 +00:00
|
|
|
* @return none
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
void WinEDA_App::GetSettings()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxASSERT( m_EDA_Config != NULL && m_EDA_CommonConfig != NULL );
|
|
|
|
|
2009-04-07 11:53:58 +00:00
|
|
|
wxString Line;
|
2009-01-07 15:59:49 +00:00
|
|
|
unsigned ii;
|
|
|
|
|
|
|
|
m_HelpSize.x = 500;
|
|
|
|
m_HelpSize.y = 400;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
m_LanguageId = m_EDA_CommonConfig->Read( wxT( "Language" ),
|
|
|
|
wxLANGUAGE_DEFAULT );
|
|
|
|
m_EditorName = m_EDA_CommonConfig->Read( wxT( "Editor" ) );
|
|
|
|
g_ConfigFileLocationChoice = m_EDA_CommonConfig->Read( HOTKEY_CFG_PATH_OPT,
|
|
|
|
0L );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
m_fileHistory.Load( *m_EDA_Config );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
/* Set default font sizes */
|
|
|
|
g_DialogFontPointSize = m_EDA_Config->Read( wxT( "DialogFontSize" ),
|
|
|
|
FONT_DEFAULT_SIZE );
|
|
|
|
g_FixedFontPointSize = m_EDA_Config->Read( wxT( "FixedFontSize" ),
|
|
|
|
FONT_DEFAULT_SIZE );
|
|
|
|
|
|
|
|
Line = m_EDA_Config->Read( wxT( "DialogFontType" ), wxEmptyString );
|
|
|
|
if( !Line.IsEmpty() )
|
|
|
|
g_DialogFont->SetFaceName( Line );
|
|
|
|
|
|
|
|
ii = m_EDA_Config->Read( wxT( "DialogFontStyle" ), wxFONTFAMILY_ROMAN );
|
|
|
|
g_DialogFont->SetStyle( ii );
|
|
|
|
ii = m_EDA_Config->Read( wxT( "DialogFontWeight" ), wxNORMAL );
|
|
|
|
g_DialogFont->SetWeight( ii );
|
|
|
|
g_DialogFont->SetPointSize( g_DialogFontPointSize );
|
|
|
|
|
|
|
|
g_FixedFont->SetPointSize( g_FixedFontPointSize );
|
|
|
|
|
|
|
|
m_EDA_Config->Read( wxT( "ShowPageLimits" ), &g_ShowPageLimits );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( m_EDA_Config->Read( wxT( "WorkingDir" ), &Line ) && wxDirExists( Line ) )
|
2009-01-07 15:59:49 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxSetWorkingDirectory( Line );
|
2009-01-07 15:59:49 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
m_EDA_Config->Read( wxT( "BgColor" ), &g_DrawBgColor );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* Save application settings
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2008-12-29 11:26:15 +00:00
|
|
|
* @return none
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
void WinEDA_App::SaveSettings()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxASSERT( m_EDA_Config != NULL );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
/* Sdt font settings */
|
2009-04-13 05:58:11 +00:00
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 2, 9, 0 )
|
2009-04-14 16:45:22 +00:00
|
|
|
#warning TODO: under wxWidgets 3.0, see how to replace the next lines
|
2009-04-13 05:58:11 +00:00
|
|
|
#else
|
2009-01-07 15:59:49 +00:00
|
|
|
/* Dialog font settings */
|
|
|
|
m_EDA_Config->Write( wxT( "DialogFontSize" ), g_DialogFontPointSize );
|
|
|
|
m_EDA_Config->Write( wxT( "DialogFontType" ), g_DialogFont->GetFaceName() );
|
|
|
|
m_EDA_Config->Write( wxT( "DialogFontStyle" ), g_DialogFont->GetStyle() );
|
|
|
|
m_EDA_Config->Write( wxT( "DialogFontWeight" ), g_DialogFont->GetWeight() );
|
|
|
|
|
|
|
|
/* Misc settings */
|
|
|
|
m_EDA_Config->Write( wxT( "FixedFontSize" ), g_FixedFontPointSize );
|
|
|
|
m_EDA_Config->Write( wxT( "ShowPageLimits" ), g_ShowPageLimits );
|
|
|
|
m_EDA_Config->Write( wxT( "WorkingDir" ), wxGetCwd() );
|
2009-04-13 05:58:11 +00:00
|
|
|
#endif // wxCHECK_VERSION
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
/* Save the file history list */
|
|
|
|
m_fileHistory.Save( *m_EDA_Config );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-22 18:58:47 +00:00
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* Set the dictionary file name for internationalization
|
2009-04-05 20:49:15 +00:00
|
|
|
* the files are in kicad/internat/xx or kicad/internat/xx_XX
|
|
|
|
* and are named kicad.mo
|
2008-12-29 11:26:15 +00:00
|
|
|
*
|
2009-04-05 20:49:15 +00:00
|
|
|
* @param first_time must be set to true the first time this funct is
|
|
|
|
* called, false otherwise
|
2009-01-18 10:15:10 +00:00
|
|
|
* @return true if the language can be set (i.e. if the locale is available)
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
bool WinEDA_App::SetLanguage( bool first_time )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-17 20:31:19 +00:00
|
|
|
bool retv = true;
|
|
|
|
|
2009-01-07 15:59:49 +00:00
|
|
|
// dictionary file name without extend (full name is kicad.mo)
|
|
|
|
wxString DictionaryName( wxT( "kicad" ) );
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
if( m_Locale )
|
2009-01-07 15:59:49 +00:00
|
|
|
delete m_Locale;
|
2009-01-29 14:26:20 +00:00
|
|
|
m_Locale = new wxLocale;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
if( !m_Locale->Init( m_LanguageId, wxLOCALE_CONV_ENCODING ) )
|
|
|
|
{
|
2009-01-17 20:31:19 +00:00
|
|
|
wxLogDebug( wxT( "Failed to initialize " ) +
|
|
|
|
wxLocale::GetLanguageInfo( m_LanguageId )->Description );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
m_LanguageId = wxLANGUAGE_DEFAULT;
|
2009-01-29 14:26:20 +00:00
|
|
|
delete m_Locale;
|
|
|
|
m_Locale = new wxLocale;
|
2009-01-07 15:59:49 +00:00
|
|
|
m_Locale->Init();
|
|
|
|
retv = false;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !first_time )
|
|
|
|
{
|
2009-01-17 20:31:19 +00:00
|
|
|
m_EDA_CommonConfig->Write( wxT( "Language" ), m_LanguageId );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-01-07 15:59:49 +00:00
|
|
|
|
|
|
|
if( !m_Locale->IsLoaded( DictionaryName ) )
|
|
|
|
m_Locale->AddCatalog( DictionaryName );
|
|
|
|
|
|
|
|
if( !retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
return m_Locale->IsOk();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
|
|
|
* Function SetLanguageIdentifier
|
|
|
|
*
|
|
|
|
* Set in .m_LanguageId member the wxWidgets language identifier Id from
|
|
|
|
* the kicad menu id (internal menu identifier)
|
|
|
|
*
|
|
|
|
* @param menu_id = the kicad menuitem id (returned by Menu Event, when
|
|
|
|
* clicking on a menu item)
|
2008-12-29 11:52:15 +00:00
|
|
|
* @return none
|
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
void WinEDA_App::SetLanguageIdentifier( int menu_id )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
unsigned int ii;
|
|
|
|
|
|
|
|
wxLogDebug( wxT( "Select language ID %d from %d possible languages." ),
|
|
|
|
menu_id, LANGUAGE_DESCR_COUNT );
|
|
|
|
|
|
|
|
for( ii = 0; ii < LANGUAGE_DESCR_COUNT; ii++ )
|
|
|
|
{
|
|
|
|
if( menu_id == s_Language_List[ii].m_KI_Lang_Identifier )
|
|
|
|
{
|
|
|
|
m_LanguageId = s_Language_List[ii].m_WX_Lang_Identifier;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
void WinEDA_App::SetLanguagePath( void )
|
|
|
|
{
|
2009-02-03 20:33:34 +00:00
|
|
|
size_t i;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
/* Add defined search paths to locale paths */
|
|
|
|
if( !m_searchPaths.IsEmpty() )
|
|
|
|
{
|
|
|
|
for( i = 0; i < m_searchPaths.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
wxFileName fn( m_searchPaths[i], wxEmptyString );
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-02-07 20:11:09 +00:00
|
|
|
// Append path for Windows and unix kicad pack install
|
2009-01-29 14:26:20 +00:00
|
|
|
fn.AppendDir( wxT( "share" ) );
|
2009-02-07 20:11:09 +00:00
|
|
|
fn.AppendDir( wxT( "internat" ) );
|
|
|
|
if( fn.DirExists() )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "Adding locale lookup path: " ) +
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.GetPath() );
|
2009-02-07 20:11:09 +00:00
|
|
|
wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
|
|
|
|
}
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
// Append path for unix standard install
|
2009-02-09 20:17:06 +00:00
|
|
|
fn.RemoveLastDir();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
// Append path for unix standard install
|
2009-01-29 14:26:20 +00:00
|
|
|
fn.AppendDir( wxT( "kicad" ) );
|
|
|
|
fn.AppendDir( wxT( "internat" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
if( fn.DirExists() )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "Adding locale lookup path: " ) +
|
2009-04-18 14:14:40 +00:00
|
|
|
fn.GetPath() );
|
2009-01-29 14:26:20 +00:00
|
|
|
wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-18 10:15:10 +00:00
|
|
|
/** Function AddMenuLanguageList
|
|
|
|
* Create menu list for language choice, and add it as submenu to a main menu
|
2009-04-05 20:49:15 +00:00
|
|
|
* @param MasterMenu : The main menu. The sub menu list will be accessible
|
|
|
|
* from the menu item with id ID_LANGUAGE_CHOICE
|
2009-01-18 10:15:10 +00:00
|
|
|
* @return none
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-18 10:15:10 +00:00
|
|
|
void WinEDA_App::AddMenuLanguageList( wxMenu* MasterMenu )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-18 10:15:10 +00:00
|
|
|
wxMenu* menu = NULL;
|
2009-01-07 15:59:49 +00:00
|
|
|
wxMenuItem* item;
|
|
|
|
unsigned int ii;
|
|
|
|
|
2009-01-17 20:31:19 +00:00
|
|
|
item = MasterMenu->FindItem( ID_LANGUAGE_CHOICE );
|
|
|
|
|
2009-01-18 10:15:10 +00:00
|
|
|
if( item ) // This menu exists, do nothing
|
|
|
|
return;
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2009-01-18 10:15:10 +00:00
|
|
|
menu = new wxMenu;
|
|
|
|
for( ii = 0; ii < LANGUAGE_DESCR_COUNT; ii++ )
|
|
|
|
{
|
2009-04-13 05:58:11 +00:00
|
|
|
wxString label;
|
2009-04-18 14:14:40 +00:00
|
|
|
if( s_Language_List[ii].m_DoNotTranslate )
|
2009-04-13 05:58:11 +00:00
|
|
|
label = s_Language_List[ii].m_Lang_Label;
|
|
|
|
else
|
|
|
|
label = wxGetTranslation( s_Language_List[ii].m_Lang_Label );
|
2009-01-07 15:59:49 +00:00
|
|
|
|
2009-01-18 10:15:10 +00:00
|
|
|
item = new wxMenuItem( menu,
|
|
|
|
s_Language_List[ii].m_KI_Lang_Identifier,
|
|
|
|
label, wxEmptyString, wxITEM_CHECK );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2009-01-18 10:15:10 +00:00
|
|
|
SETBITMAPS( s_Language_List[ii].m_Lang_Icon );
|
|
|
|
menu->Append( item );
|
2009-01-07 15:59:49 +00:00
|
|
|
}
|
|
|
|
|
2009-01-18 10:15:10 +00:00
|
|
|
ADD_MENUITEM_WITH_HELP_AND_SUBMENU( MasterMenu, menu,
|
|
|
|
ID_LANGUAGE_CHOICE,
|
|
|
|
_( "Language" ),
|
|
|
|
_( "Select application language (only for testing!)" ),
|
|
|
|
language_xpm );
|
|
|
|
|
|
|
|
// Set Check mark on current selected language
|
2009-01-07 15:59:49 +00:00
|
|
|
for( ii = 0; ii < LANGUAGE_DESCR_COUNT; ii++ )
|
|
|
|
{
|
|
|
|
if( m_LanguageId == s_Language_List[ii].m_WX_Lang_Identifier )
|
2009-01-17 20:31:19 +00:00
|
|
|
menu->Check( s_Language_List[ii].m_KI_Lang_Identifier, true );
|
2009-01-07 15:59:49 +00:00
|
|
|
else
|
2009-01-17 20:31:19 +00:00
|
|
|
menu->Check( s_Language_List[ii].m_KI_Lang_Identifier, false );
|
2009-01-07 15:59:49 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
/**
|
|
|
|
* Look in search paths for requested file.
|
|
|
|
*
|
|
|
|
*/
|
2009-02-03 20:33:34 +00:00
|
|
|
wxString WinEDA_App::FindFileInSearchPaths( const wxString& filename,
|
2009-01-29 14:26:20 +00:00
|
|
|
const wxArrayString* subdirs )
|
|
|
|
{
|
|
|
|
size_t i, j;
|
|
|
|
wxFileName fn;
|
|
|
|
wxPathList paths;
|
|
|
|
|
|
|
|
for( i = 0; i < m_searchPaths.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
fn = wxFileName( m_searchPaths[i], wxEmptyString );
|
|
|
|
|
|
|
|
if( subdirs )
|
|
|
|
{
|
|
|
|
for( j = 0; j < subdirs->GetCount(); j++ )
|
|
|
|
fn.AppendDir( subdirs->Item( j ) );
|
|
|
|
}
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
if( fn.DirExists() )
|
|
|
|
{
|
|
|
|
wxLogDebug( _T( "Adding <" ) + fn.GetPath() + _T( "> to " ) +
|
2009-04-18 14:14:40 +00:00
|
|
|
_T( "file \"" ) + filename + _T( "\" search path." ) );
|
2009-01-29 14:26:20 +00:00
|
|
|
paths.Add( fn.GetPath() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return paths.FindValidPath( filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the help file path.
|
|
|
|
*
|
|
|
|
* Return the Kicad help file with path. The base paths defined in
|
|
|
|
* m_searchPaths are tested for a valid file. The path returned can
|
|
|
|
* be relative depending on the paths added to m_searchPaths. See the
|
|
|
|
* documentation for wxPathList for more information. If the help file
|
|
|
|
* for the current locale is not found, an attempt to find the English
|
|
|
|
* version of the help file is made. wxEmptyString is returned if the
|
|
|
|
* help file is not found.
|
2009-02-03 20:33:34 +00:00
|
|
|
* Help file is searched in directories in this order:
|
|
|
|
* help/<canonical name> like help/en_GB
|
|
|
|
* help/<short name> like help/en
|
|
|
|
* help/en
|
2009-01-29 14:26:20 +00:00
|
|
|
*/
|
|
|
|
wxString WinEDA_App::GetHelpFile( void )
|
|
|
|
{
|
|
|
|
wxString fn;
|
2009-02-07 20:11:09 +00:00
|
|
|
wxArrayString subdirs, altsubdirs;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* FIXME: This is not the ideal way to handle this. Unfortunately, the
|
2009-01-29 14:26:20 +00:00
|
|
|
* CMake install paths seem to be a moving target so this crude
|
|
|
|
* hack solve the problem of install path differences between
|
|
|
|
* Windows and non-Windows platforms. */
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-02-07 20:11:09 +00:00
|
|
|
// Partially fixed, but must be enhanced
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Create subdir tree for "standard" linux distributions, when kicad comes
|
|
|
|
// from a distribution files are in /usr/share/doc/kicad/help and binaries
|
|
|
|
// in /usr/bin or /usr/local/bin
|
2009-01-29 14:26:20 +00:00
|
|
|
subdirs.Add( wxT( "share" ) );
|
|
|
|
subdirs.Add( _T( "doc" ) );
|
|
|
|
subdirs.Add( wxT( "kicad" ) );
|
|
|
|
subdirs.Add( _T( "help" ) );
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Create subdir tree for linux and Windows kicad pack.
|
|
|
|
// Note the pack form under linux is also useful if a user wants to
|
|
|
|
// install kicad to a server because there is only one path to mount
|
|
|
|
// or export (something like /usr/local/kicad).
|
2009-02-07 20:11:09 +00:00
|
|
|
// files are in <install dir>/kicad/doc/help
|
|
|
|
// (often /usr/local/kicad/kicad/doc/help)
|
2009-04-05 20:49:15 +00:00
|
|
|
// <install dir>/kicad/ is retrieved from m_BinDir
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.Add( _T( "doc" ) );
|
|
|
|
altsubdirs.Add( _T( "help" ) );
|
2009-02-09 20:17:06 +00:00
|
|
|
|
2009-02-03 20:33:34 +00:00
|
|
|
|
|
|
|
/* Search for a help file.
|
|
|
|
* we *must* find a help file.
|
|
|
|
* so help is searched in directories in this order:
|
|
|
|
* help/<canonical name> like help/en_GB
|
|
|
|
* help/<short name> like help/en
|
|
|
|
* help/en
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Step 1 : Try to find help file in help/<canonical name>
|
2009-01-29 14:26:20 +00:00
|
|
|
subdirs.Add( m_Locale->GetCanonicalName() );
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.Add( m_Locale->GetCanonicalName() );
|
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs );
|
|
|
|
if( !fn )
|
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &subdirs );
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-02-03 20:33:34 +00:00
|
|
|
// Step 2 : if not found Try to find help file in help/<short name>
|
|
|
|
if( !fn )
|
|
|
|
{
|
|
|
|
subdirs.RemoveAt( subdirs.GetCount() - 1 );
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 );
|
2009-04-18 14:14:40 +00:00
|
|
|
|
|
|
|
// wxLocale::GetName() does not return always the short name
|
2009-04-05 20:49:15 +00:00
|
|
|
subdirs.Add( m_Locale->GetName().BeforeLast( '_' ) );
|
|
|
|
altsubdirs.Add( m_Locale->GetName().BeforeLast( '_' ) );
|
2009-02-07 20:11:09 +00:00
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs );
|
2009-04-18 14:14:40 +00:00
|
|
|
if( !fn )
|
2009-02-07 20:11:09 +00:00
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &subdirs );
|
2009-02-03 20:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Step 3 : if not found Try to find help file in help/en
|
|
|
|
if( !fn )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
|
|
|
subdirs.RemoveAt( subdirs.GetCount() - 1 );
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 );
|
2009-01-29 14:26:20 +00:00
|
|
|
subdirs.Add( _T( "en" ) );
|
2009-02-07 20:11:09 +00:00
|
|
|
altsubdirs.Add( _T( "en" ) );
|
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs );
|
2009-04-18 14:14:40 +00:00
|
|
|
if( !fn )
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = FindFileInSearchPaths( m_HelpFileName, &subdirs );
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2009-02-03 20:33:34 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
wxString WinEDA_App::GetLibraryFile( const wxString& filename )
|
|
|
|
{
|
|
|
|
wxArrayString subdirs;
|
|
|
|
|
|
|
|
subdirs.Add( wxT( "share" ) );
|
|
|
|
#ifndef __WXMSW__
|
2009-02-03 20:33:34 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
/* Up on level relative to binary path with "share/kicad" appended for
|
|
|
|
* all other platforms. */
|
|
|
|
subdirs.Add( wxT( "kicad" ) );
|
|
|
|
#endif
|
|
|
|
return FindFileInSearchPaths( filename, &subdirs );
|
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
/** ReturnLastVisitedLibraryPath
|
|
|
|
* Returns the last visited library directory, or (if void) the first
|
|
|
|
* path in lib path list ( but not the CWD )
|
|
|
|
* @param aSubPathToSearch = Prefered sub path to search in path list (defualt = empty string)
|
|
|
|
*/
|
2009-04-18 14:14:40 +00:00
|
|
|
wxString WinEDA_App::ReturnLastVisitedLibraryPath( const wxString& aSubPathToSearch )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
if( !m_LastVisitedLibPath.IsEmpty() )
|
2009-04-15 19:53:41 +00:00
|
|
|
return m_LastVisitedLibPath;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
wxString path;
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
/* Initialize default path to the main default lib path
|
|
|
|
* this is the second path in list (the first is the project path)
|
|
|
|
*/
|
2009-04-15 19:53:41 +00:00
|
|
|
unsigned pcount = m_libSearchPaths.GetCount();
|
2009-04-18 14:14:40 +00:00
|
|
|
if( pcount )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
|
|
|
unsigned ipath = 0;
|
2009-04-18 14:14:40 +00:00
|
|
|
if( m_libSearchPaths[0] == wxGetCwd() )
|
2009-04-14 16:45:22 +00:00
|
|
|
ipath = 1;
|
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
// First choice of path:
|
2009-04-18 14:14:40 +00:00
|
|
|
if( ipath < pcount )
|
2009-04-15 19:53:41 +00:00
|
|
|
path = m_libSearchPaths[ipath];
|
2009-04-14 16:45:22 +00:00
|
|
|
|
|
|
|
// Search a sub path matching aSubPathToSearch
|
2009-04-18 14:14:40 +00:00
|
|
|
if( !aSubPathToSearch.IsEmpty() )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
for( ; ipath < pcount; ipath++ )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
if( m_libSearchPaths[ipath].Contains( aSubPathToSearch ) )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-15 19:53:41 +00:00
|
|
|
path = m_libSearchPaths[ipath];
|
2009-04-14 16:45:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
if( path.IsEmpty() )
|
2009-04-14 16:45:22 +00:00
|
|
|
path = wxGetCwd();
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
|
|
|
void WinEDA_App::SaveLastVisitedLibraryPath( const wxString& aPath )
|
2009-04-14 16:45:22 +00:00
|
|
|
{
|
2009-04-15 19:53:41 +00:00
|
|
|
m_LastVisitedLibPath = aPath;
|
2009-04-14 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-04-15 15:53:21 +00:00
|
|
|
/** ReturnFilenameWithRelativePathInLibPath
|
|
|
|
* @return a short filename (with extension) with only a relative path if this filename
|
|
|
|
* can be found in library paths
|
|
|
|
* @param aFullFilename = filename with path and extension.
|
|
|
|
*/
|
2009-04-18 14:14:40 +00:00
|
|
|
wxString WinEDA_App::ReturnFilenameWithRelativePathInLibPath( const wxString& aFullFilename )
|
2009-04-15 15:53:21 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
/* If the library path is already in the library search paths
|
2009-04-15 15:53:21 +00:00
|
|
|
* list, just add the library name to the list. Otherwise, add
|
|
|
|
* the library name with the full or relative path.
|
|
|
|
* the relative path, when possible is preferable,
|
|
|
|
* because it preserve use of default libraries paths, when the path is a sub path of these default paths
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
wxFileName fn = aFullFilename;
|
2009-04-18 14:14:40 +00:00
|
|
|
wxString filename = aFullFilename;
|
|
|
|
int pathlen = -1; // path len, used to find the better subpath within defualts paths
|
|
|
|
|
|
|
|
if( m_libSearchPaths.Index( fn.GetPath() ) != wxNOT_FOUND ) // Ok, trivial case
|
2009-04-15 15:53:21 +00:00
|
|
|
filename = fn.GetName();
|
|
|
|
else // not in the default, : see if this file is in a subpath:
|
|
|
|
{
|
|
|
|
filename = fn.GetPathWithSep() + fn.GetFullName();
|
2009-04-15 19:53:41 +00:00
|
|
|
for( unsigned kk = 0; kk < m_libSearchPaths.GetCount(); kk++ )
|
2009-04-15 15:53:21 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
if( fn.MakeRelativeTo( m_libSearchPaths[kk] ) )
|
2009-04-15 15:53:21 +00:00
|
|
|
{
|
|
|
|
if( pathlen < 0 // a subpath is found
|
|
|
|
|| pathlen > (int) fn.GetPath().Len() ) // a better subpath if found
|
|
|
|
{
|
|
|
|
filename = fn.GetPathWithSep() + fn.GetFullName();
|
|
|
|
pathlen = fn.GetPath().Len();
|
|
|
|
}
|
|
|
|
fn = aFullFilename; //Try to find a better subpath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
/** FindLibraryPath
|
2009-04-08 18:06:22 +00:00
|
|
|
* Kicad saves user defined library files that are not in the standard
|
|
|
|
* library search path list with the full file path. Calling the library
|
|
|
|
* search path list with a user library file will fail. This helper method
|
|
|
|
* solves that problem.
|
2009-04-14 16:45:22 +00:00
|
|
|
* @param fileName
|
|
|
|
* @return a wxEmptyString if library file is not found.
|
2009-04-08 18:06:22 +00:00
|
|
|
*/
|
2009-04-14 16:45:22 +00:00
|
|
|
wxString WinEDA_App::FindLibraryPath( const wxString& aFileName )
|
2009-04-08 18:06:22 +00:00
|
|
|
{
|
2009-04-14 16:45:22 +00:00
|
|
|
if( wxFileName::FileExists( aFileName ) )
|
|
|
|
return aFileName;
|
2009-04-08 18:06:22 +00:00
|
|
|
else
|
2009-04-14 16:45:22 +00:00
|
|
|
return m_libSearchPaths.FindValidPath( aFileName );
|
2009-04-09 18:39:39 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
/** Function RemoveLibraryPath
|
2009-04-18 14:14:40 +00:00
|
|
|
* Removes the given path(s) from the library path list
|
|
|
|
* @param aPaths = path or path list to remove. paths must be separated by ";"
|
2009-04-14 16:45:22 +00:00
|
|
|
*/
|
2009-04-18 14:14:40 +00:00
|
|
|
void WinEDA_App::RemoveLibraryPath( const wxString& aPaths )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
wxStringTokenizer Token( aPaths, wxT( ";\n\r" ) );
|
|
|
|
|
|
|
|
while( Token.HasMoreTokens() )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
wxString path = Token.GetNextToken();
|
|
|
|
if( m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_libSearchPaths.Remove( path );
|
|
|
|
}
|
2009-04-09 18:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 14:14:40 +00:00
|
|
|
|
|
|
|
/** Function InsertLibraryPath
|
|
|
|
* insert path(s) int lib paths list.
|
|
|
|
* @param aPaths = path or path list to add. paths must be separated by ";"
|
|
|
|
* @param aIndex = insertion point
|
|
|
|
*/
|
|
|
|
void WinEDA_App::InsertLibraryPath( const wxString& aPaths, size_t aIndex )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
wxStringTokenizer Token( aPaths, wxT( ";\n\r" ) );
|
|
|
|
|
|
|
|
while( Token.HasMoreTokens() )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
wxString path = Token.GetNextToken();
|
|
|
|
if( wxFileName::DirExists( path )
|
|
|
|
&& m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) == wxNOT_FOUND )
|
2009-04-09 18:39:39 +00:00
|
|
|
{
|
2009-04-18 14:14:40 +00:00
|
|
|
if( aIndex >= m_libSearchPaths.GetCount() )
|
|
|
|
{
|
|
|
|
m_libSearchPaths.Add( path );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_libSearchPaths.Insert( path, aIndex );
|
|
|
|
}
|
|
|
|
aIndex++;
|
2009-04-09 18:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-08 18:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-29 11:52:15 +00:00
|
|
|
/**
|
2009-04-05 20:49:15 +00:00
|
|
|
* Run Python scripts
|
|
|
|
*
|
|
|
|
* @return The default OnRun() value (exit codes not used in kicad, so value
|
|
|
|
* has no special meaning)
|
2008-12-29 11:52:15 +00:00
|
|
|
*/
|
2009-01-07 15:59:49 +00:00
|
|
|
int WinEDA_App::OnRun()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-01-07 15:59:49 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
|
|
|
PyHandler::GetInstance()->RunScripts();
|
|
|
|
#endif
|
|
|
|
return wxApp::OnRun();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|