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" ); wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
aFilename.SetExt( ext ); aFilename.SetExt( ext );
wxString dir; wxString projectDir = Prj().IsNullProject() ? aFilename.GetPath() : Prj().GetProjectPath();
wxString defaultDir;
if( GetMruPath().IsEmpty() ) if( aIsGlobal )
dir = aGlobalPath; {
if( !GetMruPath().IsEmpty() && !GetMruPath().StartsWith( projectDir ) )
defaultDir = GetMruPath();
else else
dir = GetMruPath(); defaultDir = aGlobalPath;
}
else
{
if( !GetMruPath().IsEmpty() && GetMruPath().StartsWith( projectDir ) )
defaultDir = GetMruPath();
else
defaultDir = projectDir;
}
if( isDirectory && doOpen ) if( isDirectory && doOpen )
{ {
if( !aIsGlobal && GetMruPath().IsEmpty() ) wxDirDialog dlg( this, prompt, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
{
dir = Prj().GetProjectPath();
}
wxDirDialog dlg( this, prompt, dir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return false; return false;
@ -1057,12 +1062,7 @@ bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
if( aFilename.GetName().empty() ) if( aFilename.GetName().empty() )
aFilename.SetName( "Library" ); aFilename.SetName( "Library" );
if( !aIsGlobal && GetMruPath().IsEmpty() ) wxFileDialog dlg( this, prompt, defaultDir, aFilename.GetFullName(),
{
dir = Prj().IsNullProject() ? aFilename.GetFullPath() : Prj().GetProjectPath();
}
wxFileDialog dlg( this, prompt, dir, aFilename.GetFullName(),
wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
: wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT ); : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );