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.
18 #include "support/mute_warning.h"
22 namespace support { class FileName; }
25 * Utility to copy a file of a specified format from one place to another.
26 * This base class simply invokes the command support::copy().
32 Mover(Mover &&) = default;
33 Mover & operator=(Mover &&) = default;
34 Mover(Mover const &) = default;
35 Mover & operator=(Mover const &) = default;
39 /** Copy file @c from to @c to.
40 * This version should be used to copy files from the original
41 * location to the temporary directory.
42 * \returns true if successful.
45 copy(support::FileName const & from, support::FileName const & to) const;
47 /** Copy file @c from to @c to.
48 * \see SpecialisedMover::SpecialisedMover() for an explanation of
50 * This version should be used to copy files from the temporary
51 * directory to the export location, since @c to and @c latex may
52 * not be equal in this case.
53 * \returns true if successful.
54 * NOTE: Although this routine simply calls do_copy() and
55 * Mover::do_copy() does not itself make any use of the @c latex argument,
56 * SpecialisedMover overrides do_copy(), so SpecialisedMover::copy(), which
57 * is just Mover::copy(), calls SpecialisedMover::do_copy(), and the @c latex
58 * argument IS in that case used.
61 copy(support::FileName const & from, support::FileName const & to,
62 std::string const & latex) const
64 return do_copy(from, to, latex);
67 /** Rename file @c from as @c to.
68 * This version should be used to move files from the original
69 * location to the temporary directory.
70 * \returns true if successful.
73 rename(support::FileName const & from, support::FileName const & to) const;
75 /** Rename file @c from as @c to.
76 * \see SpecialisedMover::SpecialisedMover() for an explanation of
78 * This version should be used to move files from the temporary
79 * directory to the export location, since @c to and @c latex may
80 * not be equal in this case.
81 * \returns true if successful.
84 rename(support::FileName const & from, support::FileName const & to,
85 std::string const & latex) const
87 return do_rename(from, to, latex);
92 do_copy(support::FileName const & from, support::FileName const & to,
93 std::string const &) const;
96 do_rename(support::FileName const & from, support::FileName const & to,
97 std::string const &) const;
102 * Specialisation of the Mover concept that uses an external command
105 * For example, an Xfig .fig file can contain references to external
106 * picture files. If such a reference has a relative path, then the
107 * copied .fig file will require a transformation of the picture file
108 * reference if it is to be found by Xfig.
110 * So, in this case, we need three arguments:
111 * (i) @c from the location of the file to be moved
112 * (ii) @c to the location to which it should be moved
113 * (iii) @c latex the identifier that should be used in the sort of
114 * transformation just mentioned.
116 class SpecialisedMover : public Mover
119 SpecialisedMover() = default;
121 /** @c command should be of the form
123 * python $$s/scripts/fig_copy.py $$i $$o $$l
125 * where $$s is a placeholder for the lyx support directory,
126 * $$i is a placeholder for the name of the file to be moved,
127 * $$o is a placeholder for the name of the file after moving,
128 * $$l is a placeholder for the latex argument, as explained above.
129 * $$o and $$l can only differ if the file is copied from the temporary
130 * directory to the export location. If it is copied from the original
131 * location to the temporary directory, they are the same, so $$l may be
132 * ignored in this case, as it is in the Mover baseclass.
134 SpecialisedMover(std::string const & command)
135 : command_(command) {}
137 /// The template used to launch the external command.
138 std::string const & command() const { return command_; }
141 bool do_copy(support::FileName const & from, support::FileName const & to,
142 std::string const & latex) const override;
144 bool do_rename(support::FileName const & from, support::FileName const & to,
145 std::string const & latex) const override;
147 std::string command_;
152 * Manage the store of (Mover)s.
157 /** Register a specialised @c command to be used to copy a file
160 void set(std::string const & fmt, std::string const & command);
162 /// @c returns the Mover registered for format @c fmt.
163 Mover const & operator()(std::string const & fmt) const;
165 /** @returns the command template if @c fmt 'finds' a
166 * SpecialisedMover. Otherwise, returns an empty string.
168 std::string const command(std::string const & fmt) const;
171 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
174 typedef SpecialsMap::const_iterator const_iterator;
175 const_iterator begin() const { return specials_.begin(); }
176 const_iterator end() const { return specials_.end(); }
180 SpecialsMap specials_;
184 extern Movers & theMovers();
185 LYX_BEGIN_MUTE_GCC_WARNING(dangling-reference)
186 /// @c returns the Mover registered for format @c fmt.
187 extern Mover const & getMover(std::string const & fmt);
188 LYX_END_MUTE_GCC_WARNING
189 /** Register a specialised @c command to be used to copy a file
192 extern void setMover(std::string const & fmt, std::string const & command);
193 extern Movers & theSystemMovers();