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.
22 * Utility to copy a file of a specified format from one place to another.
23 * This base class simply invokes the command support::copy().
30 /** Copy file @c from to @c to.
31 * This version should be used to copy files from the original
32 * location to the temporary directory, since @c to and @c latex
33 * would be equal in this case.
34 * \returns true if successful.
37 copy(std::string const & from, std::string const & to) const
39 return do_copy(from, to, to);
42 /** Copy file @c from to @c to.
43 * \see SpecialisedMover::SpecialisedMover() for an explanation of
45 * This version should be used to copy files from the temporary
46 * directory to the export location, since @c to and @c latex may
47 * not be equal in this case.
48 * \returns true if successful.
51 copy(std::string const & from, std::string const & to,
52 std::string const & latex) const
54 return do_copy(from, to, latex);
57 /** Rename file @c from as @c to.
58 * This version should be used to move files from the original
59 * location to the temporary directory, since @c to and @c latex
60 * would be equal in this case.
61 * \returns true if successful.
64 rename(std::string const & from, std::string const & to) const
66 return do_rename(from, to, to);
69 /** Rename file @c from as @c to.
70 * \see SpecialisedMover::SpecialisedMover() for an explanation of
72 * This version should be used to move files from the temporary
73 * directory to the export location, since @c to and @c latex may
74 * not be equal in this case.
75 * \returns true if successful.
78 rename(std::string const & from, std::string const & to,
79 std::string const & latex) const
81 return do_rename(from, to, latex);
86 do_copy(std::string const & from, std::string const & to,
87 std::string const &) const;
90 do_rename(std::string const & from, std::string const & to,
91 std::string const &) const;
96 * Specialisation of the Mover concept that uses an external command
99 * For example, an XFig .fig file can contain references to external
100 * picture files. If such a reference has a relative path, then the
101 * copied .fig file will require a transformation of the picture file
102 * reference if it is to be found by XFig.
104 class SpecialisedMover : public Mover
107 SpecialisedMover() {}
109 /** @c command should be of the form
111 * python $$s/scripts/fig_copy.py $$i $$o $$l
113 * where $$s is a placeholder for the lyx support directory,
114 * $$i is a placeholder for the name of the file to be moved,
115 * $$o is a placeholder for the name of the file after moving,
116 * $$l is a placeholder for the name of the file after moving,
117 * suitable as argument to a latex include command. This is
118 * either an absolute filename or relative to the master
120 * $$o and $$l can only differ if the file is copied from the
121 * temporary directory to the export location. If it is copied
122 * from the original location to the temporary directory, they
123 * are the same, so $$l may be ommitted in this case.
125 SpecialisedMover(std::string const & command)
126 : command_(command) {}
128 /// The template used to launch the external command.
129 std::string const & command() const { return command_; }
133 do_copy(std::string const & from, std::string const & to,
134 std::string const & latex) const;
137 do_rename(std::string const & from, std::string const & to,
138 std::string const & latex) const;
140 std::string command_;
145 * Manage the store of (Mover)s.
150 /** Register a specialised @c command to be used to copy a file
153 void set(std::string const & fmt, std::string const & command);
155 /// @c returns the Mover registered for format @c fmt.
156 Mover const & operator()(std::string const & fmt) const;
158 /** @returns the command template if @c fmt 'finds' a
159 * SpecialisedMover. Otherwise, returns an empty string.
161 std::string const command(std::string const & fmt) const;
164 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
167 typedef SpecialsMap::const_iterator iterator;
168 iterator begin() const { return specials_.begin(); }
169 iterator end() const { return specials_.end(); }
173 SpecialsMap specials_;
177 extern Movers movers;
178 extern Movers system_movers;