]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiAlert.cpp
Enable OK/Apply buttons when resetting to class defaults.
[lyx.git] / src / frontends / qt4 / GuiAlert.cpp
index a7bb480094f28b8547eee97a2d18a69a31b6ba52..ef4725c84accbc3173abefa5c174c34d99a12320 100644 (file)
@@ -24,6 +24,7 @@
 #include "support/debug.h"
 #include "support/docstring.h"
 #include "support/lstrings.h"
+#include "support/lassert.h"
 #include "support/ProgressInterface.h"
 
 #include <QApplication>
@@ -68,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,
@@ -75,15 +82,15 @@ 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) {
-               case 0: lyxerr << b1 << endl;
-               case 1: lyxerr << b2 << endl;
-               case 2: lyxerr << b3 << endl;
+               case 0: lyxerr << b1 << endl; break;
+               case 1: lyxerr << b2 << endl; break;
+               case 2: lyxerr << b3 << endl; break;
                case 3: lyxerr << b4 << endl;
                }
                if (!use_gui)
@@ -92,6 +99,11 @@ int doPrompt(docstring const & title0, docstring const & question,
 
        docstring const title = bformat(_("LyX: %1$s"), title0);
 
+       /// Long operation in progress prevents user from Ok-ing the error dialog
+       bool long_op = theApp()->longOperationStarted();
+       if (long_op)
+               theApp()->stopLongOperation();
+
        // For some reason, sometimes Qt uses a hourglass or watch cursor when
        // displaying the alert. Hence, we ask for the standard cursor shape.
        qApp->setOverrideCursor(Qt::ArrowCursor);
@@ -116,6 +128,9 @@ int doPrompt(docstring const & title0, docstring const & question,
 
        qApp->restoreOverrideCursor();
 
+       if (long_op)
+               theApp()->startLongOperation();
+
        // Qt bug: can return -1 on cancel or WM close, despite the docs.
        if (res == -1)
                res = cancel_button;
@@ -139,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;
@@ -153,6 +168,11 @@ void doWarning(docstring const & title0, docstring const & message,
                return;
        }
 
+       /// Long operation in progress prevents user from Ok-ing the error dialog
+       bool long_op = theApp()->longOperationStarted();
+       if (long_op)
+               theApp()->stopLongOperation();
+
        // Don't use a hourglass cursor while displaying the alert
        qApp->setOverrideCursor(Qt::ArrowCursor);
 
@@ -168,12 +188,15 @@ void doWarning(docstring const & title0, docstring const & message,
        }
 
        qApp->restoreOverrideCursor();
+
+       if (long_op)
+               theApp()->startLongOperation();
 }
 
 void warning(docstring const & title0, docstring const & message,
             bool const & askshowagain)
 {
-#ifdef EXPORT_in_THREAD        
+#ifdef EXPORT_in_THREAD
        InGuiThread<void>().call(&doWarning,
 #else
        doWarning(
@@ -181,11 +204,15 @@ void warning(docstring const & title0, docstring const & message,
                                title0, message, askshowagain);
 }
 
-void doError(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)
+               details = toqstr(printCallStack());
 
        if (!use_gui)
                return;
@@ -197,32 +224,41 @@ void doError(docstring const & title0, docstring const & message)
                return;
        }
 
+       /// Long operation in progress prevents user from Ok-ing the error dialog
+       bool long_op = theApp()->longOperationStarted();
+       if (long_op)
+               theApp()->stopLongOperation();
+
        // Don't use a hourglass cursor while displaying the alert
        qApp->setOverrideCursor(Qt::ArrowCursor);
 
        ProgressInterface::instance()->error(
                toqstr(title),
-               toqstr(message));
+               toqstr(message),
+               details);
 
        qApp->restoreOverrideCursor();
+
+       if (long_op)
+               theApp()->startLongOperation();
 }
 
-void error(docstring const & title0, docstring const & message)
+void error(docstring const & title0, docstring const & message, bool backtrace)
 {
 #ifdef EXPORT_in_THREAD
-       InGuiThread<void>().call(&doError, 
+       InGuiThread<void>().call(&doError,
 #else
        doError(
 #endif
-                               title0, message);
+                               title0, message, 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;
@@ -234,6 +270,11 @@ void doInformation(docstring const & title0, docstring const & message)
                return;
        }
 
+       /// Long operation in progress prevents user from Ok-ing the error dialog
+       bool long_op = theApp()->longOperationStarted();
+       if (long_op)
+               theApp()->stopLongOperation();
+
        // Don't use a hourglass cursor while displaying the alert
        qApp->setOverrideCursor(Qt::ArrowCursor);
 
@@ -242,6 +283,9 @@ void doInformation(docstring const & title0, docstring const & message)
                toqstr(message));
 
        qApp->restoreOverrideCursor();
+
+       if (long_op)
+               theApp()->startLongOperation();
 }
 
 void information(docstring const & title0, docstring const & message)
@@ -259,7 +303,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) {
@@ -270,6 +314,11 @@ bool doAskForText(docstring & response, docstring const & msg,
 
        docstring const title = bformat(_("LyX: %1$s"), msg);
 
+       /// Long operation in progress prevents user from Ok-ing the error dialog
+       bool long_op = theApp()->longOperationStarted();
+       if (long_op)
+               theApp()->stopLongOperation();
+
        bool ok;
        QString text = QInputDialog::getText(qApp->focusWidget(),
                toqstr(title),
@@ -277,6 +326,9 @@ bool doAskForText(docstring & response, docstring const & msg,
                QLineEdit::Normal,
                toqstr(dflt), &ok);
 
+       if (long_op)
+               theApp()->startLongOperation();
+
        if (ok) {
                response = qstring_to_ucs4(text);
                return true;