From 1bf1620157e6c8fe43a1e8cc1755c2a309171e4b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 4 Oct 2022 17:55:19 +0100 Subject: [PATCH] Improve default new-library destination logic to be more project aware. Fixes https://gitlab.com/kicad/code/kicad/issues/12570 (cherry picked from commit 2be9586c3837e37cb4418f4790dc6fb8bf6ca186) --- common/eda_draw_frame.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index e6e7ff7018..3c45be1069 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -969,22 +969,27 @@ bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename, wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" ); aFilename.SetExt( ext ); - wxString dir; + wxString projectDir = Prj().IsNullProject() ? aFilename.GetPath() : Prj().GetProjectPath(); + wxString defaultDir; - if( GetMruPath().IsEmpty() ) - dir = aGlobalPath; + if( aIsGlobal ) + { + if( !GetMruPath().IsEmpty() && !GetMruPath().StartsWith( projectDir ) ) + defaultDir = GetMruPath(); + else + defaultDir = aGlobalPath; + } else - dir = GetMruPath(); - + { + if( !GetMruPath().IsEmpty() && GetMruPath().StartsWith( projectDir ) ) + defaultDir = GetMruPath(); + else + defaultDir = projectDir; + } if( isDirectory && doOpen ) { - if( !aIsGlobal && GetMruPath().IsEmpty() ) - { - dir = Prj().GetProjectPath(); - } - - wxDirDialog dlg( this, prompt, dir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST ); + wxDirDialog dlg( this, prompt, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST ); if( dlg.ShowModal() == wxID_CANCEL ) return false; @@ -998,12 +1003,7 @@ bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename, if( aFilename.GetName().empty() ) aFilename.SetName( wxT( "Library" ) ); - if( !aIsGlobal && GetMruPath().IsEmpty() ) - { - dir = Prj().IsNullProject() ? aFilename.GetFullPath() : Prj().GetProjectPath(); - } - - wxFileDialog dlg( this, prompt, dir, aFilename.GetFullName(), + wxFileDialog dlg( this, prompt, defaultDir, aFilename.GetFullName(), wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );