From: John Levon Date: Sat, 29 Mar 2003 09:48:03 +0000 (+0000) Subject: More alert fixes X-Git-Tag: 1.6.10~17131 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=770092ed6b98556742e5576510de94c37bb07a4c;p=features.git More alert fixes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6626 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index c0656c2631..4a3df4e4e0 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -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; } diff --git a/src/ChangeLog b/src/ChangeLog index 2dbf519ca2..bb13b29597 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2003-03-29 John Levon + + * 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 * lyx_cb.C: diff --git a/src/buffer.C b/src/buffer.C index 486bb4c140..0f44d2513d 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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 @@ -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); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 4230954a60..6493b5002d 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -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; diff --git a/src/lyx_cb.h b/src/lyx_cb.h index ce4220728b..8ebb2262f2 100644 --- a/src/lyx_cb.h +++ b/src/lyx_cb.h @@ -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); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index daf01bbad6..a695355657 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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: