]> git.lyx.org Git - lyx.git/blobdiff - src/EmbeddedFiles.cpp
* Paragraph: erase unused some method and move some members to Paragraph::Private.
[lyx.git] / src / EmbeddedFiles.cpp
index 28add45c67de952b707a1bd272077ee6096421a2..4255a3023e7abc3573ffc7600a9bfd5e98c0244e 100644 (file)
@@ -109,7 +109,7 @@ void EmbeddedFile::saveBookmark(Buffer const * buf, int idx) const
                if (&(*it) == ptr) {
                        // this is basically BufferView::saveBookmark(0)
                        LyX::ref().session().bookmarks().save(
-                               FileName(buf->fileName()),
+                               FileName(buf->absFileName()),
                                it.bottom().pit(),
                                it.bottom().pos(),
                                it.paragraph().id(),
@@ -225,27 +225,38 @@ bool EmbeddedFile::updateFromExternalFile(Buffer const * buf) const
 }
 
 
+void EmbeddedFile::updateInsets(Buffer const * buf) const
+{
+       vector<Inset const *>::const_iterator it = inset_list_.begin();
+       vector<Inset const *>::const_iterator it_end = inset_list_.end();
+       for (; it != it_end; ++it)
+               const_cast<Inset *>(*it)->updateEmbeddedFile(*buf, *this);
+}
+
+
 bool EmbeddedFiles::enabled() const
 {
        return buffer_->params().embedded;
 }
 
 
-bool EmbeddedFiles::enable(bool flag)
+void EmbeddedFiles::enable(bool flag)
 {
        if (enabled() != flag) {
                // if enable, copy all files to temppath()
                // if disable, extract all files
                if ((flag && !updateFromExternalFile()) || (!flag && !extract()))
-                       return false;
+                       return;
                // if operation is successful
                buffer_->markDirty();
                buffer_->params().embedded = flag;
+               if (flag)
+                       updateInsets();
        }
 }
 
 
-void EmbeddedFiles::registerFile(string const & filename,
+EmbeddedFile & EmbeddedFiles::registerFile(string const & filename,
        bool embed, Inset const * inset, string const & inzipName)
 {
        // filename can be relative or absolute, translate to absolute filename
@@ -260,11 +271,12 @@ void EmbeddedFiles::registerFile(string const & filename,
        if (it != file_list_.end()) {
                it->addInset(inset);
                it->validate();
-               return;
+               return *it;
        }
        // try to be more careful
        file_list_.push_back(EmbeddedFile(abs_filename, 
                getInzipName(abs_filename, inzipName), embed, inset));
+       return file_list_.back();
 }
 
 
@@ -398,73 +410,13 @@ string const EmbeddedFiles::getInzipName(string const & abs_filename, string con
 }
 
 
-bool EmbeddedFiles::readManifest(Lexer & lex, ErrorList & errorList)
-{
-       int line = -1;
-       int begin_manifest_line = -1;
-
-       file_list_.clear();
-       string filename;
-       string inzipName;
-       bool embedded = false;
-
-       while (lex.isOK()) {
-               lex.next();
-               string const token = lex.getString();
-
-               if (token.empty())
-                       continue;
-
-               if (token == "\\end_manifest")
-                       break;
-
-               ++line;
-               if (token == "\\begin_manifest") {
-                       begin_manifest_line = line;
-                       continue;
-               }
-               
-               LYXERR(Debug::PARSER) << "Handling document manifest token: `"
-                                     << token << '\'' << endl;
-
-               if (token == "\\filename")
-                       lex >> filename;
-               else if (token == "\\inzipName")
-                       lex >> inzipName;
-               else if (token == "\\embed") {
-                       lex >> embedded;
-                       registerFile(filename, embedded, NULL, inzipName);
-                       filename = "";
-                       inzipName = "";
-               } else {
-                       docstring const s = _("\\begin_file is missing");
-                       errorList.push_back(ErrorItem(_("Manifest error"),
-                               s, -1, 0, 0));
-               }
-       }
-       if (begin_manifest_line) {
-               docstring const s = _("\\begin_manifest is missing");
-               errorList.push_back(ErrorItem(_("Manifest error"),
-                       s, -1, 0, 0));
-       }
-       return true;
-}
-
-
-void EmbeddedFiles::writeManifest(ostream & os) const
+void EmbeddedFiles::updateInsets() const
 {
        EmbeddedFiles::EmbeddedFileList::const_iterator it = begin();
        EmbeddedFiles::EmbeddedFileList::const_iterator it_end = end();
-       for (; it != it_end; ++it) {
-               if (!it->valid())
-                       continue;
-               // save the relative path
-               os << "\\filename "
-                       << to_utf8(makeRelPath(from_utf8(it->absFilename()),
-                               from_utf8(buffer_->filePath()))) << '\n'
-                       << "\\inzipName " << it->inzipName() << '\n'
-                       << "\\embed " << (it->embedded() ? "true" : "false") << '\n';
-       }
+       for (; it != it_end; ++it)
+               if (it->valid() && it->refCount() > 0)
+                       it->updateInsets(buffer_);
 }