More Alert/ error message fixes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6629 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-03-29 11:34:53 +00:00
parent 31dabbd890
commit 4bd79eda68
5 changed files with 117 additions and 85 deletions

View File

@ -2,6 +2,9 @@
* bufferview_funcs.C: remove pointless Alert
* buffer.C: fix confusing error message when
a template is chmoded 000
2003-03-29 John Levon <levon@movementarian.org>
* BufferView.C:

View File

@ -501,87 +501,96 @@ 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()) {
lex.next();
string const token(lex.getString());
if (token == "\\lyxformat") { // the first token _must_ be...
lex.eatLine();
string tmp_format = lex.getString();
//lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
// if present remove ".," from string.
string::size_type dot = tmp_format.find_first_of(".,");
//lyxerr << " dot found at " << dot << endl;
if (dot != string::npos)
tmp_format.erase(dot, 1);
file_format = strToInt(tmp_format);
//lyxerr << "format: " << file_format << endl;
if (file_format == LYX_FORMAT) {
// current format
} else if (file_format > LYX_FORMAT) {
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::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::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"
+tostr(LYX_FORMAT) + ' '
+ QuoteName(filename);
lyxerr[Debug::INFO] << "Running '"
<< command << '\''
<< endl;
cmd_ret const ret = RunCommand(command);
if (ret.first) {
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));
LyXLex tmplex(0, 0);
tmplex.setStream(is);
return readFile(tmplex, string(), pit);
} else {
// This code is reached if lyx2lyx failed (for
// some reason) to change the file format of
// the file.
lyx::Assert(false);
return false;
}
}
bool the_end = readBody(lex, pit);
params.setPaperStuff();
if (!the_end) {
Alert::error(_("Document format failure"),
_("The document ended unexpectedly, which means "
"that it is probably corrupted."));
}
return true;
} else {
Alert::error(_("Document format failure"),
_("The specified document is not a LyX document."));
}
} else {
if (!lex.isOK()) {
Alert::error(_("Document could not be read"),
_("The specified document could not be read."));
return false;
}
return false;
lex.next();
string const token(lex.getString());
if (!lex.isOK()) {
Alert::error(_("Document could not be read"),
_("The specified document could not be read."));
return false;
}
// the first token _must_ be...
if (token != "\\lyxformat") {
Alert::error(_("Document format failure"),
_("The specified document is not a LyX document."));
return false;
}
lex.eatLine();
string tmp_format = lex.getString();
//lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
// if present remove ".," from string.
string::size_type dot = tmp_format.find_first_of(".,");
//lyxerr << " dot found at " << dot << endl;
if (dot != string::npos)
tmp_format.erase(dot, 1);
file_format = strToInt(tmp_format);
//lyxerr << "format: " << file_format << endl;
if (file_format == LYX_FORMAT) {
// current format
} else if (file_format > LYX_FORMAT) {
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::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::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"
+tostr(LYX_FORMAT) + ' '
+ QuoteName(filename);
lyxerr[Debug::INFO] << "Running '"
<< command << '\''
<< endl;
cmd_ret const ret = RunCommand(command);
if (ret.first) {
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));
LyXLex tmplex(0, 0);
tmplex.setStream(is);
return readFile(tmplex, string(), pit);
} else {
// This code is reached if lyx2lyx failed (for
// some reason) to change the file format of
// the file.
lyx::Assert(false);
return false;
}
}
bool the_end = readBody(lex, pit);
params.setPaperStuff();
if (!the_end) {
Alert::error(_("Document format failure"),
_("The document ended unexpectedly, which means "
"that it is probably corrupted."));
}
return true;
}

View File

@ -331,8 +331,16 @@ Buffer * BufferList::readFile(string const & s, bool ronly)
FileInfo fileInfo2(s);
if (!fileInfo2.exist()) {
Alert::alert(_("Error!"), _("Cannot open file"),
MakeDisplayPath(s));
string const file = MakeDisplayPath(s, 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 0;
}
@ -463,8 +471,16 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
}
}
if (!templateok) {
Alert::alert(_("Error!"), _("Unable to open template"),
MakeDisplayPath(tname));
string const file = MakeDisplayPath(tname, 50);
#if USE_BOOST_FORMAT
boost::format fmt(_("The specified document template\n%1$s\ncould not be read."));
fmt % file;
string text = fmt.str();
#else
string text = _("The specified document template\n");
text += file + _(" could not be read.");
#endif
Alert::error(_("Could not read template"), text);
// no template, start with empty buffer
b->paragraphs.set(new Paragraph);
b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());

View File

@ -1,3 +1,7 @@
2003-03-29 John Levon <levon@movementarian.org>
* ControlSpellchecker.C: Alert cleanup
2003-03-29 John Levon <levon@movementarian.org>
* helper_funcs.C: Alert cleanup

View File

@ -115,7 +115,7 @@ void ControlSpellchecker::startSession()
message = _("The spell-checker could not be started.\n"
"Maybe it is mis-configured.");
Alert::alert(_("The spell-checker has failed"), message);
Alert::error(_("The spell-checker has failed"), message);
speller_.reset(0);
}
@ -208,7 +208,7 @@ bool ControlSpellchecker::checkAlive()
view().hide();
speller_.reset(0);
Alert::alert(_("The spell-checker has failed"), message);
Alert::error(_("The spell-checker has failed"), message);
return false;
}
@ -239,7 +239,7 @@ void ControlSpellchecker::showSummary()
#endif
view().hide();
Alert::alert(_("Spell-checking is complete"), message);
Alert::information(_("Spell-checking is complete"), message);
}