Commit 5688a872 authored by jean-pierre charras's avatar jean-pierre charras

Eeschema: fix unwanted creation of noname.pro (or other useless config file),...

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.
parent 32c67654
...@@ -60,9 +60,9 @@ void PROJECT::SetProjectFullName( const wxString& aFullPathAndName ) ...@@ -60,9 +60,9 @@ void PROJECT::SetProjectFullName( const wxString& aFullPathAndName )
wxASSERT( m_project_name.GetName() == NAMELESS_PROJECT || m_project_name.IsAbsolute() ); wxASSERT( m_project_name.GetName() == NAMELESS_PROJECT || m_project_name.IsAbsolute() );
#if 0 #if 0
wxASSERT( m_project_name.GetExt() == wxT( ".pro" ) ) wxASSERT( m_project_name.GetExt() == ProjectFileExtension )
#else #else
m_project_name.SetExt( wxT( ".pro" ) ); m_project_name.SetExt( ProjectFileExtension );
#endif #endif
// until multiple projects are in play, set an environment variable for the // 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& ...@@ -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. // 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. // Use the template kicad.pro file. Find it by using caller's SEARCH_STACK.
wxString templateFile = wxT( "kicad." ) + ProjectFileExtension;
wxString kicad_pro_template = aSList.FindValidPath( wxT( "kicad.pro" ) ); wxString kicad_pro_template = aSList.FindValidPath( templateFile );
if( !kicad_pro_template ) if( !kicad_pro_template )
{ {
wxLogDebug( wxT( "Template file <kicad.pro> not found using search paths." ) ); wxLogDebug( wxT( "Template file <%s> not found using search paths." ),
GetChars( templateFile ) );
wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(), wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
wxT( "kicad" ), ProjectFileExtension ); wxT( "kicad" ), ProjectFileExtension );
if( !templ.IsFileReadable() ) 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 ); DisplayError( NULL, msg );
...@@ -291,8 +293,12 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString& ...@@ -291,8 +293,12 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString&
kicad_pro_template = templ.GetFullPath(); kicad_pro_template = templ.GetFullPath();
} }
// copy the template to cur_pro_fn, and open it at that destination. // The project config file is not found (happens for new projects,
wxCopyFile( kicad_pro_template, cur_pro_fn ); // 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 = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
cfg->DontCreateOnDemand(); cfg->DontCreateOnDemand();
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include <general.h> #include <general.h>
#include <class_libentry.h> #include <class_libentry.h>
//#include <sch_junction.h>
#include <hotkeys.h> #include <hotkeys.h>
#include <dialogs/dialog_color_config.h> #include <dialogs/dialog_color_config.h>
#include <transform.h> #include <transform.h>
......
...@@ -139,7 +139,7 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) ...@@ -139,7 +139,7 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
switch( id ) switch( id )
{ {
case ID_CONFIG_SAVE: case ID_CONFIG_SAVE:
schFrame->SaveProjectSettings( false ); schFrame->SaveProjectSettings( true );
break; break;
case ID_CONFIG_READ: case ID_CONFIG_READ:
...@@ -205,7 +205,7 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event ) ...@@ -205,7 +205,7 @@ void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event )
switch( id ) switch( id )
{ {
case ID_CONFIG_SAVE: case ID_CONFIG_SAVE:
SaveProjectSettings( false ); SaveProjectSettings( true );
break; break;
case ID_CONFIG_READ: case ID_CONFIG_READ:
...@@ -456,8 +456,8 @@ void SCH_EDIT_FRAME::SaveProjectSettings( bool aAskForSave ) ...@@ -456,8 +456,8 @@ void SCH_EDIT_FRAME::SaveProjectSettings( bool aAskForSave )
if( aAskForSave ) if( aAskForSave )
{ {
wxFileDialog dlg( this, _( "Save Project File" ), wxFileDialog dlg( this, _( "Save Project File" ),
fn.GetPath(), fn.GetFullName(), fn.GetPath(), fn.GetFullPath(),
ProjectFileWildcard, wxFD_SAVE | wxFD_CHANGE_DIR ); ProjectFileWildcard, wxFD_SAVE );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return; return;
......
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