Improve default new-library destination logic to be more project aware.

Fixes https://gitlab.com/kicad/code/kicad/issues/12570
This commit is contained in:
Jeff Young 2022-10-04 17:55:19 +01:00
parent b4f3390626
commit 2be9586c38
1 changed files with 17 additions and 17 deletions

View File

@ -1028,22 +1028,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;
@ -1057,12 +1062,7 @@ bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
if( aFilename.GetName().empty() )
aFilename.SetName( "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 );