]> git.lyx.org Git - lyx.git/blobdiff - src/converter.C
Alfredo's second patch
[lyx.git] / src / converter.C
index 1c7fbe167929293f78973366bc5d6114515f8c98..bef488cf2e9ffff076eb3397d761cd5c01bd6bc9 100644 (file)
@@ -30,7 +30,7 @@
 #include "support/path.h"
 #include "support/systemcall.h"
 
-#include "BoostFormat.h"
+#include "support/BoostFormat.h"
 
 #include <cctype>
 
@@ -360,13 +360,22 @@ bool Converters::convert(Buffer const * buffer,
                        }
 
                        if (res) {
-                               if (conv.to == "program")
-                                       Alert::alert(_("There were errors during the Build process."),
-                                                  _("You should try to fix them."));
-                               else
-                                       Alert::alert(_("Cannot convert file"),
-                                                  _("Error while executing"),
-                                                  command.substr(0, 50));
+                               if (conv.to == "program") {
+                                       Alert::error(_("Build errors"),
+                                               _("There were errors during the build process."));
+                               } else {
+#if USE_BOOST_FORMAT
+// FIXME: this should go out of here. For example, here we cannot say if
+// it is a document (.lyx) or something else. Same goes for elsewhere.
+                               Alert::error(_("Cannot convert file"),
+                                       boost::io::str(boost::format(_("An error occurred whilst running %1$s"))
+                                       % command.substr(0, 50)));
+#else
+                               Alert::error(_("Cannot convert file"),
+                                       _("An error occurred whilst running ")
+                                       + command.substr(0, 50));
+#endif
+                               }
                                return false;
                        }
                }
@@ -388,11 +397,12 @@ bool Converters::convert(Buffer const * buffer,
                                          token_base, to_base);
                        if (!lyx::rename(from, to)) {
 #if USE_BOOST_FORMAT
-                               Alert::alert(_("Error while trying to move directory:"),
-                                          from, boost::io::str(boost::format(_("to %1$s")) % to));
+                               Alert::error(_("Cannot convert file"),
+                                       boost::io::str(boost::format(_(
+                                       "Could not move a temporary file from %1$s to %2$s.")) % from % to));
 #else
-                               Alert::alert(_("Error while trying to move directory:"),
-                                          from, _("to ") + to);
+                               Alert::error(_("Cannot convert file"),
+                                          _("Could not move a temporary file from ") + from + _(" to ") + to + ".");
 #endif
                                return false;
                        }
@@ -430,11 +440,12 @@ bool Converters::move(string const & from, string const & to, bool copy)
                                : lyx::rename(from2, to2);
                        if (!moved && no_errors) {
 #if USE_BOOST_FORMAT
-                               Alert::alert(_("Error while trying to move file:"),
-                                          from2, boost::io::str(boost::format(_("to %1$s")) % to2));
+                               Alert::error(_("Cannot convert file"),
+                                       boost::io::str(boost::format(_(
+                                       "Could not move a temporary file from %1$s to %2$s.")) % from2 % to2));
 #else
-                               Alert::alert(_("Error while trying to move file:"),
-                                          from2, _("to ") + to2);
+                               Alert::error(_("Cannot convert file"),
+                                          _("Could not move a temporary file from ") + from2 + _(" to ") + to2 + ".");
 #endif
                                no_errors = false;
                        }
@@ -465,6 +476,36 @@ bool Converters::formatIsUsed(string const & format)
 }
 
 
+namespace {
+
+void alertErrors(string const & prog, int nr_errors)
+{
+       string s;
+#if USE_BOOST_FORMAT
+       if (nr_errors == 1) {
+               boost::format fmt(_("One error detected when running %1$s.\n"));
+               fmt % prog;
+               s = fmt.str();
+       } else {
+               boost::format fmt(_("%1$s errors detected when running %2$s.\n"));
+               fmt % tostr(nr_errors);
+               fmt % prog;
+               s = fmt.str();
+       }
+#else
+       if (nr_errors == 1) {
+               s = _("One error detected");
+       } else {
+               s = tostr(nr_errors);
+               s += _(" errors detected.");
+       }
+#endif
+       Alert::error(_("Errors found"), s);
+}
+
+}
+
+
 bool Converters::scanLog(Buffer const * buffer, string const & command,
                        string const & filename)
 {
@@ -492,31 +533,13 @@ bool Converters::scanLog(Buffer const * buffer, string const & command,
        }
 
        if ((result & LaTeX::ERRORS)) {
-               int num_errors = latex.getNumErrors();
-               string s;
-               string t;
-               if (num_errors == 1) {
-                       s = _("One error detected");
-                       t = _("You should try to fix it.");
-               } else {
-                       s = tostr(num_errors);
-                       s += _(" errors detected.");
-                       t = _("You should try to fix them.");
-               }
                string head;
                split(command, head, ' ');
-#if USE_BOOST_FORMAT
-               Alert::alert(boost::io::str(boost::format(_("There were errors during running of %1$s")) % head),
-                          s, t);
-#else
-               Alert::alert(_("There were errors during running of ") + head,
-                          s, t);
-#endif
+               alertErrors(head, latex.getNumErrors());
                return false;
        } else if (result & LaTeX::NO_OUTPUT) {
-               string const s = _("The operation resulted in");
-               string const t = _("an empty file.");
-               Alert::alert(_("Resulting file is empty"), s, t);
+               Alert::warning(_("Output is empty"),
+                       _("An empty output file was generated."));
                return false;
        }
        return true;
@@ -555,26 +578,23 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command)
 
        // check return value from latex.run().
        if ((result & LaTeX::NO_LOGFILE)) {
-               Alert::alert(_("LaTeX did not work!"),
-                          _("Missing log file:"), name);
+               string str;
+#if USE_BOOST_FORMAT
+               boost::format fmt(_("LaTeX did not run successfully. Additionally, LyX "
+                       "could not locate the LaTeX log %1$s."));
+               fmt % name;
+               str = fmt.str();
+#else
+               str += _("LaTeX did not run successfully. Additionally, LyX "
+                       "could not locate the LaTeX log ");
+               str += name + ".";
+#endif
+               Alert::error(_("LaTeX failed"), str);
        } else if ((result & LaTeX::ERRORS)) {
-               int num_errors = latex.getNumErrors();
-               string s;
-               string t;
-               if (num_errors == 1) {
-                       s = _("One error detected");
-                       t = _("You should try to fix it.");
-               } else {
-                       s = tostr(num_errors);
-                       s += _(" errors detected.");
-                       t = _("You should try to fix them.");
-               }
-               Alert::alert(_("There were errors during the LaTeX run."),
-                          s, t);
+               alertErrors("LaTeX", latex.getNumErrors());
        }  else if (result & LaTeX::NO_OUTPUT) {
-               string const s = _("The operation resulted in");
-               string const t = _("an empty file.");
-               Alert::alert(_("Resulting file is empty"), s, t);
+               Alert::warning(_("Output is empty"),
+                       _("An empty output file was generated."));
        }
 
        if (bv)