]> git.lyx.org Git - lyx.git/blobdiff - src/EmbeddedFiles.h
adjust
[lyx.git] / src / EmbeddedFiles.h
index 4d4ac014f11e54496ab5e20128ba0c6425eeb231..1d526973d3cbafd6abc1179aea28e4fc71fa48e6 100644 (file)
@@ -77,7 +77,7 @@ 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. 
 If embedding is disabled, file.lyx is saved in the usual pure-text form.
-(c.f. Buffer::writeFile(), EmbeddedFiles::write())
+(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
@@ -107,34 +107,42 @@ embedded file (check path == temppath()), if so, save filename() instead.
 namespace lyx {
 
 class Buffer;
+class Lexer;
+class ErrorList;
 
 class EmbeddedFile : public support::DocFileName
 {
 public:
+       EmbeddedFile() {};
+
        EmbeddedFile(std::string const & file, std::string const & inzip_name,
-               bool embedded, ParConstIterator const & pit);
+               bool embedded, Inset const * inset);
 
        /// filename in the zip file, usually the relative path
        std::string inzipName() const { return inzip_name_; }
+       void setInzipName(std::string name) { inzip_name_ = name; }
        /// embedded file, equals to temppath()/inzipName()
        std::string embeddedFile(Buffer const * buf) const;
        /// embeddedFile() or absFilename() depending on embedding status
        std::string availableFile(Buffer const * buf) const;
 
-       /// paragraph id
-       void addParIter(ParConstIterator const & pit);
-       int parID(int idx) const;
+       /// add an inset that refers to this file
+       void addInset(Inset const * inset);
+       Inset const * inset(int idx) const;
+       /// save the location of this inset as bookmark so that
+       /// it can be located using LFUN_BOOKMARK_GOTO
+       void saveBookmark(Buffer const * buf, int idx) const;
        /// Number of Insets this file item is referred
        /// If refCount() == 0, this file must be manually inserted.
        /// This fact is used by the update() function to skip updating
        /// such items.
-       int refCount() const { return par_it_.size(); }
+       int refCount() const { return inset_list_.size(); }
 
        /// embedding status of this file
        bool embedded() const { return embedded_; }
        /// set embedding status. updateFromExternal() should be called before this
        /// to copy or sync the embedded file with external one.
-       bool setEmbed(bool embed) { embedded_ = embed; }
+       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
@@ -150,6 +158,12 @@ public:
        bool extract(Buffer const * buf) const;
        /// update embedded file from external file, does not change embedding status
        bool updateFromExternalFile(Buffer const * buf) const;
+       ///
+       /// After the embedding status is changed, update all insets related
+       /// to this file item.
+       /// Because inset pointers may not be up to date, EmbeddedFiles::update()
+       /// would better be called before this function is called.
+       void updateInsets(Buffer const * buf) const;
 
 private:
        /// filename in zip file
@@ -160,7 +174,7 @@ private:
        bool valid_;
        /// Current position of the item, used to locate the files. Because one
        /// file item can be referred by several Insets, a vector is used.
-       std::vector<ParConstIterator> par_it_;
+       std::vector<Inset const *> inset_list_;
 };
 
 
@@ -169,7 +183,7 @@ public:
        typedef std::vector<EmbeddedFile> EmbeddedFileList;
 public:
        ///
-       EmbeddedFiles(Buffer * buffer = NULL): file_list_(), buffer_(buffer) {}
+       EmbeddedFiles(Buffer * buffer = 0) : file_list_(), buffer_(buffer) {}
        ///
        ~EmbeddedFiles() {}
 
@@ -177,22 +191,24 @@ public:
        bool enabled() const;
        /// set buffer params embedded flag. Files will be updated or extracted
        /// if such an operation fails, enable will fail.
-       bool enable(bool flag);
+       void enable(bool flag);
 
        /// add a file item. 
        /* \param filename filename to add
         * \param embed embedding status. For a new file item, this is always true.
         *    If the file already exists, this parameter is ignored.
-        * \param pit paragraph id.
+        * \param inset Inset pointer
+        * \param inzipName suggested inzipname
         */
-       void registerFile(std::string const & filename, bool embed = false,
-               ParConstIterator const & pit = ParConstIterator());
+       EmbeddedFile & registerFile(std::string const & filename, bool embed = false,
+               Inset const * inset = 0,
+               std::string const & inzipName = std::string());
 
        /// scan the buffer and get a list of EmbeddedFile
        void update();
 
        /// write a zip file
-       bool write(support::DocFileName const & filename);
+       bool writeFile(support::DocFileName const & filename);
 
        void clear() { file_list_.clear(); }
 
@@ -211,22 +227,19 @@ public:
        /// update all files from external, used when enable embedding
        bool updateFromExternalFile() const;
        ///
-       friend std::istream & operator>> (std::istream & is, EmbeddedFiles &);
-
-       friend std::ostream & operator<< (std::ostream & os, EmbeddedFiles const &);
+       bool readManifest(Lexer & lex, ErrorList & errorList);
+       void writeManifest(std::ostream & os) const;
+       /// update all insets to use embedded files when embedding status is changed
+       void updateInsets() const;
 private:
-       /// get a unique inzip name
-       std::string const getInzipName(std::string const & name);
+       /// get a unique inzip name, a suggestion can be given.
+       std::string const getInzipName(std::string const & name, std::string const & inzipName);
        /// list of embedded files
        EmbeddedFileList file_list_;
        ///
        Buffer * buffer_;
 };
 
+} // namespace lyx
 
-std::istream & operator>> (std::istream & is, EmbeddedFiles &);
-
-std::ostream & operator<< (std::ostream & os, EmbeddedFiles const &);
-
-}
 #endif