Commit d3f28fb7 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Fix KiCad crash when no template is selected on new project from template. (fixes lp:1170973)

parent 74c64958
...@@ -56,7 +56,8 @@ static const wxString GeneralGroupName( wxT( "/general" ) ); ...@@ -56,7 +56,8 @@ static const wxString GeneralGroupName( wxT( "/general" ) );
PARAM_CFG_ARRAY s_KicadManagerParams; PARAM_CFG_ARRAY s_KicadManagerParams;
void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName, bool aTemplateSelector = false ) void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName,
bool aTemplateSelector = false )
{ {
wxString filename; wxString filename;
wxFileName newProjectName = aPrjFullFileName; wxFileName newProjectName = aPrjFullFileName;
...@@ -118,13 +119,17 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName, boo ...@@ -118,13 +119,17 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName, boo
// Show the project template selector dialog // Show the project template selector dialog
int result = ps->ShowModal(); int result = ps->ShowModal();
if( result != wxID_OK ) if( (result != wxID_OK) || (ps->GetWidget() == NULL) )
{ {
wxMessageBox( _( "Did not generate new project from template" ), if( ps->GetWidget() == NULL )
_( "Cancelled new project from template" ), {
wxOK | wxICON_EXCLAMATION, wxMessageBox( _( "No project template was selected. Cannot generate new "
"project." ),
_( "Error" ),
wxOK | wxICON_ERROR,
this ); this );
} }
}
else else
{ {
// The selected template widget contains the template we're attempting to use to // The selected template widget contains the template we're attempting to use to
...@@ -132,7 +137,7 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName, boo ...@@ -132,7 +137,7 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName, boo
if( !ps->GetWidget()->GetTemplate()->CreateProject( newProjectName ) ) if( !ps->GetWidget()->GetTemplate()->CreateProject( newProjectName ) )
{ {
wxMessageBox( _( "Problem whilst creating new project from template!" ), wxMessageBox( _( "Problem whilst creating new project from template!" ),
_( "Could not generate new project" ), _( "Template Error" ),
wxOK | wxICON_ERROR, wxOK | wxICON_ERROR,
this ); this );
} }
...@@ -205,17 +210,19 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event ) ...@@ -205,17 +210,19 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
// Check if the project directory is empty // Check if the project directory is empty
wxDir directory ( m_ProjectFileName.GetPath() ); wxDir directory ( m_ProjectFileName.GetPath() );
if( directory.HasFiles() ) if( directory.HasFiles() )
{ {
wxString msg = _( "The selected directory is not empty. " wxString msg = _( "The selected directory is not empty. We recommend you "
"We recommend you create projects in their own clean directory.\n\n" "create projects in their own clean directory.\n\nDo you "
"Do you want to create a new empty directory for the project?" ); "want to create a new empty directory for the project?" );
if( IsOK( this, msg ) ) if( IsOK( this, msg ) )
{ {
// Append a new directory with the same name of the project file // Append a new directory with the same name of the project file
// and try to create it // and try to create it
m_ProjectFileName.AppendDir( m_ProjectFileName.GetName() ); m_ProjectFileName.AppendDir( m_ProjectFileName.GetName() );
if( !wxMkdir( m_ProjectFileName.GetPath() ) ) if( !wxMkdir( m_ProjectFileName.GetPath() ) )
// There was a problem, undo // There was a problem, undo
m_ProjectFileName.RemoveLastDir(); m_ProjectFileName.RemoveLastDir();
......
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