X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmover.h;h=79a6a01f998da0015b05a84287f4789999884862;hb=52eb91c94fb70d58dceef430659c8781de2eccda;hp=3e807536016139cf935b9deae4dfc80eb5021819;hpb=e5706b107da902bc6a28cba0de3ccd6f75d9fee7;p=lyx.git diff --git a/src/mover.h b/src/mover.h index 3e80753601..79a6a01f99 100644 --- a/src/mover.h +++ b/src/mover.h @@ -15,6 +15,11 @@ #include #include + +namespace lyx { + +namespace support { class FileName; } + /** * Utility to copy a file of a specified format from one place to another. * This base class simply invokes the command support::copy(). @@ -25,29 +30,63 @@ public: virtual ~Mover() {} /** Copy file @c from to @c to. + * This version should be used to copy files from the original + * location to the temporary directory, since @c to and @c latex + * would be equal in this case. * \returns true if successful. */ bool - copy(std::string const & from, std::string const & to) const + copy(support::FileName const & from, support::FileName const & to, + unsigned long int mode = (unsigned long int)-1) const; + + /** Copy file @c from to @c to. + * \see SpecialisedMover::SpecialisedMover() for an explanation of + * @c latex. + * This version should be used to copy files from the temporary + * directory to the export location, since @c to and @c latex may + * not be equal in this case. + * \returns true if successful. + */ + bool + copy(support::FileName const & from, support::FileName const & to, + std::string const & latex, + unsigned long int mode = (unsigned long int)-1) const { - return do_copy(from, to); + return do_copy(from, to, latex, mode); } /** Rename file @c from as @c to. + * This version should be used to move files from the original + * location to the temporary directory, since @c to and @c latex + * would be equal in this case. + * \returns true if successful. + */ + bool + rename(support::FileName const & from, support::FileName const & to) const; + + /** Rename file @c from as @c to. + * \see SpecialisedMover::SpecialisedMover() for an explanation of + * @c latex. + * This version should be used to move files from the temporary + * directory to the export location, since @c to and @c latex may + * not be equal in this case. * \returns true if successful. */ bool - rename(std::string const & from, std::string const & to) const + rename(support::FileName const & from, support::FileName const & to, + std::string const & latex) const { - return do_rename(from, to); + return do_rename(from, to, latex); } protected: virtual bool - do_copy(std::string const & from, std::string const & to) const; + do_copy(support::FileName const & from, support::FileName const & to, + std::string const &, unsigned long int mode) const; virtual bool - do_rename(std::string const & from, std::string const & to) const; + do_rename(support::FileName const & from, support::FileName const & to, + std::string const &) const; }; @@ -60,17 +99,28 @@ protected: * copied .fig file will require a transformation of the picture file * reference if it is to be found by XFig. */ -struct SpecialisedMover : public Mover +class SpecialisedMover : public Mover { +public: SpecialisedMover() {} + virtual ~SpecialisedMover() {} + /** @c command should be of the form * - * sh $$s/copy_fig.sh $$i $$o + * python $$s/scripts/fig_copy.py $$i $$o $$l * - * where $$s is a placeholder for the lyx script directory, + * where $$s is a placeholder for the lyx support directory, * $$i is a placeholder for the name of the file to be moved, - * $$o is a placeholder for the name of the file after moving. + * $$o is a placeholder for the name of the file after moving, + * $$l is a placeholder for the name of the file after moving, + * suitable as argument to a latex include command. This is + * either an absolute filename or relative to the master + * document. + * $$o and $$l can only differ if the file is copied from the + * temporary directory to the export location. If it is copied + * from the original location to the temporary directory, they + * are the same, so $$l may be ommitted in this case. */ SpecialisedMover(std::string const & command) : command_(command) {} @@ -80,10 +130,12 @@ struct SpecialisedMover : public Mover private: virtual bool - do_copy(std::string const & from, std::string const & to) const; + do_copy(support::FileName const & from, support::FileName const & to, + std::string const & latex, unsigned long int mode) const; virtual bool - do_rename(std::string const & from, std::string const & to) const; + do_rename(support::FileName const & from, support::FileName const & to, + std::string const & latex) const; std::string command_; }; @@ -112,9 +164,9 @@ private: typedef std::map SpecialsMap; public: - typedef SpecialsMap::const_iterator iterator; - iterator begin() const { return specials_.begin(); } - iterator end() const { return specials_.end(); } + typedef SpecialsMap::const_iterator const_iterator; + const_iterator begin() const { return specials_.begin(); } + const_iterator end() const { return specials_.end(); } private: Mover default_; @@ -122,7 +174,16 @@ private: }; -extern Movers movers; -extern Movers system_movers; +extern Movers & theMovers(); +/// @c returns the Mover registered for format @c fmt. +extern Mover const & getMover(std::string const & fmt); +/** Register a specialised @c command to be used to copy a file + * of format @c fmt. + */ +extern void setMover(std::string const & fmt, std::string const & command); +extern Movers & theSystemMovers(); + + +} // namespace lyx #endif // MOVER_H