From 75773f3c2257bfc273ba3f5a180ec76ba98954ee Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Mon, 25 Oct 2010 10:18:42 +0000 Subject: [PATCH] Use Buffer::ReadStatus as a return value for Buffer::loadLyXFile. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35818 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 38 ++++++++++++++++++------------------- src/Buffer.h | 9 +++++---- src/BufferView.cpp | 2 +- src/LyX.cpp | 2 +- src/buffer_funcs.cpp | 4 ++-- src/insets/InsetInclude.cpp | 2 +- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 0013804d77..7321bcec52 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -839,16 +839,16 @@ bool Buffer::readString(string const & s) lex.setStream(is); FileName const name = FileName::tempName("Buffer_readString"); switch (readFile(lex, name, true)) { - case failure: + case ReadFailure: return false; - case wrongversion: { + case ReadWrongVersion: { // We need to call lyx2lyx, so write the input to a file ofstream os(name.toFilesystemEncoding().c_str()); os << s; os.close(); return readFile(name); } - case success: + case ReadSuccess: break; } @@ -866,7 +866,7 @@ bool Buffer::readFile(FileName const & filename) paragraphs().clear(); Lexer lex; lex.setFile(fname); - if (readFile(lex, fname) != success) + if (readFile(lex, fname) != ReadSuccess) return false; return true; @@ -895,7 +895,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, Alert::error(_("Document format failure"), bformat(_("%1$s is not a readable LyX document."), from_utf8(filename.absFileName()))); - return failure; + return ReadFailure; } string tmp_format; @@ -926,7 +926,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, if (fromstring) // lyx2lyx would fail - return wrongversion; + return ReadWrongVersion; FileName const tmpfile = FileName::tempName("Buffer_readFile"); if (tmpfile.empty()) { @@ -936,7 +936,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, " file for converting it could" " not be created."), from_utf8(filename.absFileName()))); - return failure; + return ReadFailure; } FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx"); if (lyx2lyx.empty()) { @@ -946,7 +946,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, " conversion script lyx2lyx" " could not be found."), from_utf8(filename.absFileName()))); - return failure; + return ReadFailure; } ostringstream command; command << os::python() @@ -972,11 +972,11 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, " of LyX and cannot be converted by the" " lyx2lyx script."), from_utf8(filename.absFileName()))); - return failure; + return ReadFailure; } else { bool const ret = readFile(tmpfile); // Do stuff with tmpfile name and buffer name here. - return ret ? success : failure; + return ret ? ReadSuccess : ReadFailure; } } @@ -986,11 +986,11 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, bformat(_("%1$s ended unexpectedly, which means" " that it is probably corrupted."), from_utf8(filename.absFileName()))); - return failure; + return ReadFailure; } d->file_fully_loaded = true; - return success; + return ReadSuccess; } @@ -3620,7 +3620,7 @@ bool Buffer::readFileHelper(FileName const & s) docstring str; bool res; - if ((res = readFile(e)) == success) + if (res = readFile(e)) str = _("Document was successfully recovered."); else str = _("Document was NOT successfully recovered."); @@ -3630,7 +3630,7 @@ bool Buffer::readFileHelper(FileName const & s) if (!Alert::prompt(_("Delete emergency file?"), str, 1, 1, _("&Remove"), _("&Keep it"))) { e.removeFile(); - if (res == success) + if (res) Alert::warning(_("Emergency file deleted"), _("Do not forget to save your file now!"), true); } @@ -3676,23 +3676,23 @@ bool Buffer::readFileHelper(FileName const & s) } -bool Buffer::loadLyXFile(FileName const & s) +Buffer::ReadStatus Buffer::loadLyXFile(FileName const & s) { // If the file is not readable, we try to // retrieve the file from version control. if (!s.isReadableFile() && !LyXVC::file_not_found_hook(s)) - return false; + return ReadFailure; if (s.isReadableFile()){ // InsetInfo needs to know if file is under VCS lyxvc().file_found_hook(s); if (readFileHelper(s)) { d->read_only = !s.isWritable(); - return true; + return ReadSuccess; } } - return false; + return ReadFailure; } @@ -4067,7 +4067,7 @@ bool Buffer::reload() d->filename.refresh(); docstring const disp_fn = makeDisplayPath(d->filename.absFileName()); - bool const success = loadLyXFile(d->filename); + bool const success = (loadLyXFile(d->filename) == ReadSuccess); if (success) { updateBuffer(); changed(true); diff --git a/src/Buffer.h b/src/Buffer.h index a9696812bf..54a719186a 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -95,9 +95,10 @@ public: /// Result of \c readFile() enum ReadStatus { - failure, ///< The file could not be read - success, ///< The file could not be read - wrongversion ///< The version of the file does not match ours + ReadSuccess, + ReadCancel, + ReadFailure, + ReadWrongVersion }; @@ -186,7 +187,7 @@ public: bool writeFile(support::FileName const &) const; /// Loads LyX file \c filename into buffer, * and return success - bool loadLyXFile(support::FileName const & s); + ReadStatus loadLyXFile(support::FileName const & s); /// Reloads the LyX file bool reload(); diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 8dbd511def..338a55aa5c 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -2507,7 +2507,7 @@ void BufferView::insertLyXFile(FileName const & fname) docstring res; Buffer buf("", false); - if (buf.loadLyXFile(filename)) { + if (buf.loadLyXFile(filename) == Buffer::ReadSuccess) { ErrorList & el = buffer_.errorList("Parse"); // Copy the inserted document error list into the current buffer one. el = buf.errorList("Parse"); diff --git a/src/LyX.cpp b/src/LyX.cpp index 4992de8e73..9cd448ea0b 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -496,7 +496,7 @@ bool LyX::loadFiles() continue; Buffer * buf = pimpl_->buffer_list_.newBuffer(fname.absFileName(), false); - if (buf->loadLyXFile(fname)) { + if (buf->loadLyXFile(fname) == Buffer::ReadSuccess) { ErrorList const & el = buf->errorList("Parse"); if (!el.empty()) for_each(el.begin(), el.end(), diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 6b582b6802..5b972e5e0a 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -94,7 +94,7 @@ Buffer * checkAndLoadLyXFile(FileName const & filename, bool const acceptDirty) // Buffer creation is not possible. return 0; } - if (!b->loadLyXFile(filename)) { + if (b->loadLyXFile(filename) != Buffer::ReadSuccess) { // do not save an emergency file when releasing the buffer b->markClean(); theBufferList().release(b); @@ -268,7 +268,7 @@ Buffer * loadIfNeeded(FileName const & fname) // Buffer creation is not possible. return 0; - if (!buffer->loadLyXFile(fname)) { + if (buffer->loadLyXFile(fname) != Buffer::ReadSuccess) { //close the buffer we just opened theBufferList().release(buffer); return 0; diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 7818d05a4d..ed49764750 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -440,7 +440,7 @@ Buffer * InsetInclude::loadIfNeeded() const // Buffer creation is not possible. return 0; - if (!child->loadLyXFile(included_file)) { + if (child->loadLyXFile(included_file) != Buffer::ReadSuccess) { failedtoload_ = true; //close the buffer we just opened theBufferList().release(child);