diff --git a/common/projet_config.cpp b/common/projet_config.cpp index e4a5dc4d0f..99ddc953ed 100644 --- a/common/projet_config.cpp +++ b/common/projet_config.cpp @@ -696,6 +696,50 @@ void PARAM_CFG_WXSTRING::SaveParam( wxConfigBase* aConfig ) } + +PARAM_CFG_FILENAME::PARAM_CFG_FILENAME( const wxChar* ident, + wxString* ptparam, + const wxChar* group ) : + PARAM_CFG_BASE( ident, PARAM_FILENAME, group ) +{ + m_Pt_param = ptparam; +} + + +/** ReadParam + * read the value of parameter this stored in aConfig + * @param aConfig = the wxConfigBase that store the parameter + */ +void PARAM_CFG_FILENAME::ReadParam( wxConfigBase* aConfig ) +{ + if( m_Pt_param == NULL || aConfig == NULL ) + return; + wxString prm = aConfig->Read( m_Ident ); + // filesnames are stored using Unix notation + // under Window we must use \ instead of / + // mainly if there is a server name in path (something like \\server\kicad) +#ifdef __WINDOWS__ + prm.Replace(wxT("/"), wxT("\\")); +#endif + *m_Pt_param = prm; +} + + +/** SaveParam + * save the value of parameter this stored in aConfig + * @param aConfig = the wxConfigBase that can store the parameter + */ +void PARAM_CFG_FILENAME::SaveParam( wxConfigBase* aConfig ) +{ + if( m_Pt_param == NULL || aConfig == NULL ) + return; + wxString prm = *m_Pt_param; + // filenames are stored using Unix notation + prm.Replace(wxT("\\"), wxT("/") ); + aConfig->Write( m_Ident, prm ); +} + + PARAM_CFG_LIBNAME_LIST::PARAM_CFG_LIBNAME_LIST( const wxChar* ident, wxArrayString* ptparam, const wxChar* group ) : @@ -725,6 +769,12 @@ void PARAM_CFG_LIBNAME_LIST::ReadParam( wxConfigBase* aConfig ) libname = aConfig->Read( id_lib, wxT( "" ) ); if( libname.IsEmpty() ) break; + // filesnames are stored using Unix notation + // under Window we must use \ instead of / + // mainly if there is a server name in path (something like \\server\kicad) +#ifdef __WINDOWS__ + libname.Replace(wxT("/"), wxT("\\")); +#endif libname_list->Add( libname ); } } @@ -742,12 +792,16 @@ void PARAM_CFG_LIBNAME_LIST::SaveParam( wxConfigBase* aConfig ) unsigned indexlib = 0; wxString configkey; + wxString libname; for( ; indexlib < libname_list->GetCount(); indexlib++ ) { configkey = m_Ident; // We use indexlib+1 because first lib name is LibName1 configkey << (indexlib + 1); - aConfig->Write( configkey, libname_list->Item( indexlib ) ); + libname = libname_list->Item( indexlib ); + // filenames are stored using Unix notation + libname.Replace(wxT("\\"), wxT("/") ); + aConfig->Write( configkey, libname ); } } diff --git a/cvpcb/cfg.cpp b/cvpcb/cfg.cpp index e4ced33120..ceac7a9005 100644 --- a/cvpcb/cfg.cpp +++ b/cvpcb/cfg.cpp @@ -40,7 +40,7 @@ PARAM_CFG_ARRAY& CVPCB_MAINFRAME::GetProjectFileParameters( void ) GROUPEQU ) ); m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "NetIExt" ), &m_NetlistFileExtension ) ); - m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "LibDir" ), + m_projectFileParams.push_back( new PARAM_CFG_FILENAME( wxT( "LibDir" ), &m_UserLibraryPath, GROUPLIB ) ); diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index c2fa1b105d..8f9f2a55e6 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -1,6 +1,6 @@ -/******************/ -/** eeconfig.cpp **/ -/******************/ +/** + * @file eeschema_config.cpp + */ #include "fctsys.h" #include "appl_wxstruct.h" @@ -265,7 +265,7 @@ PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetProjectFileParameters( void ) if( !m_projectFileParams.empty() ) return m_projectFileParams; - m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "LibDir" ), + m_projectFileParams.push_back( new PARAM_CFG_FILENAME( wxT( "LibDir" ), &m_UserLibraryPath ) ); m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ), &m_ComponentLibFiles, diff --git a/include/param_config.h b/include/param_config.h index 8457cdfb4f..7a64c4058d 100644 --- a/include/param_config.h +++ b/include/param_config.h @@ -20,6 +20,7 @@ enum paramcfg_id PARAM_BOOL, PARAM_LIBNAME_LIST, PARAM_WXSTRING, + PARAM_FILENAME, PARAM_COMMAND_ERASE, PARAM_FIELDNAME_LIST }; @@ -174,6 +175,24 @@ public: virtual void SaveParam( wxConfigBase* aConfig ); }; +/** + * Configuration parameter - PARAM_CFG_FILENAME Class + * Same as PARAM_CFG_WXSTRING, but stores "\" as "/". + * and replace "/" by "\" under Windows. + * Used to store paths and filenames in config files + */ +class PARAM_CFG_FILENAME : public PARAM_CFG_BASE +{ +public: + wxString* m_Pt_param; ///< Pointer to the parameter value + +public: + PARAM_CFG_FILENAME( const wxChar* ident, wxString* ptparam, const wxChar* group = NULL ); + virtual void ReadParam( wxConfigBase* aConfig ); + virtual void SaveParam( wxConfigBase* aConfig ); +}; + + class PARAM_CFG_LIBNAME_LIST : public PARAM_CFG_BASE { diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index 02b9542dca..38f9309348 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -202,7 +202,7 @@ PARAM_CFG_ARRAY& WinEDA_PcbFrame::GetProjectFileParameters() if( !m_projectFileParams.empty() ) return m_projectFileParams; - m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "LibDir" ),&g_UserLibDirBuffer, + m_projectFileParams.push_back( new PARAM_CFG_FILENAME( wxT( "LibDir" ),&g_UserLibDirBuffer, GROUPLIB ) ); m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ), &g_LibName_List, GROUPLIB ) );