mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Buffer.cpp:
- Move some lines of code to more proper places. - Let Buffer::readFile(FileName const &) return ReadStatus as well. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35827 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c1a1d16967
commit
80a5dd8144
@ -754,15 +754,15 @@ bool Buffer::readDocument(Lexer & lex)
|
|||||||
ErrorList & errorList = d->errorLists["Parse"];
|
ErrorList & errorList = d->errorLists["Parse"];
|
||||||
errorList.clear();
|
errorList.clear();
|
||||||
|
|
||||||
|
// remove dummy empty par
|
||||||
|
paragraphs().clear();
|
||||||
|
|
||||||
if (!lex.checkFor("\\begin_document")) {
|
if (!lex.checkFor("\\begin_document")) {
|
||||||
docstring const s = _("\\begin_document is missing");
|
docstring const s = _("\\begin_document is missing");
|
||||||
errorList.push_back(ErrorItem(_("Document header error"),
|
errorList.push_back(ErrorItem(_("Document header error"),
|
||||||
s, -1, 0, 0));
|
s, -1, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// we are reading in a brand new document
|
|
||||||
LASSERT(paragraphs().empty(), /**/);
|
|
||||||
|
|
||||||
readHeader(lex);
|
readHeader(lex);
|
||||||
|
|
||||||
if (params().outputChanges) {
|
if (params().outputChanges) {
|
||||||
@ -832,8 +832,6 @@ bool Buffer::readString(string const & s)
|
|||||||
{
|
{
|
||||||
params().compressed = false;
|
params().compressed = false;
|
||||||
|
|
||||||
// remove dummy empty par
|
|
||||||
paragraphs().clear();
|
|
||||||
Lexer lex;
|
Lexer lex;
|
||||||
istringstream is(s);
|
istringstream is(s);
|
||||||
lex.setStream(is);
|
lex.setStream(is);
|
||||||
@ -857,21 +855,21 @@ bool Buffer::readString(string const & s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Buffer::readFile(FileName const & filename)
|
Buffer::ReadStatus Buffer::readFile(FileName const & fn)
|
||||||
{
|
{
|
||||||
FileName fname(filename);
|
FileName fname(fn);
|
||||||
|
|
||||||
params().compressed = fname.isZippedFile();
|
|
||||||
|
|
||||||
// remove dummy empty par
|
|
||||||
paragraphs().clear();
|
|
||||||
Lexer lex;
|
Lexer lex;
|
||||||
lex.setFile(fname);
|
lex.setFile(fname);
|
||||||
if (readFile(lex, fname) != ReadSuccess)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
ReadStatus const ret_rf = readFile(lex, fname);
|
||||||
|
if (ret_rf != ReadSuccess)
|
||||||
|
return ret_rf;
|
||||||
|
|
||||||
|
// InsetInfo needs to know if file is under VCS
|
||||||
|
lyxvc().file_found_hook(fn);
|
||||||
d->read_only = !fname.isWritable();
|
d->read_only = !fname.isWritable();
|
||||||
return true;
|
params().compressed = fname.isZippedFile();
|
||||||
|
return ReadSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -976,9 +974,8 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
|
|||||||
from_utf8(filename.absFileName())));
|
from_utf8(filename.absFileName())));
|
||||||
return ReadFailure;
|
return ReadFailure;
|
||||||
} else {
|
} else {
|
||||||
bool const ret = readFile(tmpfile);
|
|
||||||
// Do stuff with tmpfile name and buffer name here.
|
// Do stuff with tmpfile name and buffer name here.
|
||||||
return ret ? ReadSuccess : ReadFailure;
|
return readFile(tmpfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3641,8 +3638,9 @@ Buffer::ReadStatus Buffer::readEmergency(FileName const & fn)
|
|||||||
// the file is not saved if we load the emergency file.
|
// the file is not saved if we load the emergency file.
|
||||||
markDirty();
|
markDirty();
|
||||||
docstring str;
|
docstring str;
|
||||||
bool const res = readFile(emergencyFile);
|
bool res;
|
||||||
if (res)
|
ReadStatus const ret_rf = readFile(emergencyFile);
|
||||||
|
if (res = (ret_rf == ReadSuccess))
|
||||||
str = _("Document was successfully recovered.");
|
str = _("Document was successfully recovered.");
|
||||||
else
|
else
|
||||||
str = _("Document was NOT successfully recovered.");
|
str = _("Document was NOT successfully recovered.");
|
||||||
@ -3675,13 +3673,13 @@ Buffer::ReadStatus Buffer::readEmergency(FileName const & fn)
|
|||||||
Buffer::ReadStatus Buffer::readAutosave(FileName const & fn)
|
Buffer::ReadStatus Buffer::readAutosave(FileName const & fn)
|
||||||
{
|
{
|
||||||
// Now check if autosave file is newer.
|
// Now check if autosave file is newer.
|
||||||
FileName autosaveFile = getAutosaveFileNameFor(fn);
|
FileName const autosaveFile = getAutosaveFileNameFor(fn);
|
||||||
if (!autosaveFile.exists()
|
if (!autosaveFile.exists()
|
||||||
|| autosaveFile.lastModified() <= fn.lastModified())
|
|| autosaveFile.lastModified() <= fn.lastModified())
|
||||||
return ReadFileNotFound;
|
return ReadFileNotFound;
|
||||||
|
|
||||||
docstring const file = makeDisplayPath(fn.absFileName(), 20);
|
docstring const file = makeDisplayPath(fn.absFileName(), 20);
|
||||||
docstring const text = bformat(_("The backup of the document %1$s
|
docstring const text = bformat(_("The backup of the document %1$s "
|
||||||
"is newer.\n\nLoad the backup instead?"), file);
|
"is newer.\n\nLoad the backup instead?"), file);
|
||||||
int const ret = Alert::prompt(_("Load backup?"), text, 0, 2,
|
int const ret = Alert::prompt(_("Load backup?"), text, 0, 2,
|
||||||
_("&Load backup"), _("Load &original"), _("&Cancel"));
|
_("&Load backup"), _("Load &original"), _("&Cancel"));
|
||||||
@ -3689,9 +3687,9 @@ Buffer::ReadStatus Buffer::readAutosave(FileName const & fn)
|
|||||||
switch (ret)
|
switch (ret)
|
||||||
{
|
{
|
||||||
case 0: {
|
case 0: {
|
||||||
bool success = readFile(autosaveFile);
|
ReadStatus const ret_rf = readFile(autosaveFile);
|
||||||
// the file is not saved if we load the autosave file.
|
// the file is not saved if we load the autosave file.
|
||||||
if (success) {
|
if (ret_rf == ReadSuccess) {
|
||||||
markDirty();
|
markDirty();
|
||||||
return ReadSuccess;
|
return ReadSuccess;
|
||||||
}
|
}
|
||||||
@ -3715,8 +3713,6 @@ Buffer::ReadStatus Buffer::loadLyXFile(FileName const & fn)
|
|||||||
if (ret_rvc != ReadSuccess)
|
if (ret_rvc != ReadSuccess)
|
||||||
return ret_rvc;
|
return ret_rvc;
|
||||||
}
|
}
|
||||||
// InsetInfo needs to know if file is under VCS
|
|
||||||
lyxvc().file_found_hook(fn);
|
|
||||||
|
|
||||||
ReadStatus const ret_re = readEmergency(fn);
|
ReadStatus const ret_re = readEmergency(fn);
|
||||||
if (ret_re == ReadSuccess || ret_re == ReadCancel)
|
if (ret_re == ReadSuccess || ret_re == ReadCancel)
|
||||||
@ -3726,9 +3722,7 @@ Buffer::ReadStatus Buffer::loadLyXFile(FileName const & fn)
|
|||||||
if (ret_ra == ReadSuccess || ret_ra == ReadCancel)
|
if (ret_ra == ReadSuccess || ret_ra == ReadCancel)
|
||||||
return ret_ra;
|
return ret_ra;
|
||||||
|
|
||||||
if (readFile(fn))
|
return readFile(fn);
|
||||||
return ReadSuccess;
|
|
||||||
return ReadFailure;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user