From 773e3d475f9c3f7cc7997feef8a1e469cd801cc1 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Tue, 30 Oct 2007 22:21:48 +0000 Subject: [PATCH] Clean up EmbeddedFiles.h/cpp because the valid_ field is no longer needed git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21304 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/EmbeddedFiles.cpp | 38 +++++------------------ src/EmbeddedFiles.h | 72 +++++++++++++------------------------------ 2 files changed, 30 insertions(+), 80 deletions(-) diff --git a/src/EmbeddedFiles.cpp b/src/EmbeddedFiles.cpp index 98556ca985..97f78d8302 100644 --- a/src/EmbeddedFiles.cpp +++ b/src/EmbeddedFiles.cpp @@ -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); @@ -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); @@ -270,10 +258,9 @@ EmbeddedFile & EmbeddedFiles::registerFile(string const & filename, // find this filename, keep the original embedding status if (it != file_list_.end()) { it->addInset(inset); - it->validate(); return *it; } - // try to be more careful + // file_list_.push_back(EmbeddedFile(abs_filename, getInzipName(abs_filename, inzipName), embed, inset)); return file_list_.back(); @@ -282,16 +269,7 @@ EmbeddedFile & EmbeddedFiles::registerFile(string const & filename, 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); @@ -311,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; @@ -356,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; @@ -368,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; @@ -415,7 +393,7 @@ 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_); } diff --git a/src/EmbeddedFiles.h b/src/EmbeddedFiles.h index 76629b7be2..fa4f2e720d 100644 --- a/src/EmbeddedFiles.h +++ b/src/EmbeddedFiles.h @@ -30,15 +30,23 @@ an 'Embedded Files' feature of lyx. Expected features: ========================= -1. With embedding enabled (disabled by default), .lyx file can embed graphics, -listings, bib file etc. +1. Bundled .lyx file can embed graphics, listings, bib file etc. The bundle +format is used when Document->Save in bundled format is selected. -2. Embedded file.lyx file is a zip file, with file.lyx, manifest.txt -and embedded files. +2. Embedded file.lyx file is a zip file, with content.lyx and embedded files. -3. An embedding dialog is provided to change embedding status (buffer -level or individual embedded files), manually embed, extract, view -or edit files. +3. The embedding status of embedded files can be set at the inset level, +or from Document->Settings->Embedded Files. + +4. Extra files such as .cls and .layout can be embedded from Document-> +Settings->Embedded Files->Extra Files. + +5. When Document->Save in bundled format is selected, all embedded files +become bundled. Changes to the external version of this file does not +affect the output of the .lyx file. + +6. When Document->Save in bundled format is unchecked, all embedded files +are copied to their original locations. Overall, this feature allows two ways of editing a .lyx file @@ -51,57 +59,33 @@ be embedded. These embedded files can be viewed or edited through the embedding dialog. This file can be shared with others more easily. -Format a anb b can be converted easily, by enable/disable embedding. Diabling -embedding is also called unpacking because all embedded files will be copied -to their original locations. +Format a anb b can be converted easily, by packing/unpacking a .lyx file. Implementation: ====================== 1. An EmbeddedFiles class is implemented to keep the embedded files ( class EmbeddedFile). (c.f. src/EmbeddedFiles.[h|cpp]) -This class keeps a manifest that has - a. external relative filename - b. inzip filename. It is the relative path name if the embedded file is - in or under the document directory, or file name otherwise. Name aliasing - is used if two external files share the same name. - c. embedding status. -It also provides functions to - a. manipulate manifest - b. scan a buffer for embeddable files - c. determine which file to use according to embedding status 2. When a file is saved, it is scanned for embedded files. (c.f. EmbeddedFiles::update(), Inset::registerEmbeddedFiles()). -3. When a lyx file file.lyx is saved, it is save to tmppath() first. -Embedded files are compressed along with file.lyx and a manifest.txt. +3. When a lyx file file.lyx is saved, it is save to tmppath()/content.lyx +first. Embedded files are compressed along with content.lyx. If embedding is disabled, file.lyx is saved in the usual pure-text form. (c.f. Buffer::writeFile(), EmbeddedFiles::writeFile()) 4. When a lyx file.lyx file is opened, if it is a zip file, it is -decompressed to tmppath(). If manifest.txt and file.lyx exists in -tmppath(), the manifest is read to buffer, and tmppath()/file.lyx is -read as usual. If file.lyx is not a zip file, it is read as usual. +decompressed to tmppath() and tmppath()/content.lyx is read as usual. (c.f. bool Buffer::readFile()) -5. A menu item Document -> Embedded Files is provided to open -a embedding dialog. It handles a EmbddedFiles point directly. -From this dialog, a user can disable embedding, change embedding status, -or embed other files, extract, view, edit files. +5. A menu item Document -> Save in bundled format is provided to pack/unpack +a .lyx file. 6. If embedding of a .lyx file with embedded files is disabled, all its embedded files are copied to their respective external filenames. This is why external filename will exist even if a file is at "EMBEDDED" status. -7. Individual embeddable insets should find ways to handle embedded files. -InsetGraphics replace params().filename with its temppath()/inzipname version -when the inset is created. The filename appears as /tmp/..../inzipname -when lyx runs. When params().filename is saved, lyx checks if this is an -embedded file (check path == temppath()), if so, save filename() instead. -(c.f. InsetGraphic::read(), InsetGraphics::edit(), InsetGraphicsParams::write()) - - */ namespace lyx { @@ -144,16 +128,6 @@ public: /// to copy or sync the embedded file with external one. void setEmbed(bool embed) { embedded_ = embed; } - // A flag indicating whether or not this filename is valid. - // When lyx runs, InsetGraphics etc may be added or removed so filename - // maybe obsolete. In Buffer::updateEmbeddedFiles, the EmbeddedFiles is first - // invalidated (c.f. invalidate()), and all insets are asked to register - // embedded files. In this way, EmbeddedFileList will be refreshed, with - // status setting untouched. - bool valid() const { return valid_; } - void validate() { valid_ = true; } - void invalidate(); - /// extract file, does not change embedding status bool extract(Buffer const * buf) const; /// update embedded file from external file, does not change embedding status @@ -170,9 +144,7 @@ private: std::string inzip_name_; /// the status of this docfile bool embedded_; - /// - bool valid_; - /// Current position of the item, used to locate the files. Because one + /// Insets that contains this file item. Because a /// file item can be referred by several Insets, a vector is used. std::vector inset_list_; };