diff --git a/eeschema/class_drawsheet.cpp b/eeschema/class_drawsheet.cpp index 45b8bf18ac..9452384cf0 100644 --- a/eeschema/class_drawsheet.cpp +++ b/eeschema/class_drawsheet.cpp @@ -467,7 +467,7 @@ void DrawSheetStruct::SetFileName( const wxString& aFilename ) * Set a new filename and manage data and associated screen * The main difficulty is the filename change in a complex hierarchy. * - if new filename is not already used: change to the new name (and if an existing file is found, load it on request) - * - if new filename is already used (a complex hierarchy) : add the sheet to the complex hierarchy. + * - if new filename is already used (a complex hierarchy) : reference the sheet. */ bool DrawSheetStruct::ChangeFileName( WinEDA_SchematicFrame * aFrame, const wxString& aFileName ) @@ -482,14 +482,17 @@ bool DrawSheetStruct::ChangeFileName( WinEDA_SchematicFrame * aFrame, const wxSt if( g_RootSheet->SearchHierarchy( aFileName, &Screen_to_use ) ) //do we reload the data from the existing hierarchy { - msg.Printf( _( - "A Sub Hierarchy named %s exists, Use it (The data in this sheet will be replaced)?" ), - aFileName.GetData() ); - if( ! IsOK( NULL, msg ) ) - { - DisplayInfo(NULL, _("Sheet Filename Renaming Aborted")); - return false; - } + if(m_AssociatedScreen) //upon initial load, this will be null. + { + msg.Printf( _( + "A Sub Hierarchy named %s exists, Use it (The data in this sheet will be replaced)?" ), + aFileName.GetData() ); + if( ! IsOK( NULL, msg ) ) + { + DisplayInfo(NULL, _("Sheet Filename Renaming Aborted")); + return false; + } + } } else if( wxFileExists( aFileName ) ) //do we reload the data from an existing file diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 00b17a1c96..b4960a665c 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -300,13 +300,14 @@ void WinEDA_SheetPropertiesFrame::SheetPropertiesAccept( wxCommandEvent& event ) } ChangeFileNameExt( FileName, g_SchExtBuffer ); - if ( (FileName != m_CurrentSheet->GetFileName()) && m_CurrentSheet->m_AssociatedScreen ) + if ( (FileName != m_CurrentSheet->GetFileName()) ) { msg = _("Changing a Filename can change all the schematic structure and cannot be undone" ); msg << wxT("\n"); msg << _("Ok to continue renaming?"); - if( IsOK( NULL, msg) ) - { + if( m_CurrentSheet->m_AssociatedScreen == 0 || IsOK( NULL, msg) ) + { //do not prompt on a new sheet. in fact, we should not allow a sheet to be created + //without a valid associated filename to be read from. m_Parent->GetScreen()->ClearUndoRedoList(); m_CurrentSheet->ChangeFileName(m_Parent, FileName); }