Add return value to wxSafeShowMessage()

This allows the caller to log the message to the console in addition to
showing the message box, for example. Previously, this would be
impossible to do without getting the duplicates if the message box was
not shown, but now it is.
This commit is contained in:
Vadim Zeitlin
2021-03-14 13:18:36 +01:00
parent e00d5e131b
commit 77593c5996
3 changed files with 12 additions and 3 deletions

View File

@@ -1459,7 +1459,7 @@ inline void wxLogNop() { }
// wxLogFatalError helper: show the (fatal) error to the user in a safe way, // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
// i.e. without using wxMessageBox() for example because it could crash // i.e. without using wxMessageBox() for example because it could crash
void WXDLLIMPEXP_BASE bool WXDLLIMPEXP_BASE
wxSafeShowMessage(const wxString& title, const wxString& text); wxSafeShowMessage(const wxString& title, const wxString& text);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -1268,12 +1268,17 @@ public:
message string. message string.
@param text @param text
The text to show to the user. The text to show to the user.
@return
@true If a message box was actually shown or @false if the message was
logged to the console because there is no safe to show it currently
(the return value is only available since wxWidgets 3.1.5, the function
doesn't return anything in the previous versions).
@see wxLogFatalError() @see wxLogFatalError()
@header{wx/log.h} @header{wx/log.h}
*/ */
void wxSafeShowMessage(const wxString& title, const wxString& text); bool wxSafeShowMessage(const wxString& title, const wxString& text);
/** /**
Returns the error code from the last system call. This function uses Returns the error code from the last system call. This function uses

View File

@@ -180,13 +180,17 @@ private:
// helper global functions // helper global functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxSafeShowMessage(const wxString& title, const wxString& text) bool wxSafeShowMessage(const wxString& title, const wxString& text)
{ {
if ( !wxApp::GetValidTraits().SafeMessageBox(text, title) ) if ( !wxApp::GetValidTraits().SafeMessageBox(text, title) )
{ {
wxFprintf(stderr, wxS("%s: %s\n"), title.c_str(), text.c_str()); wxFprintf(stderr, wxS("%s: %s\n"), title.c_str(), text.c_str());
fflush(stderr); fflush(stderr);
return false;
} }
// Message box actually shown.
return true;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------