GuiAlert: Convert html to plain text on console output

This commit is contained in:
Guillaume Munch 2016-12-04 18:28:03 +01:00
parent dbcbf305b2
commit f9528c63c8
4 changed files with 34 additions and 9 deletions

View File

@ -41,6 +41,8 @@ int prompt(docstring const & title, docstring const & question,
* Only use this if the user cannot perform some remedial action.
* \p askshowagain will display a check box where the user can turn off the
* warning for future cases. Ponder carefully if this is feasible.
*
* The console output takes care of converting any Qt html to plain text.
*/
void warning(docstring const & title, docstring const & message,
bool const & askshowagain = false);
@ -49,6 +51,8 @@ void warning(docstring const & title, docstring const & message,
* Display a warning to the user. Title should be a short (general) summary.
* Only use this if the user cannot perform some remedial action.
* On some systems it is possible to show a backtrace.
*
* The console output takes care of converting any Qt html to plain text.
*/
void error(docstring const & title, docstring const & message, bool backtrace = false);

View File

@ -69,6 +69,12 @@ void noAppDialog(QString const & title, QString const & msg, QMessageBox::Icon m
namespace Alert {
docstring toPlainText(docstring const & msg)
{
return qstring_to_ucs4(qtHtmlToPlainText(toqstr(msg)));
}
int doPrompt(docstring const & title0, docstring const & question,
int default_button, int cancel_button,
docstring const & b1, docstring const & b2,
@ -76,9 +82,9 @@ int doPrompt(docstring const & title0, docstring const & question,
{
//lyxerr << "PROMPT" << title0 << "FOCUS: " << qApp->focusWidget() << endl;
if (!use_gui || lyxerr.debugging()) {
lyxerr << title0 << '\n'
lyxerr << toPlainText(title0) << '\n'
<< "----------------------------------------\n"
<< question << endl;
<< toPlainText(question) << endl;
lyxerr << "Assuming answer is ";
switch (default_button) {
@ -148,9 +154,9 @@ int prompt(docstring const & title0, docstring const & question,
void doWarning(docstring const & title0, docstring const & message,
bool const & askshowagain)
{
lyxerr << "Warning: " << title0 << '\n'
lyxerr << "Warning: " << toPlainText(title0) << '\n'
<< "----------------------------------------\n"
<< message << endl;
<< toPlainText(message) << endl;
if (!use_gui)
return;
@ -200,9 +206,9 @@ void warning(docstring const & title0, docstring const & message,
void doError(docstring const & title0, docstring const & message, bool backtrace)
{
lyxerr << "Error: " << title0 << '\n'
lyxerr << "Error: " << toPlainText(title0) << '\n'
<< "----------------------------------------\n"
<< message << endl;
<< toPlainText(message) << endl;
QString details;
if (backtrace) {
@ -251,9 +257,9 @@ void error(docstring const & title0, docstring const & message, bool backtrace)
void doInformation(docstring const & title0, docstring const & message)
{
if (!use_gui || lyxerr.debugging())
lyxerr << title0 << '\n'
lyxerr << toPlainText(title0) << '\n'
<< "----------------------------------------\n"
<< message << endl;
<< toPlainText(message) << endl;
if (!use_gui)
return;
@ -298,7 +304,7 @@ bool doAskForText(docstring & response, docstring const & msg,
{
if (!use_gui || lyxerr.debugging()) {
lyxerr << "----------------------------------------\n"
<< msg << '\n'
<< toPlainText(msg) << '\n'
<< "Assuming answer is " << dflt << '\n'
<< "----------------------------------------" << endl;
if (!use_gui) {

View File

@ -683,4 +683,14 @@ QString formatToolTip(QString text, int em)
}
QString qtHtmlToPlainText(QString const & html)
{
if (!Qt::mightBeRichText(html))
return html;
QTextDocument td;
td.setHtml(html);
return td.toPlainText();
}
} // namespace lyx

View File

@ -231,6 +231,11 @@ private:
#endif
// Check if qstr is understood as rich text (Qt HTML) and if so, produce a
// rendering in plain text.
QString qtHtmlToPlainText(QString const & qstr);
} // namespace lyx
#endif // QTHELPERS_H