So, i am trying to handle my own ini files in cinder and I would like to save them right before I close the window. I was wondering if there is a built in cinder function that runs before i close the program I can use. I have tried atexit
without success because of my file structure.
ci::app::App::cleanup()
will be called if your app is exited deliberately but if you write your ini class using RAII techniques you shouldn’t have to manually write them on exit. E.g
class IniReader
{
public:
void Load ( ) { ... }
void Save ( ) { ... }
~IniReader ( )
{
Save ( );
}
};
I wanted to implement a confirmation popup when the user tries to close the application. To achieve this I made some changes in my Cinder fork, so that if mQuitOnLastWindowClosed == true
the last window will not be closed. Instead a signal is triggered, allowing the app to respond by showing a confirmation popup and then either quitting the app or not doing anything at all.
Here are the changes to the Window and App classes
And then in my custom Application I can do something like this
Application::Application()
{
...
// setup quit handler
ci::app::App::get()->getWindow()->getSignalPreventedClose().connect([this]() {
if(projectHasUnsavedChanges()) {
confirmPopup("Are you sure?", "The current project has unsaved changes.", [this]() {
quit();
});
} else {
quit();
}
});
...
}
void Application::quit()
{
CI_LOG_I("Closing application");
ci::app::App::get()->quit();
}
Hi,
Are you aware of this callback that you can register for? from cinder/AppBase.h:
//! Signal that emits before the app quit process begins. If any slots return false then the app quitting is canceled.
EventSignalShouldQuit& getSignalShouldQuit() { return mSignalShouldQuit; }
If you wanted to implement your confirmPopup() using this, you could return false and then wait for youre popup’s OK button to be tapped and then issue an App::quit()
yourself from that.
Cheers,
Rich