X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiAlert.cpp;h=9b651d3681580244faf905e060dfe66f0e92897d;hb=58505db8192762ee74a30622a3a0a8b6e091c555;hp=36bf3eecfbed026accebd77c3e5d3d0c5e7e73e3;hpb=f625dd7ea0770f0f1151401ed90d0ef2146595d7;p=lyx.git diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp index 36bf3eecfb..9b651d3681 100644 --- a/src/frontends/qt4/GuiAlert.cpp +++ b/src/frontends/qt4/GuiAlert.cpp @@ -1,9 +1,10 @@ /** - * \file qt4/alert_pimpl.cpp + * \file qt4/GuiAlert.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author John Levon + * \author Jürgen Spitzmüller * \author Abdelrazak Younes * * Full author contact details are available in file CREDITS. @@ -13,31 +14,36 @@ #include "alert.h" + #include "frontends/Application.h" #include "qt_helpers.h" -#include "debug.h" #include "LyX.h" // for lyx::use_gui -#include "ui_AskForTextUi.h" -#include "gettext.h" +#include "support/gettext.h" +#include "support/debug.h" #include "support/docstring.h" #include "support/lstrings.h" +#include "support/ProgressInterface.h" #include +#include #include -#include #include -#include #include +#include -using std::endl; -using std::string; +#include +#include +using namespace std; +using namespace lyx::support; namespace lyx { +namespace frontend { + + -using support::bformat; static docstring const formatted(docstring const & text) { @@ -53,7 +59,7 @@ static docstring const formatted(docstring const & text) while (true) { size_t const nxtpos1 = text.find(' ', curpos); size_t const nxtpos2 = text.find('\n', curpos); - size_t const nxtpos = std::min(nxtpos1, nxtpos2); + size_t const nxtpos = min(nxtpos1, nxtpos2); docstring const word = nxtpos == docstring::npos ? @@ -99,20 +105,52 @@ static docstring const formatted(docstring const & text) } -int prompt_pimpl(docstring const & tit, docstring const & question, - int default_button, int cancel_button, - docstring const & b1, docstring const & b2, docstring const & b3) +void noAppDialog(QString const & title, QString const & msg, QMessageBox::Icon mode) +{ + int argc = 1; + char * argv[1]; + QApplication app(argc, argv); + switch (mode) + { + case QMessageBox::Information: QMessageBox::information(0, title, msg); break; + case QMessageBox::Warning: QMessageBox::warning(0, title, msg); break; + case QMessageBox::Critical: QMessageBox::critical(0, title, msg); break; + default: break; + } +} + + +namespace Alert { + +int prompt(docstring const & title0, docstring const & question, + int default_button, int cancel_button, + docstring const & b1, docstring const & b2, docstring const & b3) { - docstring const title = bformat(_("LyX: %1$s"), tit); + //lyxerr << "PROMPT" << title0 << "FOCUS: " << qApp->focusWidget() << endl; + if (!use_gui || lyxerr.debugging()) { + lyxerr << title0 << '\n' + << "----------------------------------------\n" + << question << endl; + + lyxerr << "Assuming answer is "; + switch (default_button) { + case 0: lyxerr << b1 << endl; + case 1: lyxerr << b2 << endl; + case 2: lyxerr << b3 << endl; + } + if (!use_gui) + return default_button; + } - QMessageBox mb; + docstring const title = bformat(_("LyX: %1$s"), title0); // For some reason, sometimes Qt uses an hourglass or watch cursor when // displaying the alert. Hence, we ask for the standard cursor shape. // This call has no effect if the cursor has not been overridden. qApp->changeOverrideCursor(Qt::ArrowCursor); - // FIXME replace that with theApp->gui()->currentView() + // FIXME replace that with guiApp->currentView() + //LYXERR0("FOCUS: " << qApp->focusWidget()); int res = QMessageBox::information(qApp->focusWidget(), toqstr(title), toqstr(formatted(question)), @@ -128,131 +166,78 @@ int prompt_pimpl(docstring const & tit, docstring const & question, } -void warning_pimpl(docstring const & tit, docstring const & message) +void warning(docstring const & title0, docstring const & message, + bool const & askshowagain) { - docstring const title = bformat(_("LyX: %1$s"), tit); + lyxerr << "Warning: " << title0 << '\n' + << "----------------------------------------\n" + << message << endl; - if (theApp() == 0) { - int argc = 1; - char * argv[1]; - QApplication app(argc, argv); - QMessageBox::warning(0, - toqstr(title), - toqstr(formatted(message))); + if (!use_gui) return; - } - QMessageBox::warning(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); -} + docstring const title = bformat(_("LyX: %1$s"), title0); -void error_pimpl(docstring const & tit, docstring const & message) -{ - docstring const title = bformat(_("LyX: %1$s"), tit); if (theApp() == 0) { - int argc = 1; - char * argv[1]; - QApplication app(argc, argv); - QMessageBox::critical(0, - toqstr(title), - toqstr(formatted(message))); + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Warning); return; } - QMessageBox::critical(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); -} - - -void information_pimpl(docstring const & tit, docstring const & message) -{ - docstring const title = bformat(_("LyX: %1$s"), tit); - QMessageBox::information(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); -} - - -bool askForText_pimpl(docstring & response, docstring const & msg, - docstring const & dflt) -{ - docstring const title = bformat(_("LyX: %1$s"), msg); - - bool ok; - QString text = QInputDialog::getText(qApp->focusWidget(), - toqstr(title), - toqstr(char_type('&') + msg), - QLineEdit::Normal, - toqstr(dflt), &ok); - if (ok && !text.isEmpty()) { - response = qstring_to_ucs4(text); - return true; + if (!askshowagain) { + ProgressInterface::instance()->warning( + toqstr(title), + toqstr(formatted(message))); + } else { + ProgressInterface::instance()->toggleWarning( + toqstr(title), + toqstr(message), + toqstr(formatted(message))); } - response.clear(); - return false; } -namespace Alert { - -int prompt(docstring const & title, docstring const & question, - int default_button, int escape_button, - docstring const & b1, docstring const & b2, docstring const & b3) -{ - if (!use_gui || lyxerr.debugging()) { - lyxerr << to_utf8(title) << '\n' - << "----------------------------------------\n" - << to_utf8(question) << endl; - - lyxerr << "Assuming answer is "; - switch (default_button) { - case 0: lyxerr << to_utf8(b1) << endl; - case 1: lyxerr << to_utf8(b2) << endl; - case 2: lyxerr << to_utf8(b3) << endl; - } - if (!use_gui) - return default_button; - } - - return prompt_pimpl(title, question, - default_button, escape_button, b1, b2, b3); - -} - - -void warning(docstring const & title, docstring const & message) +void error(docstring const & title0, docstring const & message) { - lyxerr << "Warning: " << to_utf8(title) << '\n' + lyxerr << "Error: " << title0 << '\n' << "----------------------------------------\n" - << to_utf8(message) << endl; + << message << endl; - if (use_gui) - warning_pimpl(title, message); -} + if (!use_gui) + return; + docstring const title = bformat(_("LyX: %1$s"), title0); -void error(docstring const & title, docstring const & message) -{ - lyxerr << "Error: " << to_utf8(title) << '\n' - << "----------------------------------------\n" - << to_utf8(message) << endl; + if (theApp() == 0) { + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Critical); + return; + } - if (use_gui) - error_pimpl(title, message); + ProgressInterface::instance()->error( + toqstr(title), + toqstr(formatted(message))); } -void information(docstring const & title, docstring const & message) +void information(docstring const & title0, docstring const & message) { if (!use_gui || lyxerr.debugging()) - lyxerr << to_utf8(title) << '\n' + lyxerr << title0 << '\n' << "----------------------------------------\n" - << to_utf8(message) << endl; + << message << endl; - if (use_gui) - information_pimpl(title, message); + if (!use_gui) + return; + + docstring const title = bformat(_("LyX: %1$s"), title0); + + if (theApp() == 0) { + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Information); + return; + } + + ProgressInterface::instance()->information( + toqstr(title), + toqstr(formatted(message))); } @@ -261,8 +246,8 @@ bool askForText(docstring & response, docstring const & msg, { if (!use_gui || lyxerr.debugging()) { lyxerr << "----------------------------------------\n" - << to_utf8(msg) << '\n' - << "Assuming answer is " << to_utf8(dflt) << '\n' + << msg << '\n' + << "Assuming answer is " << dflt << '\n' << "----------------------------------------" << endl; if (!use_gui) { response = dflt; @@ -270,8 +255,24 @@ bool askForText(docstring & response, docstring const & msg, } } - return askForText_pimpl(response, msg, dflt); + docstring const title = bformat(_("LyX: %1$s"), msg); + + bool ok; + QString text = QInputDialog::getText(qApp->focusWidget(), + toqstr(title), + toqstr(char_type('&') + msg), + QLineEdit::Normal, + toqstr(dflt), &ok); + + if (ok) { + response = qstring_to_ucs4(text); + return true; + } + response.clear(); + return false; } + } // namespace Alert +} // namespace frontend } // namespace lyx