Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added registry::Autosaver class to automatically persist settings whe…
…n the XML tree has changed Prevents losing settings or keybinds when the app is crashing or terminated through the debugger.
- Loading branch information
1 parent
4e01460
commit 8ee895d
Showing
6 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <wx/event.h> | ||
#include <wx/app.h> | ||
#include "itextstream.h" | ||
#include "iregistry.h" | ||
|
||
namespace registry | ||
{ | ||
|
||
class Autosaver : | ||
public wxEvtHandler | ||
{ | ||
private: | ||
std::function<bool()> _shouldSave; | ||
|
||
public: | ||
Autosaver(const std::function<bool()>& shouldSaveCallback) : | ||
_shouldSave(shouldSaveCallback) | ||
{ | ||
wxTheApp->Connect(wxEVT_IDLE, wxIdleEventHandler(Autosaver::onIdle), nullptr, this); | ||
} | ||
|
||
~Autosaver() | ||
{ | ||
wxTheApp->Disconnect(wxEVT_IDLE, wxIdleEventHandler(Autosaver::onIdle), nullptr, this); | ||
} | ||
|
||
private: | ||
void onIdle(wxIdleEvent& ev) | ||
{ | ||
if (_shouldSave()) | ||
{ | ||
rMessage() << "Auto-saving registry to user settings path." << std::endl; | ||
|
||
if (module::GlobalModuleRegistry().moduleExists(MODULE_XMLREGISTRY)) | ||
{ | ||
GlobalRegistry().saveToDisk(); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters