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,
38 unsigned long int mode = (unsigned long int)-1) const
40 return do_copy(from, to, to, mode);
43 /** Copy file @c from to @c to.
44 * \see SpecialisedMover::SpecialisedMover() for an explanation of
46 * This version should be used to copy files from the temporary
47 * directory to the export location, since @c to and @c latex may
48 * not be equal in this case.
49 * \returns true if successful.
52 copy(std::string const & from, std::string const & to,
53 std::string const & latex,
54 unsigned long int mode = (unsigned long int)-1) const
56 return do_copy(from, to, latex, mode);
59 /** Rename file @c from as @c to.
60 * This version should be used to move files from the original
61 * location to the temporary directory, since @c to and @c latex
62 * would be equal in this case.
63 * \returns true if successful.
66 rename(std::string const & from, std::string const & to) const
68 return do_rename(from, to, to);
71 /** Rename file @c from as @c to.
72 * \see SpecialisedMover::SpecialisedMover() for an explanation of
74 * This version should be used to move files from the temporary
75 * directory to the export location, since @c to and @c latex may
76 * not be equal in this case.
77 * \returns true if successful.
80 rename(std::string const & from, std::string const & to,
81 std::string const & latex) const
83 return do_rename(from, to, latex);
88 do_copy(std::string const & from, std::string const & to,
89 std::string const &, unsigned long int mode) const;
92 do_rename(std::string const & from, std::string const & to,
93 std::string const &) const;
98 * Specialisation of the Mover concept that uses an external command
101 * For example, an XFig .fig file can contain references to external
102 * picture files. If such a reference has a relative path, then the
103 * copied .fig file will require a transformation of the picture file
104 * reference if it is to be found by XFig.
106 class SpecialisedMover : public Mover
109 SpecialisedMover() {}
111 /** @c command should be of the form
113 * python $$s/scripts/fig_copy.py $$i $$o $$l
115 * where $$s is a placeholder for the lyx support directory,
116 * $$i is a placeholder for the name of the file to be moved,
117 * $$o is a placeholder for the name of the file after moving,
118 * $$l is a placeholder for the name of the file after moving,
119 * suitable as argument to a latex include command. This is
120 * either an absolute filename or relative to the master
122 * $$o and $$l can only differ if the file is copied from the
123 * temporary directory to the export location. If it is copied
124 * from the original location to the temporary directory, they
125 * are the same, so $$l may be ommitted in this case.
127 SpecialisedMover(std::string const & command)
128 : command_(command) {}
130 /// The template used to launch the external command.
131 std::string const & command() const { return command_; }
135 do_copy(std::string const & from, std::string const & to,
136 std::string const & latex, unsigned long int mode) const;
139 do_rename(std::string const & from, std::string const & to,
140 std::string const & latex) const;
142 std::string command_;
147 * Manage the store of (Mover)s.
152 /** Register a specialised @c command to be used to copy a file
155 void set(std::string const & fmt, std::string const & command);
157 /// @c returns the Mover registered for format @c fmt.
158 Mover const & operator()(std::string const & fmt) const;
160 /** @returns the command template if @c fmt 'finds' a
161 * SpecialisedMover. Otherwise, returns an empty string.
163 std::string const command(std::string const & fmt) const;
166 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
169 typedef SpecialsMap::const_iterator iterator;
170 iterator begin() const { return specials_.begin(); }
171 iterator end() const { return specials_.end(); }
175 SpecialsMap specials_;
179 extern Movers movers;
180 extern Movers system_movers;