Fix project handling in eagle project import and ensure the titlebar is correct
Previously it didn't properly close or create a new project for the Eagle project. Also, update the titlebar text whenever the project changes (so it is cleared properly when a project is unloaded). Fixes https://gitlab.com/kicad/code/kicad/issues/5152
This commit is contained in:
parent
4c535c160c
commit
0975f3817a
|
@ -48,11 +48,6 @@
|
||||||
|
|
||||||
void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event )
|
void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
// Close other windows.
|
|
||||||
if( !Kiway().PlayersClose( false ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
wxString title = _( "Import Eagle Project Files" );
|
wxString title = _( "Import Eagle Project Files" );
|
||||||
int style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
|
int style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
|
||||||
wxString default_dir = GetMruPath();
|
wxString default_dir = GetMruPath();
|
||||||
|
@ -117,8 +112,10 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event )
|
||||||
if( !pro.IsAbsolute() )
|
if( !pro.IsAbsolute() )
|
||||||
pro.MakeAbsolute();
|
pro.MakeAbsolute();
|
||||||
|
|
||||||
SetProjectFileName( pro.GetFullPath() );
|
// Close the project and make the new one
|
||||||
wxString prj_filename = GetProjectFileName();
|
CloseProject( true );
|
||||||
|
CreateNewProject( pro.GetFullPath(), false /* Don't create stub files */ );
|
||||||
|
LoadProject( pro );
|
||||||
|
|
||||||
if( sch.FileExists() )
|
if( sch.FileExists() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -210,27 +210,9 @@ KICAD_SETTINGS* KICAD_MANAGER_FRAME::kicadSettings() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KICAD_MANAGER_FRAME::SetProjectFileName( const wxString& aFullProjectProFileName )
|
|
||||||
{
|
|
||||||
// ensure file name is absolute:
|
|
||||||
wxFileName fn( aFullProjectProFileName );
|
|
||||||
|
|
||||||
if( !fn.IsAbsolute() )
|
|
||||||
fn.MakeAbsolute();
|
|
||||||
|
|
||||||
SetTitle( wxString( "KiCad " ) + GetBuildVersion() );
|
|
||||||
wxString title = GetTitle() + " " + fn.GetFullPath();
|
|
||||||
|
|
||||||
if( !fn.IsDirWritable() )
|
|
||||||
title += _( " [Read Only]" );
|
|
||||||
|
|
||||||
SetTitle( title );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const wxString KICAD_MANAGER_FRAME::GetProjectFileName() const
|
const wxString KICAD_MANAGER_FRAME::GetProjectFileName() const
|
||||||
{
|
{
|
||||||
return m_active_project ? Prj().GetProjectFullName() : wxString( wxEmptyString );
|
return Pgm().GetSettingsManager().IsProjectOpen() ? Prj().GetProjectFullName() : wxString( wxEmptyString );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -394,7 +376,6 @@ void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName )
|
||||||
m_active_project = true;
|
m_active_project = true;
|
||||||
|
|
||||||
Pgm().GetSettingsManager().LoadProject( aProjectFileName.GetFullPath() );
|
Pgm().GetSettingsManager().LoadProject( aProjectFileName.GetFullPath() );
|
||||||
SetProjectFileName( Prj().GetProjectFullName() );
|
|
||||||
|
|
||||||
if( aProjectFileName.IsDirWritable() )
|
if( aProjectFileName.IsDirWritable() )
|
||||||
SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. Why?
|
SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. Why?
|
||||||
|
@ -418,14 +399,11 @@ void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName )
|
void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName, bool aCreateStubFiles )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
|
wxCHECK_RET( aProjectFileName.DirExists() && aProjectFileName.IsDirWritable(),
|
||||||
"Project folder must exist and be writable to create a new project." );
|
"Project folder must exist and be writable to create a new project." );
|
||||||
|
|
||||||
// Init project filename. This clears all elements from the project object.
|
|
||||||
SetProjectFileName( aProjectFileName.GetFullPath() );
|
|
||||||
|
|
||||||
// If the project is legacy, convert it
|
// If the project is legacy, convert it
|
||||||
if( !aProjectFileName.FileExists() )
|
if( !aProjectFileName.FileExists() )
|
||||||
{
|
{
|
||||||
|
@ -460,40 +438,43 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure a "stub" for a schematic root sheet and a board exist.
|
// Create a "stub" for a schematic root sheet and a board if requested.
|
||||||
// It will avoid messages from the schematic editor or the board editor to create a new file
|
// It will avoid messages from the schematic editor or the board editor to create a new file
|
||||||
// And forces the user to create main files under the right name for the project manager
|
// And forces the user to create main files under the right name for the project manager
|
||||||
wxFileName fn( aProjectFileName.GetFullPath() );
|
if( aCreateStubFiles )
|
||||||
fn.SetExt( KiCadSchematicFileExtension );
|
|
||||||
|
|
||||||
// If a <project>.kicad_sch file does not exist, create a "stub" file ( minimal schematic file )
|
|
||||||
if( !fn.FileExists() )
|
|
||||||
{
|
{
|
||||||
wxFile file( fn.GetFullPath(), wxFile::write );
|
wxFileName fn( aProjectFileName.GetFullPath() );
|
||||||
|
fn.SetExt( KiCadSchematicFileExtension );
|
||||||
|
|
||||||
if( file.IsOpened() )
|
// If a <project>.kicad_sch file does not exist, create a "stub" file ( minimal schematic file )
|
||||||
file.Write( wxT( "(kicad_sch (version 20200310) (host eeschema \"unknown\")\n"
|
if( !fn.FileExists() )
|
||||||
"( page \"A4\")\n (lib_symbols)\n"
|
{
|
||||||
" (symbol_instances)\n)\n" ) );
|
wxFile file( fn.GetFullPath(), wxFile::write );
|
||||||
|
|
||||||
|
if( file.IsOpened() )
|
||||||
|
file.Write( wxT( "(kicad_sch (version 20200310) (host eeschema \"unknown\")\n"
|
||||||
|
"( page \"A4\")\n (lib_symbols)\n"
|
||||||
|
" (symbol_instances)\n)\n" ) );
|
||||||
|
|
||||||
|
|
||||||
// wxFile dtor will close the file
|
// wxFile dtor will close the file
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a <project>.kicad_pcb or <project>.brd file does not exist,
|
// If a <project>.kicad_pcb or <project>.brd file does not exist,
|
||||||
// create a .kicad_pcb "stub" file
|
// create a .kicad_pcb "stub" file
|
||||||
fn.SetExt( KiCadPcbFileExtension );
|
fn.SetExt( KiCadPcbFileExtension );
|
||||||
wxFileName leg_fn( fn );
|
wxFileName leg_fn( fn );
|
||||||
leg_fn.SetExt( LegacyPcbFileExtension );
|
leg_fn.SetExt( LegacyPcbFileExtension );
|
||||||
|
|
||||||
if( !fn.FileExists() && !leg_fn.FileExists() )
|
if( !fn.FileExists() && !leg_fn.FileExists() )
|
||||||
{
|
{
|
||||||
wxFile file( fn.GetFullPath(), wxFile::write );
|
wxFile file( fn.GetFullPath(), wxFile::write );
|
||||||
|
|
||||||
if( file.IsOpened() )
|
if( file.IsOpened() )
|
||||||
file.Write( wxT( "(kicad_pcb (version 4) (host kicad \"dummy file\") )\n" ) );
|
file.Write( wxT( "(kicad_pcb (version 4) (host kicad \"dummy file\") )\n" ) );
|
||||||
|
|
||||||
// wxFile dtor will close the file
|
// wxFile dtor will close the file
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateFileHistory( aProjectFileName.GetFullPath() );
|
UpdateFileHistory( aProjectFileName.GetFullPath() );
|
||||||
|
@ -561,6 +542,30 @@ void KICAD_MANAGER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void KICAD_MANAGER_FRAME::ProjectChanged()
|
||||||
|
{
|
||||||
|
wxString title = wxS( "KiCad " ) + GetBuildVersion();
|
||||||
|
wxString file = GetProjectFileName();
|
||||||
|
|
||||||
|
if( !file.IsEmpty() )
|
||||||
|
{
|
||||||
|
// Ensure file name is absolute
|
||||||
|
wxFileName fn( file );
|
||||||
|
|
||||||
|
if( !fn.IsAbsolute() )
|
||||||
|
fn.MakeAbsolute();
|
||||||
|
|
||||||
|
title += " ";
|
||||||
|
title += fn.GetFullPath();
|
||||||
|
|
||||||
|
if( !fn.IsDirWritable() )
|
||||||
|
title += _( " [Read Only]" );
|
||||||
|
}
|
||||||
|
|
||||||
|
SetTitle( title );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void KICAD_MANAGER_FRAME::ClearMsg()
|
void KICAD_MANAGER_FRAME::ClearMsg()
|
||||||
{
|
{
|
||||||
m_messagesBox->Clear();
|
m_messagesBox->Clear();
|
||||||
|
|
|
@ -138,8 +138,9 @@ public:
|
||||||
* If any of these files already exist, they are not overwritten.
|
* If any of these files already exist, they are not overwritten.
|
||||||
*
|
*
|
||||||
* @param aProjectFileName is the absolute path of the project file name.
|
* @param aProjectFileName is the absolute path of the project file name.
|
||||||
|
* @param aCreateStubFiles specifies if an empty PCB and schematic should be created
|
||||||
*/
|
*/
|
||||||
void CreateNewProject( const wxFileName& aProjectFileName );
|
void CreateNewProject( const wxFileName& aProjectFileName, bool aCreateStubFiles = true );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the project, and saves it if aSave is true;
|
* Closes the project, and saves it if aSave is true;
|
||||||
|
@ -154,6 +155,7 @@ public:
|
||||||
|
|
||||||
void ShowChangedLanguage() override;
|
void ShowChangedLanguage() override;
|
||||||
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
|
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
|
||||||
|
void ProjectChanged() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by sending a event with id = ID_INIT_WATCHED_PATHS
|
* Called by sending a event with id = ID_INIT_WATCHED_PATHS
|
||||||
|
@ -165,7 +167,6 @@ public:
|
||||||
|
|
||||||
void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
|
void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
|
||||||
|
|
||||||
void SetProjectFileName( const wxString& aFullProjectProFileName );
|
|
||||||
const wxString GetProjectFileName() const;
|
const wxString GetProjectFileName() const;
|
||||||
|
|
||||||
bool IsProjectActive();
|
bool IsProjectActive();
|
||||||
|
|
|
@ -70,10 +70,11 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
|
||||||
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::newProject, SELECTION_CONDITIONS::ShowAlways );
|
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::newProject, SELECTION_CONDITIONS::ShowAlways );
|
||||||
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::newFromTemplate, SELECTION_CONDITIONS::ShowAlways );
|
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::newFromTemplate, SELECTION_CONDITIONS::ShowAlways );
|
||||||
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::openProject, SELECTION_CONDITIONS::ShowAlways );
|
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::openProject, SELECTION_CONDITIONS::ShowAlways );
|
||||||
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::closeProject, SELECTION_CONDITIONS::ShowAlways );
|
|
||||||
fileMenu->AddMenu( openRecentMenu,
|
fileMenu->AddMenu( openRecentMenu,
|
||||||
FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
|
FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
|
||||||
|
|
||||||
|
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::closeProject, SELECTION_CONDITIONS::ShowAlways );
|
||||||
|
|
||||||
fileMenu->AddSeparator();
|
fileMenu->AddSeparator();
|
||||||
fileMenu->AddItem( ACTIONS::saveAs, SELECTION_CONDITIONS::ShowAlways );
|
fileMenu->AddItem( ACTIONS::saveAs, SELECTION_CONDITIONS::ShowAlways );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue