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, since @c to and @c latex
35 * would be equal in this case.
36 * \returns true if successful.
39 copy(support::FileName const & from, support::FileName const & to,
40 unsigned long int mode = (unsigned long int)-1) const;
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(support::FileName const & from, support::FileName const & to,
52 std::string const & latex,
53 unsigned long int mode = (unsigned long int)-1) const
55 return do_copy(from, to, latex, mode);
58 /** Rename file @c from as @c to.
59 * This version should be used to move files from the original
60 * location to the temporary directory, since @c to and @c latex
61 * would be equal in this case.
62 * \returns true if successful.
65 rename(support::FileName const & from, support::FileName const & to) const;
67 /** Rename file @c from as @c to.
68 * \see SpecialisedMover::SpecialisedMover() for an explanation of
70 * This version should be used to move files from the temporary
71 * directory to the export location, since @c to and @c latex may
72 * not be equal in this case.
73 * \returns true if successful.
76 rename(support::FileName const & from, support::FileName const & to,
77 std::string const & latex) const
79 return do_rename(from, to, latex);
84 do_copy(support::FileName const & from, support::FileName const & to,
85 std::string const &, unsigned long int mode) const;
88 do_rename(support::FileName const & from, support::FileName const & to,
89 std::string const &) const;
94 * Specialisation of the Mover concept that uses an external command
97 * For example, an Xfig .fig file can contain references to external
98 * picture files. If such a reference has a relative path, then the
99 * copied .fig file will require a transformation of the picture file
100 * reference if it is to be found by Xfig.
102 class SpecialisedMover : public Mover
105 SpecialisedMover() {}
107 virtual ~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(support::FileName const & from, support::FileName const & to,
134 std::string const & latex, unsigned long int mode) const;
137 do_rename(support::FileName const & from, support::FileName 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 const_iterator;
168 const_iterator begin() const { return specials_.begin(); }
169 const_iterator end() const { return specials_.end(); }
173 SpecialsMap specials_;
177 extern Movers & theMovers();
178 /// @c returns the Mover registered for format @c fmt.
179 extern Mover const & getMover(std::string const & fmt);
180 /** Register a specialised @c command to be used to copy a file
183 extern void setMover(std::string const & fmt, std::string const & command);
184 extern Movers & theSystemMovers();