]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Fulfill promise to Andre: TextClass_ptr --> TextClassPtr.
[lyx.git] / src / Buffer.cpp
index 3eeb7d0d1b4dd1f8e8d2efe87c5ca1f75b009d7f..19d479cc9b2c8f1b1826723d22f479045b3dddfc 100644 (file)
@@ -142,7 +142,7 @@ namespace fs = boost::filesystem;
 
 namespace {
 
-int const LYX_FORMAT = 282;
+int const LYX_FORMAT = 285;
 
 } // namespace anon
 
@@ -531,8 +531,9 @@ bool Buffer::readDocument(Lexer & lex)
        BOOST_ASSERT(paragraphs().empty());
 
        readHeader(lex);
-       if (!params().getTextClass().load(filePath())) {
-               string theclass = params().getTextClass().name();
+       TextClass const & baseClass = textclasslist[params().getBaseClass()];
+       if (!baseClass.load(filePath())) {
+               string theclass = baseClass.name();
                Alert::error(_("Can't load document class"), bformat(
                        _("Using the default document class, because the "
                                     "class %1$s could not be loaded."), from_utf8(theclass)));
@@ -558,7 +559,10 @@ bool Buffer::readDocument(Lexer & lex)
                                         "\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
                }
        }
+       // read manifest after header
+       embeddedFiles().readManifest(lex, errorList);   
 
+       // read main text
        bool const res = text().read(*this, lex, errorList);
        for_each(text().paragraphs().begin(),
                 text().paragraphs().end(),
@@ -660,20 +664,11 @@ bool Buffer::readFile(FileName const & filename)
                LYXERR(Debug::FILES) << filename << " is in zip format. Unzip to " << temppath() << endl;
                ::unzipToDir(filename.toFilesystemEncoding(), temppath());
                //
-               FileName manifest(addName(temppath(), "manifest.txt"));
-               FileName lyxfile(addName(temppath(), 
-                       onlyFilename(filename.toFilesystemEncoding())));
+               FileName lyxfile(addName(temppath(), "content.lyx"));
                // if both manifest.txt and file.lyx exist, this is am embedded file
-               if (fs::exists(manifest.toFilesystemEncoding()) &&
-                       fs::exists(lyxfile.toFilesystemEncoding())) {
+               if (fs::exists(lyxfile.toFilesystemEncoding())) {
                        params().embedded = true;
                        fname = lyxfile;
-                       // read manifest file
-                       ifstream is(manifest.toFilesystemEncoding().c_str());
-                       is >> pimpl_->embedded_files;
-                       is.close();
-                       LYXERR(Debug::FILES) << filename << " is a embedded file. Its manifest is:\n"
-                                       << pimpl_->embedded_files;
                }
        }
        // The embedded lyx file can also be compressed, for backward compatibility
@@ -756,8 +751,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                string diskfile = filename.toFilesystemEncoding();
                if (suffixIs(diskfile, ".emergency"))
                        diskfile = diskfile.substr(0, diskfile.size() - 10);
-               pimpl_->timestamp_ = fs::last_write_time(diskfile);
-               pimpl_->checksum_ = sum(FileName(diskfile));
+               saveCheckSum(diskfile);
        }
 
        if (file_format != LYX_FORMAT) {
@@ -874,8 +868,7 @@ bool Buffer::save() const
        if (writeFile(pimpl_->filename)) {
                markClean();
                removeAutosaveFile(fileName());
-               pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename.toFilesystemEncoding());
-               pimpl_->checksum_ = sum(pimpl_->filename);
+               saveCheckSum(pimpl_->filename.toFilesystemEncoding());
                return true;
        } else {
                // Saving failed, so backup is not backup
@@ -896,8 +889,7 @@ bool Buffer::writeFile(FileName const & fname) const
        FileName content;
        if (params().embedded)
                // first write the .lyx file to the temporary directory
-               content = FileName(addName(temppath(), 
-                       onlyFilename(fname.toFilesystemEncoding())));
+               content = FileName(addName(temppath(), "content.lyx"));
        else
                content = fname;
        
@@ -917,9 +909,8 @@ bool Buffer::writeFile(FileName const & fname) const
 
        if (retval && params().embedded) {
                // write file.lyx and all the embedded files to the zip file fname
-               // if embedding is enabled, and there is any embedded file
-               pimpl_->embedded_files.update();
-               return pimpl_->embedded_files.write(fname);
+               // if embedding is enabled
+               return pimpl_->embedded_files.writeFile(fname);
        }
        return retval;
 }
@@ -958,6 +949,12 @@ bool Buffer::write(ostream & ofs) const
        params().writeFile(ofs);
        ofs << "\\end_header\n";
 
+       // write the manifest after header
+       ofs << "\n\\begin_manifest\n";
+       pimpl_->embedded_files.update();
+       embeddedFiles().writeManifest(ofs);
+       ofs << "\\end_manifest\n";
+
        // write the text
        ofs << "\n\\begin_body\n";
        text().write(*this, ofs);
@@ -1634,6 +1631,19 @@ bool Buffer::isExternallyModified(CheckMethod method) const
 }
 
 
+void Buffer::saveCheckSum(string const & file) const
+{
+       if (fs::exists(file)) {
+               pimpl_->timestamp_ = fs::last_write_time(file);
+               pimpl_->checksum_ = sum(FileName(file));
+       } else {
+               // in the case of save to a new file.
+               pimpl_->timestamp_ = 0;
+               pimpl_->checksum_ = 0;
+       }
+}
+
+
 void Buffer::markClean() const
 {
        if (!pimpl_->lyx_clean) {
@@ -1730,7 +1740,10 @@ Buffer * Buffer::getMasterBuffer()
        if (!params().parentname.empty()
            && theBufferList().exists(params().parentname)) {
                Buffer * buf = theBufferList().getBuffer(params().parentname);
-               if (buf)
+               //We need to check if the parent is us...
+               //FIXME RECURSIVE INCLUDE
+               //This is not sufficient, since recursive includes could be downstream.
+               if (buf && buf != this)
                        return buf->getMasterBuffer();
        }