From cd341cc3019da432bfd24d2e6a812953e0aa9e99 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 2 May 2014 19:56:24 +0200 Subject: [PATCH] Eeschema: fix unwanted creation of noname.pro (or other useless config file), when opening eeschema. Fix also an issue when saving the config (from save config menu) which saved the config file in an unknow folder. --- common/project.cpp | 22 ++++++++++++++-------- eeschema/eeschema.cpp | 1 - eeschema/eeschema_config.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/common/project.cpp b/common/project.cpp index df43e60a5e..df31c81c1b 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -60,9 +60,9 @@ void PROJECT::SetProjectFullName( const wxString& aFullPathAndName ) wxASSERT( m_project_name.GetName() == NAMELESS_PROJECT || m_project_name.IsAbsolute() ); #if 0 - wxASSERT( m_project_name.GetExt() == wxT( ".pro" ) ) + wxASSERT( m_project_name.GetExt() == ProjectFileExtension ) #else - m_project_name.SetExt( wxT( ".pro" ) ); + m_project_name.SetExt( ProjectFileExtension ); #endif // until multiple projects are in play, set an environment variable for the @@ -269,19 +269,21 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString& // No suitable pro file was found, either does not exist, or is too old. // Use the template kicad.pro file. Find it by using caller's SEARCH_STACK. - - wxString kicad_pro_template = aSList.FindValidPath( wxT( "kicad.pro" ) ); + wxString templateFile = wxT( "kicad." ) + ProjectFileExtension; + wxString kicad_pro_template = aSList.FindValidPath( templateFile ); if( !kicad_pro_template ) { - wxLogDebug( wxT( "Template file not found using search paths." ) ); + wxLogDebug( wxT( "Template file <%s> not found using search paths." ), + GetChars( templateFile ) ); wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(), wxT( "kicad" ), ProjectFileExtension ); if( !templ.IsFileReadable() ) { - wxString msg = wxString::Format( _( "Unable to find kicad.pro template file." ) ); + wxString msg = wxString::Format( _( "Unable to find %s template config file." ), + GetChars( templateFile ) ); DisplayError( NULL, msg ); @@ -291,8 +293,12 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString& kicad_pro_template = templ.GetFullPath(); } - // copy the template to cur_pro_fn, and open it at that destination. - wxCopyFile( kicad_pro_template, cur_pro_fn ); + // The project config file is not found (happens for new projects, + // or if the schematic editor is run outside an existing project + // In this case the default template (kicad.pro) is used + cur_pro_fn = kicad_pro_template; + wxLogDebug( wxT( "Use template file '%s' as project file." ), GetChars( cur_pro_fn ) ); + cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString ); cfg->DontCreateOnDemand(); diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index fafcd90ac5..c5e1432036 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -40,7 +40,6 @@ #include #include -//#include #include #include #include diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index ee091ae82c..caa3b2782b 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -139,7 +139,7 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) switch( id ) { case ID_CONFIG_SAVE: - schFrame->SaveProjectSettings( false ); + schFrame->SaveProjectSettings( true ); break; case ID_CONFIG_READ: @@ -205,7 +205,7 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event ) switch( id ) { case ID_CONFIG_SAVE: - SaveProjectSettings( false ); + SaveProjectSettings( true ); break; case ID_CONFIG_READ: @@ -456,8 +456,8 @@ void SCH_EDIT_FRAME::SaveProjectSettings( bool aAskForSave ) if( aAskForSave ) { wxFileDialog dlg( this, _( "Save Project File" ), - fn.GetPath(), fn.GetFullName(), - ProjectFileWildcard, wxFD_SAVE | wxFD_CHANGE_DIR ); + fn.GetPath(), fn.GetFullPath(), + ProjectFileWildcard, wxFD_SAVE ); if( dlg.ShowModal() == wxID_CANCEL ) return;