]> git.lyx.org Git - features.git/commitdiff
More alert fixes
authorJohn Levon <levon@movementarian.org>
Sat, 29 Mar 2003 09:48:03 +0000 (09:48 +0000)
committerJohn Levon <levon@movementarian.org>
Sat, 29 Mar 2003 09:48:03 +0000 (09:48 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6626 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/ChangeLog
src/buffer.C
src/lyx_cb.C
src/lyx_cb.h
src/lyxfunc.C

index c0656c26314828d1d6fb7785b97e968e656748e2..4a3df4e4e042f1cd89904582d8ee946fc6888330 100644 (file)
@@ -303,9 +303,16 @@ bool BufferView::insertLyXFile(string const & filen)
        FileInfo const fi(fname);
 
        if (!fi.readable()) {
-               Alert::alert(_("Error!"),
-                          _("Specified file is unreadable: "),
-                          MakeDisplayPath(fname, 50));
+               string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+               boost::format fmt(_("The specified document\n%1$s\ncould not be read."));
+               fmt % file;
+               string text = fmt.str();
+#else
+               string text = _("The specified document\n");
+               text += file + _(" could not be read.");
+#endif
+               Alert::error(_("Could not read document"), text);
                return false;
        }
 
index 2dbf519ca2703d21cca42c421b165a85f16e65c2..bb13b295971b51e206e5c1f6655af45a1dc4d7ab 100644 (file)
@@ -1,3 +1,12 @@
+2003-03-29  John Levon  <levon@movementarian.org>
+
+       * BufferView.C:
+       * buffer.C:
+       * lyx_cb.h:
+       * lyx_cb.C: more Alert cleanups
+
+       * lyxfunc.C: don't allow chktex if not latex document
+
 2003-03-29  John Levon  <levon@movementarian.org>
 
        * lyx_cb.C:
index 486bb4c14030d476e6fe46af3cebd6c28d364dae..0f44d2513daba8caca4f8d8aee9c07781b80a639 100644 (file)
@@ -1,15 +1,11 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file buffer.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Lars Gullik Bjønnes
  *
- *          Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 The LyX Team.
- *
- *           This file is Copyright 1996-2001
- *           Lars Gullik Bjønnes
- *
- * ======================================================
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
@@ -258,23 +254,18 @@ void Buffer::setFileName(string const & newfile)
 // We'll remove this later. (Lgb)
 namespace {
 
-#ifdef WITH_WARNINGS
-#warning this is never set to != 0 !!! - remove ?
-#endif
-int unknown_layouts;
-
 void unknownClass(string const & unknown)
 {
        string msg =
 #if USE_BOOST_FORMAT
                boost::io::str(boost::format(
-                       _("The document uses an unknown textclass \"%1$s\".")) % unknown)
-               + _("-- substituting default.");
+                       _("Using the default document class, because the "
+                       " class %1$s is unknown.")) % unknown);
 #else
-               _("The document uses an unknown textclass ")
-               + unknown + _("-- substituting default.");
+               _("Using the default document class, because the "
+               " class ") + unknown + (" is unknown."); 
 #endif
-       Alert::alert(_("Textclass error"), msg);
+       Alert::warning(_("Unknown document class"), msg);
 }
 
 } // anon
@@ -319,7 +310,6 @@ int Buffer::readHeader(LyXLex & lex)
 // Returns false if "\the_end" is not read (Asger)
 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
 {
-       unknown_layouts = 0;
        int unknown_tokens = 0;
 
        Paragraph::depth_type depth = 0;
@@ -329,17 +319,17 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
                unknown_tokens += readHeader(lex);
 
                if (!params.getLyXTextClass().load()) {
+                       string theclass = params.getLyXTextClass().name();
+                       string msg =
 #if USE_BOOST_FORMAT
-                       Alert::alert(_("Textclass Loading Error!"),
-                                  boost::io::str(boost::format(_("Can't load textclass %1$s")) %
-                                  params.getLyXTextClass().name()),
-                                  _("-- substituting default."));
+                               boost::io::str(boost::format(
+                                       _("Using the default document class, because the "
+                                       " class %1$s could not be loaded.")) % theclass);
 #else
-                       Alert::alert(_("Textclass Loading Error!"),
-                                    _("Can't load textclass ")
-                                    + params.getLyXTextClass().name(),
-                                    _("-- substituting default."));
+                               _("Using the default document class, because the "
+                               " class ") + theclass + (" could not be loaded.");
 #endif
+                       Alert::error(_("Can't load document class"), msg);
                        params.textclass = 0;
                }
        } else {
@@ -372,24 +362,21 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
                unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
        }
 
-       if (unknown_layouts > 0) {
-               string s = _("Couldn't set the layout for ");
-               if (unknown_layouts == 1) {
-                       s += _("one paragraph");
+
+       if (unknown_tokens > 0) {
+#if USE_BOOST_FORMAT
+               string s;
+               if (unknown_tokens == 1) {
+                       boost::format fmt(_("Encountered one unknown token when reading the document %1$s."));
+                       fmt % fileName();
+                       s = fmt.str();
                } else {
-                       s += tostr(unknown_layouts);
-                       s += _(" paragraphs");
+                       boost::format fmt(_("Encountered %1$s unknown tokens when reading the document %2$s."));
+                       fmt % tostr(unknown_tokens);
+                       fmt % fileName();
+                       s = fmt.str();
                }
-#if USE_BOOST_FORMAT
-               Alert::alert(_("Textclass Loading Error!"), s,
-                          boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
 #else
-               Alert::alert(_("Textclass Loading Error!"), s,
-                            _("When reading ") + fileName());
-#endif
-       }
-
-       if (unknown_tokens > 0) {
                string s = _("Encountered ");
                if (unknown_tokens == 1) {
                        s += _("one unknown token");
@@ -397,12 +384,7 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
                        s += tostr(unknown_tokens);
                        s += _(" unknown tokens");
                }
-#if USE_BOOST_FORMAT
-               Alert::alert(_("Textclass Loading Error!"), s,
-                          boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
-#else
-               Alert::alert(_("Textclass Loading Error!"), s,
-                            _("When reading ") +  fileName());
+               Alert::warning(_("Document format failure"), s);
 #endif
        }
 
@@ -516,6 +498,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
 }
 
 
+// FIXME: all the below Alerts should give the filename..
 bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iterator pit)
 {
        if (lex.isOK()) {
@@ -535,24 +518,24 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iter
                        if (file_format == LYX_FORMAT) {
                                // current format
                        } else if (file_format > LYX_FORMAT) {
-                               // future format
-                               Alert::alert(_("Warning!"),
-                                       _("The file was created with a newer version of "
+                               Alert::warning(_("Document format failure"),
+                                       _("This document was created with a newer version of "
                                        "LyX. This is likely to cause problems."));
-
                        } else if (file_format < LYX_FORMAT) {
                                // old formats
                                if (file_format < 200) {
-                                       Alert::alert(_("ERROR!"),
-                                                  _("Old LyX file format found. "
-                                                    "Use LyX 0.10.x to read this!"));
+                                       Alert::error(_("Document format failure"),
+                                               _("This LyX document is too old to be read "
+                                               "by this version of LyX. Try LyX 0.10."));
                                        return false;
                                } else if (!filename.empty()) {
                                        string command =
                                                LibFileSearch("lyx2lyx", "lyx2lyx");
                                        if (command.empty()) {
-                                               Alert::alert(_("ERROR!"),
-                                                            _("Can't find conversion script."));
+                                               Alert::error(_("Conversion script not found"),
+                                                       _("The document is from an earlier version "
+                                                         "of LyX, but the conversion script lyx2lyx "
+                                                         "could not be found."));
                                                return false;
                                        }
                                        command += " -t"
@@ -563,9 +546,10 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iter
                                                            << endl;
                                        cmd_ret const ret = RunCommand(command);
                                        if (ret.first) {
-                                               Alert::alert(_("ERROR!"),
-                                                            _("An error occured while "
-                                                              "running the conversion script."));
+                                               Alert::error(_("Conversion script failed"),
+                                                       _("The document is from an earlier version "
+                                                         "of LyX, but the lyx2lyx script failed "
+                                                         "to convert it."));
                                                return false;
                                        }
                                        istringstream is(STRCONV(ret.second));
@@ -584,16 +568,19 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iter
                        params.setPaperStuff();
 
                        if (!the_end) {
-                               Alert::alert(_("Warning!"),
-                                          _("Reading of document is not complete"),
-                                          _("Maybe the document is truncated"));
+                               Alert::error(_("Document format failure"),
+                                       _("The document ended unexpectedly, which means "
+                                         "that it is probably corrupted."));
                        }
                        return true;
-               } else { // "\\lyxformat" not found
-                       Alert::alert(_("ERROR!"), _("Not a LyX file!"));
+               } else {
+                       Alert::error(_("Document format failure"),
+                               _("The specified document is not a LyX document."));
                }
-       } else
-               Alert::alert(_("ERROR!"), _("Unable to read file!"));
+       } else {
+               Alert::error(_("Document could not be read"),
+                       _("The specified document could not be read."));
+       }
        return false;
 }
 
@@ -1170,7 +1157,16 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
        ofstream ofs(fname.c_str());
 
        if (!ofs) {
-               Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
+               string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+               boost::format fmt(_("Could not save the specified document\n%1$s.\n"));
+               fmt % file;
+               string text = fmt.str();
+#else
+               string text = _("Could not save the specified document\n");
+               text += file + _(".\n");
+#endif
+               Alert::error(_("Could not save document"), text);
                return;
        }
 
@@ -1627,7 +1623,17 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 {
        ofstream ofs(fname.c_str());
        if (!ofs) {
-               Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
+               string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+               boost::format fmt(_("Could not save the specified document\n%1$s.\n"));
+               fmt % file;
+               string text = fmt.str();
+#else
+               string text = _("Could not save the specified document\n");
+               text += file + _(".\n");
+#endif
+               Alert::error(_("Could not save document"), text);
+               return;
                return;
        }
 
@@ -2021,8 +2027,8 @@ int Buffer::runChktex()
        int res = chktex.run(terr); // run chktex
 
        if (res == -1) {
-               Alert::alert(_("chktex did not work!"),
-                          _("Could not run with file:"), name);
+               Alert::error(_("chktex failure"),
+                       _("Could not run chktex successfully."));
        } else if (res > 0) {
                // Insert all errors as errors boxes
                users->insertErrors(terr);
index 4230954a60bc6ad0ba3bda3ba032f1f79fcf962c..6493b5002deffc2a303327664d0e1455911caa1a 100644 (file)
@@ -177,37 +177,6 @@ bool WriteAs(BufferView * bv, Buffer * buffer, string const & filename)
 }
 
 
-int MenuRunChktex(Buffer * buffer)
-{
-       int ret;
-
-       if (buffer->isSGML()) {
-               Alert::alert(_("Chktex does not work with SGML derived documents."));
-               return 0;
-       } else
-               ret = buffer->runChktex();
-
-       if (ret >= 0) {
-               string s;
-               string t;
-               if (ret == 0) {
-                       s = _("No warnings found.");
-               } else if (ret == 1) {
-                       s = _("One warning found.");
-                       t = _("Use `Navigate->Error' to find it.");
-               } else {
-                       s += tostr(ret);
-                       s += _(" warnings found.");
-                       t = _("Use `Navigate->Error' to find them.");
-               }
-               Alert::alert(_("Chktex run successfully"), s, t);
-       } else {
-               Alert::alert(_("Error!"), _("It seems chktex does not work."));
-       }
-       return ret;
-}
-
-
 void QuitLyX()
 {
        lyxerr[Debug::INFO] << "Running QuitLyX." << endl;
index ce4220728beda1ecae5b47d8e5f9e13639cb2d43..8ebb2262f2dcf45ca0a249e9afae2231420bbc85 100644 (file)
@@ -21,8 +21,6 @@ bool MenuWrite(BufferView * bv, Buffer * buffer);
 bool WriteAs(BufferView * bv, Buffer * buffer,
             string const & filename = string());
 ///
-int MenuRunChktex(Buffer * buffer);
-///
 void QuitLyX();
 ///
 void AutoSave(BufferView * bv);
index daf01bbad6ff7334f1759079619153165bc6b9e4..a695355657237bdb809bf83f9230bb738230d0ca 100644 (file)
@@ -348,7 +348,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                disable = !mathcursor && !view()->getLyXText()->selection.set();
                break;
        case LFUN_RUNCHKTEX:
-               disable = lyxrc.chktex_command == "none";
+               disable = !buf->isLatex() || lyxrc.chktex_command == "none";
                break;
        case LFUN_BUILDPROG:
                disable = !Exporter::IsExportable(buf, "program");
@@ -1054,7 +1054,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                break;
 
        case LFUN_RUNCHKTEX:
-               MenuRunChktex(owner->buffer());
+               owner->buffer()->runChktex();
                break;
 
        case LFUN_MENUPRINT: