GUI2/Modal Dialog: added a convenience set_retval wrapper

This wraps window::set_retval and acts as a companion to get_retval
This commit is contained in:
Charles Dang 2020-12-11 22:35:08 +11:00
parent 213453e6cf
commit 3f1ca71e0c
2 changed files with 21 additions and 2 deletions

View File

@ -118,6 +118,13 @@ bool modal_dialog::show(const unsigned auto_close_time)
return retval_ == retval::OK;
}
void modal_dialog::set_retval(int retval)
{
if(window_) {
window_->set_retval(retval);
}
}
field_bool* modal_dialog::register_bool(
const std::string& id,
const bool mandatory,

View File

@ -170,7 +170,6 @@ public:
*/
bool show(const unsigned auto_close_time = 0);
/***** ***** ***** setters / getters for members ***** ****** *****/
/** Returns a pointer to the dialog's window. Will be null if it hasn't been built yet. */
@ -179,11 +178,15 @@ public:
return window_.get();
}
/** Returns the cached window exit code. */
int get_retval() const
{
return retval_;
}
/** Convenience wrapper to set the window's exit code. */
void set_retval(int retval);
void set_always_save_fields(const bool always_save_fields)
{
always_save_fields_ = always_save_fields;
@ -330,7 +333,16 @@ protected:
std::unique_ptr<window> window_;
private:
/** Returns the window exit status, 0 means not shown. */
/**
* The window's exit code (return value).
*
* We keep a copy here so it may be accessed even after the dialog is closed and
* the window object is destroyed.
*
* This value is initially set to 0 (retval::NONE) meaning the dialog was not
* shown. After @ref show returns, it will hold the most recent retval of the
* window object, including any modifications made in @ref post_show.
*/
int retval_;
/**