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.
19 * Utility to copy a file of a specified format from one place to another.
20 * This base class simply invokes the command support::copy().
27 /** Copy file @c from to @c to.
28 * This version should be used to copy files from the original
29 * location to the temporary directory, since @c to and @c latex
30 * would be equal in this case.
31 * \returns true if successful.
34 copy(std::string
const & from
, std::string
const & to
) const
36 return do_copy(from
, to
, to
);
39 /** Copy file @c from to @c to.
40 * \see SpecialisedMover::SpecialisedMover() for an explanation of
42 * This version should be used to copy files from the temporary
43 * directory to the export location, since @c to and @c latex may
44 * not be equal in this case.
45 * \returns true if successful.
48 copy(std::string
const & from
, std::string
const & to
,
49 std::string
const & latex
) const
51 return do_copy(from
, to
, latex
);
54 /** Rename file @c from as @c to.
55 * This version should be used to move files from the original
56 * location to the temporary directory, since @c to and @c latex
57 * would be equal in this case.
58 * \returns true if successful.
61 rename(std::string
const & from
, std::string
const & to
) const
63 return do_rename(from
, to
, to
);
66 /** Rename file @c from as @c to.
67 * \see SpecialisedMover::SpecialisedMover() for an explanation of
69 * This version should be used to move files from the temporary
70 * directory to the export location, since @c to and @c latex may
71 * not be equal in this case.
72 * \returns true if successful.
75 rename(std::string
const & from
, std::string
const & to
,
76 std::string
const & latex
) const
78 return do_rename(from
, to
, latex
);
83 do_copy(std::string
const & from
, std::string
const & to
,
84 std::string
const &) const;
87 do_rename(std::string
const & from
, std::string
const & to
,
88 std::string
const &) const;
93 * Specialisation of the Mover concept that uses an external command
96 * For example, an XFig .fig file can contain references to external
97 * picture files. If such a reference has a relative path, then the
98 * copied .fig file will require a transformation of the picture file
99 * reference if it is to be found by XFig.
101 class SpecialisedMover
: public Mover
104 SpecialisedMover() {}
106 /** @c command should be of the form
108 * sh $$s/scripts/fig_copy.sh $$i $$o $$l
110 * where $$s is a placeholder for the lyx support directory,
111 * $$i is a placeholder for the name of the file to be moved,
112 * $$o is a placeholder for the name of the file after moving,
113 * $$l is a placeholder for the name of the file after moving,
114 * suitable as argument to a latex include command. This is
115 * either an absolute filename or relative to the master
117 * $$o and $$l can only differ if the file is copied from the
118 * temporary directory to the export location. If it is copied
119 * from the original location to the temporary directory, they
120 * are the same, so $$l may be ommitted in this case.
122 SpecialisedMover(std::string
const & command
)
123 : command_(command
) {}
125 /// The template used to launch the external command.
126 std::string
const & command() const { return command_
; }
130 do_copy(std::string
const & from
, std::string
const & to
,
131 std::string
const & latex
) const;
134 do_rename(std::string
const & from
, std::string
const & to
,
135 std::string
const & latex
) const;
137 std::string command_
;
142 * Manage the store of (Mover)s.
147 /** Register a specialised @c command to be used to copy a file
150 void set(std::string
const & fmt
, std::string
const & command
);
152 /// @c returns the Mover registered for format @c fmt.
153 Mover
const & operator()(std::string
const & fmt
) const;
155 /** @returns the command template if @c fmt 'finds' a
156 * SpecialisedMover. Otherwise, returns an empty string.
158 std::string
const command(std::string
const & fmt
) const;
161 typedef std::map
<std::string
, SpecialisedMover
> SpecialsMap
;
164 typedef SpecialsMap::const_iterator iterator
;
165 iterator
begin() const { return specials_
.begin(); }
166 iterator
end() const { return specials_
.end(); }
170 SpecialsMap specials_
;
174 extern Movers movers
;
175 extern Movers system_movers
;