From 9c12a6ee1dabd964514a0b81f2b00fbb2bd82b51 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 22 Jan 2023 13:17:05 +0100 Subject: [PATCH] Eeschema, eeschema_config.cpp: fix incorrect *.wks file path when trying to save it. And add tests to see if the file can be saved Fix also an issue in sch_editor_control.cpp: The page setup dlg must generate changes only if the OK button is clicked. Fixes #13599 https://gitlab.com/kicad/code/kicad/issues/13599 --- eeschema/eeschema_config.cpp | 20 ++++++++++++-------- eeschema/tools/sch_editor_control.cpp | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 174ff6aff4..c85f787124 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -130,22 +130,26 @@ void SCH_EDIT_FRAME::SaveProjectSettings() RecordERCExclusions(); + + // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic) + // TODO: We need to remove dependence on BASE_SCREEN - Prj().GetProjectFile().m_SchematicSettings->m_SchDrawingSheetFileName = BASE_SCREEN::m_DrawingSheetFileName; + Prj().GetProjectFile().m_SchematicSettings->m_SchDrawingSheetFileName + = BASE_SCREEN::m_DrawingSheetFileName; if( !BASE_SCREEN::m_DrawingSheetFileName.IsEmpty() ) { - // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic) - wxFileName layoutfn( BASE_SCREEN::m_DrawingSheetFileName ); - if( !layoutfn.IsAbsolute() ) - layoutfn = wxFileName( Prj().GetProjectPath(), BASE_SCREEN::m_DrawingSheetFileName ); + bool success = true; - if( !layoutfn.FileExists() ) + if( !layoutfn.IsAbsolute() ) + success = layoutfn.MakeAbsolute( Prj().GetProjectPath() ); + + if( success && layoutfn.IsOk() && !layoutfn.FileExists() ) { - layoutfn.MakeAbsolute(); - DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() ); + if( layoutfn.DirExists() && layoutfn.IsDirWritable() ) + DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() ); } } diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 51bfe41aad..04929c7e66 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -182,7 +182,7 @@ int SCH_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent ) MAX_PAGE_SIZE_EESCHEMA_MILS ) ); dlg.SetWksFileName( BASE_SCREEN::m_DrawingSheetFileName ); - if( dlg.ShowModal() ) + if( dlg.ShowModal() == wxID_OK ) { // Update text variables m_frame->GetCanvas()->GetView()->MarkDirty();