(svn r23476) -Codechange: use the error queue to replace switch mode error strings, again making it possible to return multiple errors

This commit is contained in:
rubidium
2011-12-10 15:16:58 +00:00
parent 43e78a88ca
commit 56f37d9386
9 changed files with 58 additions and 42 deletions

View File

@@ -127,6 +127,8 @@ public:
typedef std::list<ErrorMessageData> ErrorList;
/** The actual queue with errors. */
ErrorList _errors;
/** Whether the window system is initialized or not. */
bool _window_system_initialized = false;
/** Window class for displaying an error message window. */
struct ErrmsgWindow : public Window, ErrorMessageData {
@@ -261,11 +263,7 @@ public:
~ErrmsgWindow()
{
SetRedErrorSquare(INVALID_TILE);
if (!_errors.empty()) {
new ErrmsgWindow(_errors.front());
_errors.pop_front();
}
if (_window_system_initialized) ShowFirstError();
}
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
@@ -293,6 +291,30 @@ void ClearErrorMessages()
_errors.clear();
}
/** Show the first error of the queue. */
void ShowFirstError()
{
_window_system_initialized = true;
if (!_errors.empty()) {
new ErrmsgWindow(_errors.front());
_errors.pop_front();
}
}
/**
* Unshow the critical error. This has to happen when a critical
* error is shown and we uninitialise the window system, i.e.
* remove all the windows.
*/
void UnshowCriticalError()
{
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
if (w != NULL) {
if (w->IsCritical()) _errors.push_front(*w);
_window_system_initialized = false;
}
}
/**
* Display an error message in a window.
* @param summary_msg General error message showed in first line. Must be valid.