]> git.lyx.org Git - features.git/commitdiff
Merge readFile and readFile; and readFile and readString.
authorVincent van Ravesteijn <vfr@lyx.org>
Mon, 25 Oct 2010 14:14:44 +0000 (14:14 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Mon, 25 Oct 2010 14:14:44 +0000 (14:14 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35832 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h

index 8e48e5a81b18a02cf6d17d5404cb310d07b9368c..5b7cc8219a3a471c3a511b1326fe56b3ddbb1846 100644 (file)
@@ -835,22 +835,24 @@ bool Buffer::readString(string const & s)
        Lexer lex;
        istringstream is(s);
        lex.setStream(is);
-       FileName const name = FileName::tempName("Buffer_readString");
-       switch (readFile(lex, name, true)) {
-       case ReadFailure:
-               return false;
+       FileName const fn = FileName::tempName("Buffer_readString");
 
-       case ReadWrongVersion: {
+       int file_format;
+       ReadStatus const ret_plf = parseLyXFormat(lex, fn, file_format);
+       if (ret_plf != ReadSuccess)
+               return ret_plf;
+
+       if (file_format != LYX_FORMAT) {
                // We need to call lyx2lyx, so write the input to a file
-               ofstream os(name.toFilesystemEncoding().c_str());
+               ofstream os(fn.toFilesystemEncoding().c_str());
                os << s;
                os.close();
-               return readFile(name);
-       }
-       default:
-               break;
+               // lyxvc in readFile
+               return readFile(fn) == ReadSuccess;
        }
 
+       if (readDocument(lex))
+               return false;
        return true;
 }
 
@@ -861,10 +863,28 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn)
        Lexer lex;
        lex.setFile(fname);
 
-       ReadStatus const ret_rf = readFile(lex, fname);
-       if (ret_rf != ReadSuccess)
-               return ret_rf;
+       int file_format;
+       ReadStatus const ret_plf = parseLyXFormat(lex, fn, file_format);
+       if (ret_plf != ReadSuccess)
+               return ret_plf;
+
+       if (file_format != LYX_FORMAT) {
+               FileName tmpFile;
+               ReadStatus const ret_clf = convertLyXFormat(fn, tmpFile, file_format);
+               if (ret_clf != ReadSuccess)
+                       return ret_clf;
+               return readFile(tmpFile);
+       }
+
+       if (readDocument(lex)) {
+               Alert::error(_("Document format failure"),
+                       bformat(_("%1$s ended unexpectedly, which means"
+                               " that it is probably corrupted."),
+                                       from_utf8(fn.absFileName())));
+               return ReadDocumentFailure;
+       }
 
+       d->file_fully_loaded = true;
        // InsetInfo needs to know if file is under VCS
        lyxvc().file_found_hook(fn);
        d->read_only = !fname.isWritable();
@@ -969,40 +989,6 @@ Buffer::ReadStatus Buffer::convertLyXFormat(FileName const & fn,
 }
 
 
-Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & fn,
-               bool fromstring)
-{
-       int file_format;
-       ReadStatus const ret_plf = parseLyXFormat(lex, fn, file_format);
-       if (ret_plf != ReadSuccess)
-               return ret_plf;
-
-       if (file_format != LYX_FORMAT) {
-               if (fromstring)
-                       // lyx2lyx would fail
-                       return ReadWrongVersion;
-
-               FileName tmpFile;
-               ReadStatus const ret_clf = convertLyXFormat(fn, tmpFile, file_format);
-               if (ret_clf != ReadSuccess)
-                       return ret_clf;
-               else
-                       return readFile(tmpFile);
-       }
-
-       if (readDocument(lex)) {
-               Alert::error(_("Document format failure"),
-                            bformat(_("%1$s ended unexpectedly, which means"
-                                                   " that it is probably corrupted."),
-                                      from_utf8(fn.absFileName())));
-               return ReadDocumentFailure;
-       }
-
-       d->file_fully_loaded = true;
-       return ReadSuccess;
-}
-
-
 // Should probably be moved to somewhere else: BufferView? GuiView?
 bool Buffer::save() const
 {
index c5e09de014c3509f415d0c433fbec43db73f745d..97c339d198ea7bcafe7e1bf0495a54a447b7a7f7 100644 (file)
@@ -638,11 +638,6 @@ public:
 private:
        ///
        std::vector<std::string> backends() const;
-       /** Inserts a file into a document
-           \return \c false if method fails.
-       */
-       ReadStatus readFile(Lexer &, support::FileName const & filename,
-                           bool fromString = false);
        ///
        void getLanguages(std::set<Language const *> &) const;
        /// Update the list of all bibfiles in use (including bibfiles