Add THROW_[MF]ALERT[EC] (AIArgs, AIAlert, AIAlertCode, AIAlertPrefix, AIAlertLine)

A system to throw errors that allow for easy error reporting to the user
by showing a translated pop-up alert box with the error message.

The messages use strings.xml for translation and allow the usual
replacement args (ie [FILE] is replaced with a filename).

The exceptions can be cascaded, by adding more (translated) text
when caught and then re-throwing the result.

Macros are being used to support adding a function name prefix
to a message of the current function that the exception is thrown
from.

The syntax is:

  <macro>(<line>);		to show 'line'
  <macro>(<alert>, <line>);	to append 'line' to a caught alert.
  <macro>(<line>, <alert>);	to prepend 'line' to a caught alert.

  where <macro> is one of:
  THROW_ALERT, THROW_MALERT, THROW_FALERT, THROW_FMALERT,
  THROW_ALERTE, THROW_MALERTE, THROW_FALERTE, THROW_FMALERTE, where
  M = modal, F = Function name.
  and where <line> is one of:

  <xmldesc>
  <xmldesc>, AIArgs<args>

  where <xmldesc> is a string literal that will be looked up
  in strings.xml, and <args> is:

  (<key>, <replacement>)[<args>]

  There are more variations of the macros to throw an arbitrary
  class (append _CLASS), include an int code (append C) or
  to store the current errno as code (append E).

  For example, THROW_MALERTC(code, ...), or THROW_FALERT_CLASS(Foobar, ...),
  where the ... is the same as for the macros above.

Documentation and example usage has been added to aialert.h.
This commit is contained in:
Aleric Inglewood
2013-11-03 21:18:06 +01:00
parent b7d2683b76
commit 193010e947
10 changed files with 408 additions and 1 deletions

View File

@@ -40,6 +40,7 @@
#include "lltrans.h"
#include "llnotifications.h"
#include "aialert.h"
#include "../newview/hippogridmanager.h"
@@ -1479,6 +1480,32 @@ LLNotificationPtr LLNotifications::add(const LLNotification::Params& p)
return pNotif;
}
LLNotificationPtr LLNotifications::add(AIAlert const& alert, unsigned int suppress_mask)
{
std::string alert_text;
bool suppress_newlines = false;
bool last_was_prefix = false;
for (AIAlert::lines_type::const_iterator line = alert.lines().begin(); line != alert.lines().end(); ++line)
{
// Even if a line is suppressed, we print its leading newline if requested, but never more than one.
if (!suppress_newlines && line->prepend_newline())
{
alert_text += '\n';
suppress_newlines = true;
}
if (!line->suppressed(suppress_mask))
{
if (last_was_prefix) alert_text += ' '; // The translation system strips off spaces... add them back.
alert_text += LLTrans::getString(line->getXmlDesc(), line->args());
suppress_newlines = false;
last_was_prefix = line->is_prefix();
}
}
LLSD substitutions = LLSD::emptyMap();
substitutions["[PAYLOAD]"] = alert_text;
return add(LLNotification::Params(alert.is_modal() ? "AIAlertModal" : "AIAlert").substitutions(substitutions));
}
void LLNotifications::add(const LLNotificationPtr pNotif)
{