4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
21 namespace support { class FileName; }
24 * Utility to copy a file of a specified format from one place to another.
25 * This base class simply invokes the command support::copy().
32 /** Copy file @c from to @c to.
33 * This version should be used to copy files from the original
34 * location to the temporary directory, since @c to and @c latex
35 * would be equal in this case.
36 * \returns true if successful.
39 copy(support::FileName const & from, support::FileName const & to) const;
41 /** Copy file @c from to @c to.
42 * \see SpecialisedMover::SpecialisedMover() for an explanation of
44 * This version should be used to copy files from the temporary
45 * directory to the export location, since @c to and @c latex may
46 * not be equal in this case.
47 * \returns true if successful.
50 copy(support::FileName const & from, support::FileName const & to,
51 std::string const & latex) const
53 return do_copy(from, to, latex);
56 /** Rename file @c from as @c to.
57 * This version should be used to move files from the original
58 * location to the temporary directory, since @c to and @c latex
59 * would be equal in this case.
60 * \returns true if successful.
63 rename(support::FileName const & from, support::FileName const & to) const;
65 /** Rename file @c from as @c to.
66 * \see SpecialisedMover::SpecialisedMover() for an explanation of
68 * This version should be used to move files from the temporary
69 * directory to the export location, since @c to and @c latex may
70 * not be equal in this case.
71 * \returns true if successful.
74 rename(support::FileName const & from, support::FileName const & to,
75 std::string const & latex) const
77 return do_rename(from, to, latex);
82 do_copy(support::FileName const & from, support::FileName const & to,
83 std::string const &) const;
86 do_rename(support::FileName const & from, support::FileName const & to,
87 std::string const &) const;
92 * Specialisation of the Mover concept that uses an external command
95 * For example, an Xfig .fig file can contain references to external
96 * picture files. If such a reference has a relative path, then the
97 * copied .fig file will require a transformation of the picture file
98 * reference if it is to be found by Xfig.
100 class SpecialisedMover : public Mover
103 SpecialisedMover() {}
105 virtual ~SpecialisedMover() {}
107 /** @c command should be of the form
109 * python $$s/scripts/fig_copy.py $$i $$o $$l
111 * where $$s is a placeholder for the lyx support directory,
112 * $$i is a placeholder for the name of the file to be moved,
113 * $$o is a placeholder for the name of the file after moving,
114 * $$l is a placeholder for the name of the file after moving,
115 * suitable as argument to a latex include command. This is
116 * either an absolute filename or relative to the master
118 * $$o and $$l can only differ if the file is copied from the
119 * temporary directory to the export location. If it is copied
120 * from the original location to the temporary directory, they
121 * are the same, so $$l may be ommitted in this case.
123 SpecialisedMover(std::string const & command)
124 : command_(command) {}
126 /// The template used to launch the external command.
127 std::string const & command() const { return command_; }
131 do_copy(support::FileName const & from, support::FileName const & to,
132 std::string const & latex) const;
135 do_rename(support::FileName const & from, support::FileName const & to,
136 std::string const & latex) const;
138 std::string command_;
143 * Manage the store of (Mover)s.
148 /** Register a specialised @c command to be used to copy a file
151 void set(std::string const & fmt, std::string const & command);
153 /// @c returns the Mover registered for format @c fmt.
154 Mover const & operator()(std::string const & fmt) const;
156 /** @returns the command template if @c fmt 'finds' a
157 * SpecialisedMover. Otherwise, returns an empty string.
159 std::string const command(std::string const & fmt) const;
162 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
165 typedef SpecialsMap::const_iterator const_iterator;
166 const_iterator begin() const { return specials_.begin(); }
167 const_iterator end() const { return specials_.end(); }
171 SpecialsMap specials_;
175 extern Movers & theMovers();
176 /// @c returns the Mover registered for format @c fmt.
177 extern Mover const & getMover(std::string const & fmt);
178 /** Register a specialised @c command to be used to copy a file
181 extern void setMover(std::string const & fmt, std::string const & command);
182 extern Movers & theSystemMovers();