Try not to forget file history and window state on a crash.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15343
This commit is contained in:
Jeff Young 2023-08-14 22:43:17 +01:00
parent b986391a04
commit e30b05fcd0
2 changed files with 25 additions and 2 deletions

View File

@ -612,7 +612,10 @@ void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName )
if( aProjectFileName.IsDirWritable() )
SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. Why?
UpdateFileHistory( Prj().GetProjectFullName() );
// Save history & window state to disk now. Don't wait around for a crash.
KICAD_SETTINGS* settings = kicadSettings();
SaveSettings( settings );
settings->SaveToFile( Pgm().GetSettingsManager().GetPathForSettingsFile( settings ) );
m_leftWin->ReCreateTreePrj();
@ -713,7 +716,10 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName,
}
}
UpdateFileHistory( aProjectFileName.GetFullPath() );
// Save history & window state to disk now. Don't wait around for a crash.
KICAD_SETTINGS* settings = kicadSettings();
SaveSettings( settings );
settings->SaveToFile( Pgm().GetSettingsManager().GetPathForSettingsFile( settings ) );
m_openSavedWindows = true;
}
@ -832,6 +838,9 @@ void KICAD_MANAGER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
wxCHECK( settings, /*void*/);
settings->m_LeftWinWidth = m_leftWin->GetSize().x;
if( !m_isClosing )
settings->m_OpenProjects = GetSettingsManager()->GetOpenProjects();
}

View File

@ -743,6 +743,20 @@ int KICAD_MANAGER_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
if( wxWindow::FindFocus() != player )
player->SetFocus();
// Save window state to disk now. Don't wait around for a crash.
if( Pgm().GetCommonSettings()->m_Session.remember_open_files
&& !player->GetCurrentFileName().IsEmpty() )
{
wxFileName rfn( player->GetCurrentFileName() );
rfn.MakeRelativeTo( Prj().GetProjectPath() );
WINDOW_SETTINGS windowSettings;
player->SaveWindowSettings( &windowSettings );
Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &windowSettings, true );
Prj().GetLocalSettings().SaveToFile( Prj().GetProjectPath() );
}
return 0;
}