]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiAlert.cpp
Fix the tab ordering of GuiDocument components.
[lyx.git] / src / frontends / qt4 / GuiAlert.cpp
index 70bca4151e83df79e3eb8161710f0b1c6a990f26..a7bb480094f28b8547eee97a2d18a69a31b6ba52 100644 (file)
 #include <config.h>
 
 #include "alert.h"
-
+#include "InGuiThread.h"
 
 #include "frontends/Application.h"
 
 #include "qt_helpers.h"
 #include "LyX.h" // for lyx::use_gui
-#include "support/gettext.h"
 
+#include "support/gettext.h"
 #include "support/debug.h"
 #include "support/docstring.h"
 #include "support/lstrings.h"
 #include <iomanip>
 #include <iostream>
 
+
+// sync with GuiView.cpp
+#define EXPORT_in_THREAD 1
+
+
 using namespace std;
 using namespace lyx::support;
 
@@ -44,68 +49,6 @@ namespace lyx {
 namespace frontend {
 
 
-
-
-static docstring const formatted(docstring const & text)
-{
-       const int w = 80;
-       docstring sout;
-
-       if (text.empty())
-               return sout;
-
-       size_t curpos = 0;
-       docstring line;
-
-       while (true) {
-               size_t const nxtpos1 = text.find(' ',  curpos);
-               size_t const nxtpos2 = text.find('\n', curpos);
-               size_t const nxtpos = min(nxtpos1, nxtpos2);
-
-               docstring const word =
-                       nxtpos == docstring::npos ?
-                       text.substr(curpos) :
-                       text.substr(curpos, nxtpos - curpos);
-
-               bool const newline = (nxtpos2 != docstring::npos &&
-                                     nxtpos2 < nxtpos1);
-
-               docstring const line_plus_word =
-                       line.empty() ? word : line + char_type(' ') + word;
-
-               // FIXME: make w be size_t
-               if (int(line_plus_word.length()) >= w) {
-                       sout += line + char_type('\n');
-                       if (newline) {
-                               sout += word + char_type('\n');
-                               line.erase();
-                       } else {
-                               line = word;
-                       }
-
-               } else if (newline) {
-                       sout += line_plus_word + char_type('\n');
-                       line.erase();
-
-               } else {
-                       if (!line.empty())
-                               line += char_type(' ');
-                       line += word;
-               }
-
-               if (nxtpos == docstring::npos) {
-                       if (!line.empty())
-                               sout += line;
-                       break;
-               }
-
-               curpos = nxtpos + 1;
-       }
-
-       return sout;
-}
-
-
 void noAppDialog(QString const & title, QString const & msg, QMessageBox::Icon mode)
 {
        int argc = 1;
@@ -124,7 +67,8 @@ void noAppDialog(QString const & title, QString const & msg, QMessageBox::Icon m
 
 namespace Alert {
 
-int prompt(docstring const & title0, docstring const & question,
+
+int doPrompt(docstring const & title0, docstring const & question,
                  int default_button, int cancel_button,
                  docstring const & b1, docstring const & b2,
                  docstring const & b3, docstring const & b4)
@@ -156,7 +100,7 @@ int prompt(docstring const & title0, docstring const & question,
        //LYXERR0("FOCUS: " << qApp->focusWidget());
        QPushButton * b[4] = { 0, 0, 0, 0 };
        QMessageBox msg_box(QMessageBox::Information,
-                       toqstr(title), toqstr(formatted(question)),
+                       toqstr(title), toqstr(question),
                        QMessageBox::NoButton, qApp->focusWidget());
        b[0] = msg_box.addButton(b1.empty() ? "OK" : toqstr(b1),
                                        QMessageBox::ActionRole);
@@ -178,8 +122,21 @@ int prompt(docstring const & title0, docstring const & question,
        return res;
 }
 
+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 & b4)
+{
+#ifdef EXPORT_in_THREAD
+       return InGuiThread<int>().call(&doPrompt,
+#else
+       return doPrompt(
+#endif
+                               title0, question, default_button,
+                               cancel_button, b1, b2, b3, b4);
+}
 
-void warning(docstring const & title0, docstring const & message,
+void doWarning(docstring const & title0, docstring const & message,
             bool const & askshowagain)
 {
        lyxerr << "Warning: " << title0 << '\n'
@@ -192,7 +149,7 @@ void warning(docstring const & title0, docstring const & message,
        docstring const title = bformat(_("LyX: %1$s"), title0);
 
        if (theApp() == 0) {
-               noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Warning);
+               noAppDialog(toqstr(title), toqstr(message), QMessageBox::Warning);
                return;
        }
 
@@ -202,19 +159,29 @@ void warning(docstring const & title0, docstring const & message,
        if (!askshowagain) {
                ProgressInterface::instance()->warning(
                                toqstr(title),
-                               toqstr(formatted(message)));
+                               toqstr(message));
        } else {
                ProgressInterface::instance()->toggleWarning(
                                toqstr(title),
                                toqstr(message),
-                               toqstr(formatted(message)));
+                               toqstr(message));
        }
 
        qApp->restoreOverrideCursor();
 }
 
+void warning(docstring const & title0, docstring const & message,
+            bool const & askshowagain)
+{
+#ifdef EXPORT_in_THREAD        
+       InGuiThread<void>().call(&doWarning,
+#else
+       doWarning(
+#endif
+                               title0, message, askshowagain);
+}
 
-void error(docstring const & title0, docstring const & message)
+void doError(docstring const & title0, docstring const & message)
 {
        lyxerr << "Error: " << title0 << '\n'
               << "----------------------------------------\n"
@@ -226,7 +193,7 @@ void error(docstring const & title0, docstring const & message)
        docstring const title = bformat(_("LyX: %1$s"), title0);
 
        if (theApp() == 0) {
-               noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Critical);
+               noAppDialog(toqstr(title), toqstr(message), QMessageBox::Critical);
                return;
        }
 
@@ -235,13 +202,22 @@ void error(docstring const & title0, docstring const & message)
 
        ProgressInterface::instance()->error(
                toqstr(title),
-               toqstr(formatted(message)));
+               toqstr(message));
 
        qApp->restoreOverrideCursor();
 }
 
+void error(docstring const & title0, docstring const & message)
+{
+#ifdef EXPORT_in_THREAD
+       InGuiThread<void>().call(&doError, 
+#else
+       doError(
+#endif
+                               title0, message);
+}
 
-void information(docstring const & title0, docstring const & message)
+void doInformation(docstring const & title0, docstring const & message)
 {
        if (!use_gui || lyxerr.debugging())
                lyxerr << title0 << '\n'
@@ -254,7 +230,7 @@ void information(docstring const & title0, docstring const & message)
        docstring const title = bformat(_("LyX: %1$s"), title0);
 
        if (theApp() == 0) {
-               noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Information);
+               noAppDialog(toqstr(title), toqstr(message), QMessageBox::Information);
                return;
        }
 
@@ -263,13 +239,22 @@ void information(docstring const & title0, docstring const & message)
 
        ProgressInterface::instance()->information(
                toqstr(title),
-               toqstr(formatted(message)));
+               toqstr(message));
 
        qApp->restoreOverrideCursor();
 }
 
+void information(docstring const & title0, docstring const & message)
+{
+#ifdef EXPORT_in_THREAD
+       InGuiThread<void>().call(&doInformation,
+#else
+       doInformation(
+#endif
+                               title0, message);
+}
 
-bool askForText(docstring & response, docstring const & msg,
+bool doAskForText(docstring & response, docstring const & msg,
        docstring const & dflt)
 {
        if (!use_gui || lyxerr.debugging()) {
@@ -300,6 +285,16 @@ bool askForText(docstring & response, docstring const & msg,
        return false;
 }
 
+bool askForText(docstring & response, docstring const & msg,
+       docstring const & dflt)
+{
+#ifdef EXPORT_in_THREAD
+       return InGuiThread<bool>().call(&doAskForText,
+#else
+       return doAskForText(
+#endif
+                               response, msg, dflt);
+}
 
 } // namespace Alert
 } // namespace frontend