Delay restoring the auto-saved state

Restoring auto-saved state triggers source/destination sync which breaks
in the early stage when wxZRColaComposerPanel is still in its
constructor. The sync uses the application's m_mainWnd to get its
settings, but the application doesn't have the m_mainWnd set yet.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2021-11-12 15:35:43 +01:00
parent 980e5c6b2c
commit fc7f9da219
3 changed files with 17 additions and 12 deletions

View File

@ -174,6 +174,7 @@ bool ZRColaApp::OnInit()
wxSocketBase::Initialize(); wxSocketBase::Initialize();
m_mainWnd = new wxZRColaFrame(); m_mainWnd = new wxZRColaFrame();
m_mainWnd->m_panel->RestoreFromStateFile();
m_mainWnd->Show(); m_mainWnd->Show();
return true; return true;

View File

@ -45,7 +45,22 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) :
m_destination->SetMargins(FromDIP(wxPoint(5, 2))); m_destination->SetMargins(FromDIP(wxPoint(5, 2)));
m_source->PushEventHandler(&m_keyhandler); m_source->PushEventHandler(&m_keyhandler);
}
wxZRColaComposerPanel::~wxZRColaComposerPanel()
{
m_source->PopEventHandler();
// This is a controlled exit. Purge saved state.
wxString fileName(GetStateFileName());
if (wxFileExists(fileName))
wxRemoveFile(fileName);
}
void wxZRColaComposerPanel::RestoreFromStateFile()
{
// Restore the previously saved state (if exists). // Restore the previously saved state (if exists).
wxString fileName(GetStateFileName()); wxString fileName(GetStateFileName());
if (wxFileExists(fileName)) { if (wxFileExists(fileName)) {
@ -83,17 +98,6 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) :
} }
wxZRColaComposerPanel::~wxZRColaComposerPanel()
{
m_source->PopEventHandler();
// This is a controlled exit. Purge saved state.
wxString fileName(GetStateFileName());
if (wxFileExists(fileName))
wxRemoveFile(fileName);
}
void wxZRColaComposerPanel::SynchronizePanels() void wxZRColaComposerPanel::SynchronizePanels()
{ {
if (m_sourceChanged) { if (m_sourceChanged) {
@ -193,7 +197,6 @@ void wxZRColaComposerPanel::SynchronizePanels()
} }
void wxZRColaComposerPanel::OnSourcePaint(wxPaintEvent& event) void wxZRColaComposerPanel::OnSourcePaint(wxPaintEvent& event)
{ {
event.Skip(); event.Skip();

View File

@ -49,6 +49,7 @@ public:
wxZRColaComposerPanel(wxWindow* parent); wxZRColaComposerPanel(wxWindow* parent);
virtual ~wxZRColaComposerPanel(); virtual ~wxZRColaComposerPanel();
void RestoreFromStateFile();
void SynchronizePanels(); void SynchronizePanels();
friend class wxPersistentZRColaComposerPanel; // Allow saving/restoring window state. friend class wxPersistentZRColaComposerPanel; // Allow saving/restoring window state.