From 315e07fabce78eaa12ebe8762090cc6222edfc4a Mon Sep 17 00:00:00 2001 From: John Levon Date: Mon, 31 Mar 2003 01:15:44 +0000 Subject: [PATCH] kill Alert::alert() git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6653 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 10 +++ src/bufferlist.C | 2 +- src/converter.C | 46 ++++++++++---- src/exporter.C | 32 ++++++---- src/format.C | 18 ++++-- src/frontends/Alert.C | 12 ---- src/frontends/Alert.h | 8 +-- src/frontends/Alert_pimpl.h | 2 - src/frontends/ChangeLog | 6 ++ src/frontends/controllers/ChangeLog | 5 ++ src/frontends/controllers/ControlDocument.C | 68 ++++++++++++++------- src/frontends/controllers/ControlPrint.C | 32 +++++++--- src/frontends/qt2/Alert_pimpl.C | 8 --- src/frontends/qt2/ChangeLog | 4 ++ src/frontends/xforms/Alert_pimpl.C | 8 --- src/frontends/xforms/ChangeLog | 4 ++ src/importer.C | 26 ++++---- src/insets/ChangeLog | 4 ++ src/insets/insetgraphics.C | 28 ++++++--- src/insets/insettext.C | 4 +- src/lyx_main.C | 13 ++-- 21 files changed, 214 insertions(+), 126 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 475b65c0c4..9e4c393aab 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2003-03-31 John Levon + + * bufferlist.C: "Load original" -> "Load Original" + + * converter.C: + * exporter.C: + * importer.C: + * lyx_main.C: + * format.C: more Alert cleanups + 2003-03-30 Lars Gullik Bjønnes * text2.C (removeParagraph): make it take a RowList::iterator as diff --git a/src/bufferlist.C b/src/bufferlist.C index 9b76eafb63..bdfd8567ca 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -365,7 +365,7 @@ Buffer * BufferList::readFile(string const & s, bool ronly) text += file + _(" exists.\n\nRecover emergency save?"); #endif int const ret = Alert::prompt(_("Load emergency save?"), - text, 0, _("&Recover"), _("&Load original")); + text, 0, _("&Recover"), _("&Load Original")); if (ret == 0) { ts = e; diff --git a/src/converter.C b/src/converter.C index d0f1529c92..bef488cf2e 100644 --- a/src/converter.C +++ b/src/converter.C @@ -364,9 +364,17 @@ bool Converters::convert(Buffer const * buffer, Alert::error(_("Build errors"), _("There were errors during the build process.")); } else { - Alert::alert(_("Cannot convert file"), - _("Error while executing"), - command.substr(0, 50)); +#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; } @@ -389,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; } @@ -431,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; } @@ -568,8 +578,18 @@ 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)) { alertErrors("LaTeX", latex.getNumErrors()); } else if (result & LaTeX::NO_OUTPUT) { diff --git a/src/exporter.C b/src/exporter.C index 8ebafda41e..a8957f5eb0 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -1,12 +1,12 @@ -/* This file is part of - * ====================================================== +/** + * \file exporter.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * LyX, The Document Processor + * \author unknown * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2001 The LyX Team. - * - * ====================================================== */ + * Full author contact details are available in file CREDITS + */ #include @@ -16,6 +16,7 @@ #include "buffer.h" #include "lyx_cb.h" //ShowMessage() #include "support/filetools.h" +#include "support/BoostFormat.h" #include "lyxrc.h" #include "converter.h" #include "format.h" @@ -56,9 +57,16 @@ bool Exporter::Export(Buffer * buffer, string const & format, } } if (backend_format.empty()) { - Alert::alert(_("Cannot export file"), - _("No information for exporting to ") - + formats.prettyName(format)); +#if USE_BOOST_FORMAT +// FIXME: better english ... + Alert::error(_("Couldn't export file"), + boost::io::str(boost::format(_("No information for exporting the format %1$s.")) + % formats.prettyName(format))); +#else + Alert::error(_("Couldn't export file"), + _("No information for exporting the format ") + + formats.prettyName(format) + "."); +#endif return false; } } else @@ -83,8 +91,8 @@ bool Exporter::Export(Buffer * buffer, string const & format, else if (backend_format == format) buffer->makeLaTeXFile(filename, string(), true); else if (contains(buffer->filePath(), ' ')) { - Alert::alert(_("Cannot run LaTeX."), - _("The path to the lyx file cannot contain spaces.")); + Alert::error(_("File name error"), + _("The directory path to the document cannot contain spaces.")); return false; } else buffer->makeLaTeXFile(filename, buffer->filePath(), false); diff --git a/src/format.C b/src/format.C index b8df07ce3b..27b6d9d3f1 100644 --- a/src/format.C +++ b/src/format.C @@ -158,12 +158,14 @@ bool Formats::view(Buffer const * buffer, string const & filename, format->isChildFormat()) format = getFormat(format->parentFormat()); if (!format || format->viewer().empty()) { +// I believe this is the wrong place to show alerts, it should be done by +// the caller (this should be "utility" code #if USE_BOOST_FORMAT - Alert::alert(_("Cannot view file"), + Alert::error(_("Cannot view file"), boost::io::str(boost::format(_("No information for viewing %1$s")) % prettyName(format_name))); #else - Alert::alert(_("Cannot view file"), + Alert::error(_("Cannot view file"), _("No information for viewing ") + prettyName(format_name)); #endif @@ -199,9 +201,15 @@ bool Formats::view(Buffer const * buffer, string const & filename, int const res = one.startscript(Systemcall::DontWait, command); if (res) { - Alert::alert(_("Cannot view file"), - _("Error while executing"), - command.substr(0, 50)); +#if USE_BOOST_FORMAT + Alert::error(_("Cannot view file"), + boost::io::str(boost::format(_("An error occurred whilst running %1$s")) + % command.substr(0, 50))); +#else + Alert::error(_("Cannot view file"), + _("An error occurred whilst running ") + + command.substr(0, 50)); +#endif return false; } return true; diff --git a/src/frontends/Alert.C b/src/frontends/Alert.C index 5b39e2e5bc..51e96f9e3c 100644 --- a/src/frontends/Alert.C +++ b/src/frontends/Alert.C @@ -21,18 +21,6 @@ using std::endl; using std::pair; using std::make_pair; -void Alert::alert(string const & s1, string const & s2, string const & s3) -{ - if (!lyxrc.use_gui) { - lyxerr << "------------------------------" << endl - << s1 << endl << s2 << endl << s3 << endl - << "------------------------------" << endl; - } else { - alert_pimpl(s1, s2, s3); - } -} - - int Alert::prompt(string const & title, string const & question, int default_button, string const & b1, string const & b2, string const & b3) diff --git a/src/frontends/Alert.h b/src/frontends/Alert.h index ead44a879d..f49d1d587c 100644 --- a/src/frontends/Alert.h +++ b/src/frontends/Alert.h @@ -33,13 +33,13 @@ int prompt(string const & title, string const & question, string const & b1, string const & b2, string const & b3 = string()); /** - * Display a warning to the user. Title should be a short summary. + * Display a warning to the user. Title should be a short (general) summary. * Only use this if the user cannot perform some remedial action. */ void warning(string const & title, string const & message); /** - * Display a warning to the user. Title should be a short summary. + * Display a warning to the user. Title should be a short (general) summary. * Only use this if the user cannot perform some remedial action. */ void error(string const & title, string const & message); @@ -52,10 +52,6 @@ void error(string const & title, string const & message); */ void information(string const & title, string const & message); -/// show an alert message. DO NOT USE !! -void alert(string const & title, string const & s1 = string(), - string const & s2 = string()); - /// Asks for a text. DO NOT USE !! std::pair const askForText(string const & msg, diff --git a/src/frontends/Alert_pimpl.h b/src/frontends/Alert_pimpl.h index f9c587d587..88becb95d6 100644 --- a/src/frontends/Alert_pimpl.h +++ b/src/frontends/Alert_pimpl.h @@ -12,8 +12,6 @@ // GUI-specific implementations -void alert_pimpl(string const & s1, string const & s2, string const & s3); - int prompt_pimpl(string const & title, string const & question, int default_button, string const & b1, string const & b2, string const & b3); diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 6d724c6a04..660221fc69 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,9 @@ +2003-03-31 John Levon + + * Alert_pimpl.h: + * Alert.h: + * Alert.C: finally kill alert() + 2003-03-30 Lars Gullik Bjønnes * screen.C (drawFromTo): adjust for RowList. diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index ab9bda9b0f..04ccecf118 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2003-03-31 John Levon + + * ControlPrint.C: + * ControlDocument.C: more Alert cleanups + 2003-03-29 John Levon * ControlSpellchecker.C: Alert cleanup diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index d730f2b7b9..77dc09462f 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -121,36 +121,60 @@ void ControlDocument::classApply() old_class, new_class, &*(lv_.buffer()->paragraphs.begin()), lv_.buffer()->params); - if (ret) { - string s; - if (ret == 1) { - s = _("One paragraph couldn't be converted"); - } else { + + if (!ret) + return; + + string s; #if USE_BOOST_FORMAT - boost::format fmt(_("%1$s paragraphs couldn't be converted")); - fmt % ret; - s = fmt.str(); -#else - s += tostr(ret); - s += _(" paragraphs couldn't be converted"); -#endif - } - Alert::alert(_("Conversion Errors!"),s, - _("into chosen document class")); + if (ret == 1) { + boost::format fmt(_("One paragraph could not be converted\n" + "into the document class %2$s.")); + fmt % textclasslist[new_class].name(); + s = fmt.str(); + } else { + boost::format fmt(_("%1$s paragraphs could not be converted\n" + "into the document class %2$s.")); + fmt % tostr(ret); + fmt % textclasslist[new_class].name(); + s = fmt.str(); } +#else + if (ret == 1) { + s += _("One paragraph could not be converted\n" + "into the document class "); + s += textclasslist[new_class].name() + "."; + } else { + s += tostr(ret); + s += _(" paragraphs could not be converted\n" + "into the document class "); + s += textclasslist[new_class].name() + "."; + } +#endif + Alert::warning(_("Class conversion errors"), s); } bool ControlDocument::loadTextclass(lyx::textclass_type tc) const { bool const success = textclasslist[tc].load(); - if (!success) { - // problem changing class - // -- warn user (to retain old style) - Alert::alert(_("Conversion Errors!"), - _("Errors loading new document class."), - _("Reverting to original document class.")); - } + if (success) + return success; + + string s; + +#if USE_BOOST_FORMAT + boost::format fmt(_("The document could not be converted\n" + "into the document class %1$s.")); + fmt % textclasslist[tc].name(); + s = fmt.str(); +#else + s += _("The document could not be converted\n" + "into the document class "); + s += textclasslist[tc].name() + "."; +#endif + Alert::error(_("Could not change class"), s); + return success; } diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index bcc51336dd..04128b71c4 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -29,6 +29,7 @@ #include "support/filetools.h" #include "support/path.h" #include "support/systemcall.h" +#include "support/BoostFormat.h" #include "debug.h" // for lyxerr @@ -81,6 +82,26 @@ string const ControlPrint::Browse(string const & in_name) } +namespace { + +void showPrintError(string const & name) +{ +#if USE_BOOST_FORMAT + boost::format fmt(_("Could not print the document %1$s.\n" + "Check that your printer is set up correctly.")); + fmt % MakeDisplayPath(name, 50); + string str = fmt.str(); +#else + string str = _("Could not print the document "); + str += MakeDisplayPath(name, 50); + str += _(".\nCheck that your printer is set up correctly."); +#endif + Alert::error(_("Print document failed"), str); +} + +} + + /// print the current buffer void ControlPrint::apply() { @@ -142,9 +163,7 @@ void ControlPrint::apply() command += converters.dvips_options(buffer()) + ' '; if (!Exporter::Export(buffer(), "dvi", true)) { - Alert::alert(_("Error:"), - _("Unable to print"), - _("Check that your parameters are correct")); + showPrintError(buffer()->fileName()); return; } @@ -205,9 +224,6 @@ void ControlPrint::apply() lyxerr[Debug::LATEX] << "ControlPrint::apply(): print command = \"" << command << '"' << endl; - if (res != 0) { - Alert::alert(_("Error:"), - _("Unable to print"), - _("Check that your parameters are correct")); - } + if (res != 0) + showPrintError(buffer()->fileName()); } diff --git a/src/frontends/qt2/Alert_pimpl.C b/src/frontends/qt2/Alert_pimpl.C index 3281e70b30..0cebcd0fdc 100644 --- a/src/frontends/qt2/Alert_pimpl.C +++ b/src/frontends/qt2/Alert_pimpl.C @@ -29,14 +29,6 @@ using std::pair; using std::make_pair; - -void alert_pimpl(string const & s1, string const & s2, string const & s3) -{ - QMessageBox::warning(0, "LyX", - toqstr(s1 + '\n' + '\n' + s2 + '\n' + s3)); -} - - int prompt_pimpl(string const & tit, string const & question, int default_button, string const & b1, string const & b2, string const & b3) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index f2f46a6567..31d593e797 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,7 @@ +2003-03-31 John Levon + + * Alert_pimpl.C: remove alert() + 2003-03-29 John Levon * QBrowseBox.C: handle transparent pixmaps diff --git a/src/frontends/xforms/Alert_pimpl.C b/src/frontends/xforms/Alert_pimpl.C index 298b4dfc1a..8a7f950fb4 100644 --- a/src/frontends/xforms/Alert_pimpl.C +++ b/src/frontends/xforms/Alert_pimpl.C @@ -25,13 +25,6 @@ using std::pair; using std::make_pair; using std::endl; -void alert_pimpl(string const & s1, string const & s2, string const & s3) -{ - fl_set_resource("flAlert.dismiss.label", _("Dismiss")); - fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0); -} - - void warning_pimpl(string const &, string const & message) { fl_show_messages(message.c_str()); @@ -60,7 +53,6 @@ int prompt_pimpl(string const &, string const & question, boost::tie(b1label, b1sc) = parse_shortcut(b1); boost::tie(b2label, b2sc) = parse_shortcut(b2); boost::tie(b3label, b3sc) = parse_shortcut(b3); - lyxerr << "Parsed " << b1 << " as " << b1label << " and " << b1sc << endl; if (b3.empty()) { fl_set_choices_shortcut(b1sc.c_str(), b2sc.c_str(), ""); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index d116238a70..476766919f 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2003-03-31 John Levon + + * Alert_pimpl.C: remove alert() + 2003-03-29 John Levon * bmtable.c: handle transparent pixels diff --git a/src/importer.C b/src/importer.C index d1ffa0537c..50601b456c 100644 --- a/src/importer.C +++ b/src/importer.C @@ -1,12 +1,13 @@ -/* This file is part of - * ====================================================== +/** + * \file exporter.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * LyX, The Document Processor + * \author unknown * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2001 The LyX Team. - * - * ====================================================== */ + * Full author contact details are available in file CREDITS + */ + #include @@ -62,13 +63,14 @@ bool Importer::Import(LyXView * lv, string const & filename, } if (loader_format.empty()) { #if USE_BOOST_FORMAT - Alert::alert(_("Cannot import file"), - boost::io::str(boost::format(_("No information for importing from %1$s")) +// FIXME: better english ... + Alert::error(_("Couldn't import file"), + boost::io::str(boost::format(_("No information for importing the format %1$s.")) % formats.prettyName(format))); #else - Alert::alert(_("Cannot import file"), - _("No information for importing from ") - + formats.prettyName(format)); + Alert::error(_("Couldn't import file"), + _("No information for importing the format ") + + formats.prettyName(format) + "."); #endif return false; } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index fb60c92316..a9f2bd3a59 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2003-03-31 John Levon + + * insettext.C: Alert fix + 2003-03-30 Lars Gullik Bjønnes * insettext.C (ascent): adjust for RowList diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 1182ad0ef1..834e3c629d 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -654,8 +654,16 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const << temp_file << (success ? " succeeded\n" : " failed\n"); if (!success) { - Alert::alert(_("Cannot copy file"), orig_file_with_path, - _("into tempdir")); +#if USE_BOOST_FORMAT + boost::format fmt(_("Could not copy the file\n%1$s\ninto the temporary directory.")); + fmt % orig_file_with_path; + string str = fmt.str(); +#else + string str = _("Could not copy the file\n"); + str += orig_file_with_path; + str += _("\ninto the temporary directory."); +#endif + Alert::error(_("Graphics display failed"), str); return orig_file; } } @@ -689,15 +697,19 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const << command << endl; Systemcall one; one.startscript(Systemcall::Wait, command); - if (!IsFileReadable(ChangeExtension(outfile_base, to))) + if (!IsFileReadable(ChangeExtension(outfile_base, to))) { #if USE_BOOST_FORMAT - Alert::alert(_("Cannot convert Image (not existing file?)"), - boost::io::str(boost::format(_("No information for converting from %1$s to %2$s")) - % from % to)); + boost::format fmt(_("No information for converting %1$s format files to %1$s.\n" + "Try defining a convertor in the preferences.")); + fmt % from % to; + string str = fmt.str(); #else - Alert::alert(_("Cannot convert Image (not existing file?)"), - _("No information for converting from ") + from + " to " + to); + string str = _("No information for converting "); + str += from + _(" format files to " + to; + str += ".\nTry defining a convertor in the preferences."); #endif + Alert::error(_("Could not convert image"), str); + } } return RemoveExtension(temp_file); diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 6a523f2a84..424c707a10 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1290,9 +1290,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev) #ifdef WITH_WARNINGS #warning FIXME horrendously bad UI #endif - Alert::alert(_("Impossible operation!"), - _("Cannot include more than one paragraph!"), - _("Sorry.")); + Alert::error(_("Paste failed"), _("Cannot include more than one paragraph.")); break; } } diff --git a/src/lyx_main.C b/src/lyx_main.C index 25b984fd3b..248ae2aa9d 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -641,13 +641,14 @@ bool LyX::readRcFile(string const & name) << " in " << lyxrc_path << endl; if (lyxrc.read(lyxrc_path) < 0) { #if USE_BOOST_FORMAT - Alert::alert(_("LyX Warning!"), - boost::io::str(boost::format(_("Error while reading %1$s.")) % lyxrc_path), - _("Using built-in defaults.")); + Alert::warning(_("Could not read preferences"), + boost::io::str(boost::format( + _("Error while reading the preferences file\n%1$s.\n" + "LyX will use the built-in defaults.")) % lyxrc_path)); #else - Alert::alert(_("LyX Warning!"), - _("Error while reading ") + lyxrc_path, - _("Using built-in defaults.")); + Alert::warning(_("Could not read preferences"), + string(_("Error while reading the preferences file\n")) + + lyxrc_path + _("LyX will use the built-in defaults.")); #endif return false; }