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().
31 Mover(Mover &&) = default;
32 Mover & operator=(Mover &&) = default;
33 Mover(Mover const &) = default;
34 Mover & operator=(Mover const &) = default;
38 /** Copy file @c from to @c to.
39 * This version should be used to copy files from the original
40 * location to the temporary directory.
41 * \returns true if successful.
44 copy(support::FileName const & from, support::FileName const & to) const;
46 /** Copy file @c from to @c to.
47 * \see SpecialisedMover::SpecialisedMover() for an explanation of
49 * This version should be used to copy files from the temporary
50 * directory to the export location, since @c to and @c latex may
51 * not be equal in this case.
52 * \returns true if successful.
53 * NOTE: Although this routine simply calls do_copy() and
54 * Mover::do_copy() does not itself make any use of the @c latex argument,
55 * SpecialisedMover overrides do_copy(), so SpecialisedMover::copy(), which
56 * is just Mover::copy(), calls SpecialisedMover::do_copy(), and the @c latex
57 * argument IS in that case used.
60 copy(support::FileName const & from, support::FileName const & to,
61 std::string const & latex) const
63 return do_copy(from, to, latex);
66 /** Rename file @c from as @c to.
67 * This version should be used to move files from the original
68 * location to the temporary directory.
69 * \returns true if successful.
72 rename(support::FileName const & from, support::FileName const & to) const;
74 /** Rename file @c from as @c to.
75 * \see SpecialisedMover::SpecialisedMover() for an explanation of
77 * This version should be used to move files from the temporary
78 * directory to the export location, since @c to and @c latex may
79 * not be equal in this case.
80 * \returns true if successful.
83 rename(support::FileName const & from, support::FileName const & to,
84 std::string const & latex) const
86 return do_rename(from, to, latex);
91 do_copy(support::FileName const & from, support::FileName const & to,
92 std::string const &) const;
95 do_rename(support::FileName const & from, support::FileName const & to,
96 std::string const &) const;
101 * Specialisation of the Mover concept that uses an external command
104 * For example, an Xfig .fig file can contain references to external
105 * picture files. If such a reference has a relative path, then the
106 * copied .fig file will require a transformation of the picture file
107 * reference if it is to be found by Xfig.
109 * So, in this case, we need three arguments:
110 * (i) @c from the location of the file to be moved
111 * (ii) @c to the location to which it should be moved
112 * (iii) @c latex the identifier that should be used in the sort of
113 * transformation just mentioned.
115 class SpecialisedMover : public Mover
118 SpecialisedMover() = default;
120 /** @c command should be of the form
122 * python $$s/scripts/fig_copy.py $$i $$o $$l
124 * where $$s is a placeholder for the lyx support directory,
125 * $$i is a placeholder for the name of the file to be moved,
126 * $$o is a placeholder for the name of the file after moving,
127 * $$l is a placeholder for the latex argument, as explained above.
128 * $$o and $$l can only differ if the file is copied from the temporary
129 * directory to the export location. If it is copied from the original
130 * location to the temporary directory, they are the same, so $$l may be
131 * ignored in this case, as it is in the Mover baseclass.
133 SpecialisedMover(std::string const & command)
134 : command_(command) {}
136 /// The template used to launch the external command.
137 std::string const & command() const { return command_; }
140 bool do_copy(support::FileName const & from, support::FileName const & to,
141 std::string const & latex) const override;
143 bool do_rename(support::FileName const & from, support::FileName const & to,
144 std::string const & latex) const override;
146 std::string command_;
151 * Manage the store of (Mover)s.
156 /** Register a specialised @c command to be used to copy a file
159 void set(std::string const & fmt, std::string const & command);
161 /// @c returns the Mover registered for format @c fmt.
162 Mover const & operator()(std::string const & fmt) const;
164 /** @returns the command template if @c fmt 'finds' a
165 * SpecialisedMover. Otherwise, returns an empty string.
167 std::string const command(std::string const & fmt) const;
170 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
173 typedef SpecialsMap::const_iterator const_iterator;
174 const_iterator begin() const { return specials_.begin(); }
175 const_iterator end() const { return specials_.end(); }
179 SpecialsMap specials_;
183 extern Movers & theMovers();
184 /// @c returns the Mover registered for format @c fmt.
185 extern Mover const & getMover(std::string const & fmt);
186 /** Register a specialised @c command to be used to copy a file
189 extern void setMover(std::string const & fmt, std::string const & command);
190 extern Movers & theSystemMovers();