Skip to content

Commit

Permalink
GUI2/Modal Dialog: added a convenience set_retval wrapper
Browse files Browse the repository at this point in the history
This wraps window::set_retval and acts as a companion to get_retval
  • Loading branch information
Vultraz committed Dec 11, 2020
1 parent 213453e commit 3f1ca71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/gui/dialogs/modal_dialog.cpp
Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions src/gui/dialogs/modal_dialog.hpp
Expand Up @@ -170,7 +170,6 @@ class modal_dialog
*/
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. */
Expand All @@ -179,11 +178,15 @@ class modal_dialog
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;
Expand Down Expand Up @@ -330,7 +333,16 @@ class modal_dialog
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_;

/**
Expand Down

0 comments on commit 3f1ca71

Please sign in to comment.