Fix missing project file when creating a new project.

Fixes lp:1714522

https://bugs.launchpad.net/kicad/+bug/1714522
This commit is contained in:
Wayne Stambaugh 2017-09-01 15:31:03 -04:00
parent d190aa423f
commit 8d14751352
2 changed files with 46 additions and 16 deletions

View File

@ -219,6 +219,16 @@ public:
void OnUpdatePreferredPdfBrowser( wxUpdateUIEvent& event );
void OnUpdateRequiresProject( wxUpdateUIEvent& event );
/**
* Creates a new project by setting up and initial project, schematic, and board files.
*
* The project file is copied from the kicad.pro template file if possible. Otherwise,
* a minimal project file is created from an empty project. A minimal schematic and
* board file are created to prevent the schematic and board editors from complaining.
* If any of these files already exist, they are not overwritten.
*
* @param aProjectFileName is the absolute path of the project file name.
*/
void CreateNewProject( const wxFileName& aProjectFileName );
void LoadProject( const wxFileName& aProjectFileName );

View File

@ -110,9 +110,22 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName )
wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
"Project folder must exist and be writable to create a new project." );
// Init project filename
// Init project filename. This clears all elements from the project object.
SetProjectFileName( aProjectFileName.GetFullPath() );
// Copy kicad.pro file from template folder.
if( !aProjectFileName.FileExists() )
{
wxString srcFileName = sys_search().FindValidPath( "kicad.pro" );
// Create a minimal project (.pro) file if the template project file could not be copied.
if( !wxFileName::FileExists( srcFileName )
|| !wxCopyFile( srcFileName, aProjectFileName.GetFullPath() ) )
{
Prj().ConfigSave( PgmTop().SysSearch(), GeneralGroupName, s_KicadManagerParams );
}
}
// Ensure a "stub" for a schematic root sheet and a board exist.
// It will avoid messages from the schematic editor or the board editor to create a new file
// And forces the user to create main files under the right name for the project manager
@ -186,28 +199,35 @@ void KICAD_MANAGER_FRAME::OnNewProject( wxCommandEvent& aEvent )
if( !pro.IsAbsolute() )
pro.MakeAbsolute();
// Check if the project directory is empty.
wxDir directory( pro.GetPath() );
if( directory.HasFiles() )
{
wxString msg = _( "The selected directory is not empty. We recommend you "
"create projects in their own clean directory.\n\nDo you "
"want to create a new empty directory for the project?" );
if( IsOK( this, msg ) )
{
// Append a new directory with the same name of the project file
// and try to create it
// Append a new directory with the same name of the project file.
pro.AppendDir( pro.GetName() );
if( !wxMkdir( pro.GetPath() ) )
// There was a problem, undo
pro.RemoveLastDir();
// Check if the project directory is empty if it already exists.
wxDir directory( pro.GetPath() );
if( !pro.DirExists() )
{
if( !pro.Mkdir() )
{
wxString msg;
msg.Printf( _( "Directory '%s' could not be created.\n\n"
"Please make sure you have write permissions and try again." ),
pro.GetPath() );
DisplayErrorMessage( this, msg );
return;
}
}
else if( directory.HasFiles() )
{
wxString msg = _( "The selected directory is not empty. It is recommended that you "
"create projects in their own empty directory.\n\nDo you "
"want to continue?" );
if( !IsOK( this, msg ) )
return;
}
CreateNewProject( pro.GetFullPath() );
CreateNewProject( pro );
LoadProject( pro );
}