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.
35 * \returns true if successful.
38 copy(support::FileName const & from, support::FileName const & to) const;
40 /** Copy file @c from to @c to.
41 * \see SpecialisedMover::SpecialisedMover() for an explanation of
43 * This version should be used to copy files from the temporary
44 * directory to the export location, since @c to and @c latex may
45 * not be equal in this case.
46 * \returns true if successful.
47 * NOTE: Although this routine simply calls do_copy() and
48 * Mover::do_copy() does not itself make any use of the @c latex argument,
49 * SpecialisedMover overrides do_copy(), so SpecialisedMover::copy(), which
50 * is just Mover::copy(), calls SpecialisedMover::do_copy(), and the @c latex
51 * argument IS in that case used.
54 copy(support::FileName const & from, support::FileName const & to,
55 std::string const & latex) const
57 return do_copy(from, to, latex);
60 /** Rename file @c from as @c to.
61 * This version should be used to move files from the original
62 * location to the temporary directory.
63 * \returns true if successful.
66 rename(support::FileName const & from, support::FileName const & to) const;
68 /** Rename file @c from as @c to.
69 * \see SpecialisedMover::SpecialisedMover() for an explanation of
71 * This version should be used to move files from the temporary
72 * directory to the export location, since @c to and @c latex may
73 * not be equal in this case.
74 * \returns true if successful.
77 rename(support::FileName const & from, support::FileName const & to,
78 std::string const & latex) const
80 return do_rename(from, to, latex);
85 do_copy(support::FileName const & from, support::FileName const & to,
86 std::string const &) const;
89 do_rename(support::FileName const & from, support::FileName const & to,
90 std::string const &) const;
95 * Specialisation of the Mover concept that uses an external command
98 * For example, an Xfig .fig file can contain references to external
99 * picture files. If such a reference has a relative path, then the
100 * copied .fig file will require a transformation of the picture file
101 * reference if it is to be found by Xfig.
103 * So, in this case, we need three arguments:
104 * (i) @c from the location of the file to be moved
105 * (ii) @c to the location to which it should be moved
106 * (iii) @c latex the identifier that should be used in the sort of
107 * transformation just mentioned.
109 class SpecialisedMover : public Mover
112 SpecialisedMover() {}
114 virtual ~SpecialisedMover() {}
116 /** @c command should be of the form
118 * python $$s/scripts/fig_copy.py $$i $$o $$l
120 * where $$s is a placeholder for the lyx support directory,
121 * $$i is a placeholder for the name of the file to be moved,
122 * $$o is a placeholder for the name of the file after moving,
123 * $$l is a placeholder for the latex argument, as explained above.
124 * $$o and $$l can only differ if the file is copied from the temporary
125 * directory to the export location. If it is copied from the original
126 * location to the temporary directory, they are the same, so $$l may be
127 * ignored in this case, as it is in the Mover baseclass.
129 SpecialisedMover(std::string const & command)
130 : command_(command) {}
132 /// The template used to launch the external command.
133 std::string const & command() const { return command_; }
137 do_copy(support::FileName const & from, support::FileName const & to,
138 std::string const & latex) const;
141 do_rename(support::FileName const & from, support::FileName const & to,
142 std::string const & latex) const;
144 std::string command_;
149 * Manage the store of (Mover)s.
154 /** Register a specialised @c command to be used to copy a file
157 void set(std::string const & fmt, std::string const & command);
159 /// @c returns the Mover registered for format @c fmt.
160 Mover const & operator()(std::string const & fmt) const;
162 /** @returns the command template if @c fmt 'finds' a
163 * SpecialisedMover. Otherwise, returns an empty string.
165 std::string const command(std::string const & fmt) const;
168 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
171 typedef SpecialsMap::const_iterator const_iterator;
172 const_iterator begin() const { return specials_.begin(); }
173 const_iterator end() const { return specials_.end(); }
177 SpecialsMap specials_;
181 extern Movers & theMovers();
182 /// @c returns the Mover registered for format @c fmt.
183 extern Mover const & getMover(std::string const & fmt);
184 /** Register a specialised @c command to be used to copy a file
187 extern void setMover(std::string const & fmt, std::string const & command);
188 extern Movers & theSystemMovers();