]> git.lyx.org Git - lyx.git/blobdiff - src/EmbeddedFiles.cpp
* gcc does not like missing characters in keywords
[lyx.git] / src / EmbeddedFiles.cpp
index 73db1e4bda2a021775e1e7bec76672af360d052b..97f78d83024d69ece7a2df18bb4665a5889dc8e5 100644 (file)
@@ -74,7 +74,7 @@ using support::makedir;
 EmbeddedFile::EmbeddedFile(string const & file, string const & inzip_name,
        bool embed, Inset const * inset)
        : DocFileName(file, true), inzip_name_(inzip_name), embedded_(embed),
-               valid_(true), inset_list_()
+               inset_list_()
 {
        if (inset != NULL)
                inset_list_.push_back(inset);
@@ -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(),
@@ -125,24 +125,12 @@ void EmbeddedFile::saveBookmark(Buffer const * buf, int idx) const
 
 string EmbeddedFile::availableFile(Buffer const * buf) const
 {
-       if (embedded())
-               return embeddedFile(buf);
-       else
-               return absFilename();
-}
-
-
-void EmbeddedFile::invalidate()
-{
-       // Clear inset_list_ because they will be registered again.
-       inset_list_.clear();
-       valid_ = false;
+       return embedded() ? embeddedFile(buf) : absFilename();
 }
 
 
 bool EmbeddedFile::extract(Buffer const * buf) const
 {
-
        string ext_file = absFilename();
        string emb_file = embeddedFile(buf);
 
@@ -199,7 +187,7 @@ bool EmbeddedFile::updateFromExternalFile(Buffer const * buf) const
                // other wise, ask if overwrite
                int const ret = Alert::prompt(
                        _("Update embedded file?"),
-                       bformat(_("Embeddedl file %1$s already exists, do you want to overwrite it"),
+                       bformat(_("Embedded file %1$s already exists, do you want to overwrite it"),
                                from_utf8(ext_file)), 1, 1, _("&Overwrite"), _("&Cancel"));
                if (ret != 0)
                        // if the user does not want to overwrite, we still consider it
@@ -256,7 +244,7 @@ void EmbeddedFiles::enable(bool flag)
 }
 
 
-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
@@ -270,27 +258,18 @@ void EmbeddedFiles::registerFile(string const & filename,
        // find this filename, keep the original embedding status
        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();
 }
 
 
 void EmbeddedFiles::update()
 {
-       // invalidate all files, obsolete files will then not be validated by the
-       // following document scan. These files will still be kept though, because
-       // they may be added later and their embedding status will be meaningful
-       // again (thinking of cut/paste of an InsetInclude).
-       EmbeddedFileList::iterator it = file_list_.begin();
-       EmbeddedFileList::iterator it_end = file_list_.end();
-       for (; it != it_end; ++it)
-               // we do not update items that are manually inserted
-               if (it->refCount() > 0)
-                       it->invalidate();
+       file_list_.clear();
 
        for (InsetIterator it = inset_iterator_begin(buffer_->inset()); it; ++it)
                it->registerEmbeddedFiles(*buffer_, *this);
@@ -310,7 +289,7 @@ bool EmbeddedFiles::writeFile(DocFileName const & filename)
        EmbeddedFileList::iterator it = file_list_.begin();
        EmbeddedFileList::iterator it_end = file_list_.end();
        for (; it != it_end; ++it) {
-               if (it->valid() && it->embedded()) {
+               if (it->embedded()) {
                        string file = it->availableFile(buffer_);
                        if (file.empty())
                                lyxerr << "File " << it->absFilename() << " does not exist. Skip embedding it. " << endl;
@@ -355,7 +334,7 @@ bool EmbeddedFiles::extract() const
        EmbeddedFileList::const_iterator it = file_list_.begin();
        EmbeddedFileList::const_iterator it_end = file_list_.end();
        for (; it != it_end; ++it)
-               if (it->valid() && it->embedded())
+               if (it->embedded())
                        if(!it->extract(buffer_))
                                return false;
        return true;
@@ -367,7 +346,7 @@ bool EmbeddedFiles::updateFromExternalFile() const
        EmbeddedFileList::const_iterator it = file_list_.begin();
        EmbeddedFileList::const_iterator it_end = file_list_.end();
        for (; it != it_end; ++it)
-               if (it->valid() && it->embedded())
+               if (it->embedded())
                        if (!it->updateFromExternalFile(buffer_))
                                return false;
        return true;
@@ -409,82 +388,12 @@ 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
-{
-       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';
-       }
-}
-
-
 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() && it->refCount() > 0)
+               if (it->refCount() > 0)
                        it->updateInsets(buffer_);
 }