2004-10-26 18:39:13 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Mover.h
|
2004-10-26 18:39:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MOVER_H
|
|
|
|
#define MOVER_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
namespace support { class FileName; }
|
|
|
|
|
2004-10-26 18:39:13 +00:00
|
|
|
/**
|
|
|
|
* Utility to copy a file of a specified format from one place to another.
|
|
|
|
* This base class simply invokes the command support::copy().
|
|
|
|
*/
|
|
|
|
class Mover
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Mover() {}
|
|
|
|
|
|
|
|
/** Copy file @c from to @c to.
|
2004-11-01 08:50:42 +00:00
|
|
|
* This version should be used to copy files from the original
|
2008-10-08 15:07:09 +00:00
|
|
|
* location to the temporary directory.
|
2004-10-26 18:39:13 +00:00
|
|
|
* \returns true if successful.
|
|
|
|
*/
|
|
|
|
bool
|
2007-12-13 08:20:45 +00:00
|
|
|
copy(support::FileName const & from, support::FileName const & to) const;
|
2004-11-01 08:50:42 +00:00
|
|
|
|
2008-10-08 15:07:09 +00:00
|
|
|
/** Copy file @c from to @c to.
|
|
|
|
* \see SpecialisedMover::SpecialisedMover() for an explanation of
|
|
|
|
* @c latex.
|
|
|
|
* This version should be used to copy files from the temporary
|
|
|
|
* directory to the export location, since @c to and @c latex may
|
|
|
|
* not be equal in this case.
|
|
|
|
* \returns true if successful.
|
|
|
|
* NOTE: Although this routine simply calls do_copy() and
|
|
|
|
* Mover::do_copy() does not itself make any use of the @c latex argument,
|
|
|
|
* SpecialisedMover overrides do_copy(), so SpecialisedMover::copy(), which
|
|
|
|
* is just Mover::copy(), calls SpecialisedMover::do_copy(), and the @c latex
|
|
|
|
* argument IS in that case used.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
copy(support::FileName const & from, support::FileName const & to,
|
|
|
|
std::string const & latex) const
|
|
|
|
{
|
|
|
|
return do_copy(from, to, latex);
|
|
|
|
}
|
|
|
|
|
2004-10-26 18:39:13 +00:00
|
|
|
/** Rename file @c from as @c to.
|
2004-11-01 08:50:42 +00:00
|
|
|
* This version should be used to move files from the original
|
2008-10-08 15:07:09 +00:00
|
|
|
* location to the temporary directory.
|
2004-10-26 18:39:13 +00:00
|
|
|
* \returns true if successful.
|
|
|
|
*/
|
|
|
|
bool
|
2006-11-26 21:30:39 +00:00
|
|
|
rename(support::FileName const & from, support::FileName const & to) const;
|
2004-11-01 08:50:42 +00:00
|
|
|
|
|
|
|
/** Rename file @c from as @c to.
|
|
|
|
* \see SpecialisedMover::SpecialisedMover() for an explanation of
|
|
|
|
* @c latex.
|
|
|
|
* This version should be used to move files from the temporary
|
|
|
|
* directory to the export location, since @c to and @c latex may
|
|
|
|
* not be equal in this case.
|
|
|
|
* \returns true if successful.
|
|
|
|
*/
|
|
|
|
bool
|
2006-11-26 21:30:39 +00:00
|
|
|
rename(support::FileName const & from, support::FileName const & to,
|
2004-11-01 08:50:42 +00:00
|
|
|
std::string const & latex) const
|
|
|
|
{
|
|
|
|
return do_rename(from, to, latex);
|
2004-10-26 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2008-10-08 15:07:09 +00:00
|
|
|
virtual bool
|
|
|
|
do_copy(support::FileName const & from, support::FileName const & to,
|
|
|
|
std::string const &) const;
|
|
|
|
|
2004-10-26 18:39:13 +00:00
|
|
|
virtual bool
|
2006-11-26 21:30:39 +00:00
|
|
|
do_rename(support::FileName const & from, support::FileName const & to,
|
2006-04-05 23:56:29 +00:00
|
|
|
std::string const &) const;
|
2004-10-26 18:39:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialisation of the Mover concept that uses an external command
|
|
|
|
* to copy a file.
|
|
|
|
*
|
2007-03-15 21:22:02 +00:00
|
|
|
* For example, an Xfig .fig file can contain references to external
|
2004-10-26 18:39:13 +00:00
|
|
|
* picture files. If such a reference has a relative path, then the
|
|
|
|
* copied .fig file will require a transformation of the picture file
|
2008-10-08 15:07:09 +00:00
|
|
|
* reference if it is to be found by Xfig.
|
|
|
|
*
|
|
|
|
* So, in this case, we need three arguments:
|
|
|
|
* (i) @c from the location of the file to be moved
|
|
|
|
* (ii) @c to the location to which it should be moved
|
|
|
|
* (iii) @c latex the identifier that should be used in the sort of
|
|
|
|
* transformation just mentioned.
|
2004-10-26 18:39:13 +00:00
|
|
|
*/
|
2005-01-19 15:03:31 +00:00
|
|
|
class SpecialisedMover : public Mover
|
2004-10-26 18:39:13 +00:00
|
|
|
{
|
2005-01-19 15:03:31 +00:00
|
|
|
public:
|
2004-10-26 18:39:13 +00:00
|
|
|
SpecialisedMover() {}
|
|
|
|
|
2007-01-18 08:42:53 +00:00
|
|
|
virtual ~SpecialisedMover() {}
|
|
|
|
|
2004-10-26 18:39:13 +00:00
|
|
|
/** @c command should be of the form
|
|
|
|
* <code>
|
2006-08-08 21:12:50 +00:00
|
|
|
* python $$s/scripts/fig_copy.py $$i $$o $$l
|
2004-10-26 18:39:13 +00:00
|
|
|
* </code>
|
2005-01-20 15:02:16 +00:00
|
|
|
* where $$s is a placeholder for the lyx support directory,
|
2004-10-26 18:39:13 +00:00
|
|
|
* $$i is a placeholder for the name of the file to be moved,
|
2004-11-01 08:50:42 +00:00
|
|
|
* $$o is a placeholder for the name of the file after moving,
|
2008-10-08 15:07:09 +00:00
|
|
|
* $$l is a placeholder for the latex argument, as explained above.
|
|
|
|
* $$o and $$l can only differ if the file is copied from the temporary
|
|
|
|
* directory to the export location. If it is copied from the original
|
|
|
|
* location to the temporary directory, they are the same, so $$l may be
|
|
|
|
* ignored in this case, as it is in the Mover baseclass.
|
2004-10-26 18:39:13 +00:00
|
|
|
*/
|
|
|
|
SpecialisedMover(std::string const & command)
|
|
|
|
: command_(command) {}
|
|
|
|
|
|
|
|
/// The template used to launch the external command.
|
|
|
|
std::string const & command() const { return command_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual bool
|
2006-11-26 21:30:39 +00:00
|
|
|
do_copy(support::FileName const & from, support::FileName const & to,
|
2007-12-13 08:20:45 +00:00
|
|
|
std::string const & latex) const;
|
2004-10-26 18:39:13 +00:00
|
|
|
|
|
|
|
virtual bool
|
2006-11-26 21:30:39 +00:00
|
|
|
do_rename(support::FileName const & from, support::FileName const & to,
|
2006-04-05 23:56:29 +00:00
|
|
|
std::string const & latex) const;
|
2004-10-26 18:39:13 +00:00
|
|
|
|
|
|
|
std::string command_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manage the store of (Mover)s.
|
|
|
|
*/
|
|
|
|
class Movers
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Register a specialised @c command to be used to copy a file
|
|
|
|
* of format @c fmt.
|
|
|
|
*/
|
|
|
|
void set(std::string const & fmt, std::string const & command);
|
|
|
|
|
|
|
|
/// @c returns the Mover registered for format @c fmt.
|
|
|
|
Mover const & operator()(std::string const & fmt) const;
|
|
|
|
|
|
|
|
/** @returns the command template if @c fmt 'finds' a
|
|
|
|
* SpecialisedMover. Otherwise, returns an empty string.
|
|
|
|
*/
|
|
|
|
std::string const command(std::string const & fmt) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::map<std::string, SpecialisedMover> SpecialsMap;
|
|
|
|
|
|
|
|
public:
|
2007-01-18 08:42:53 +00:00
|
|
|
typedef SpecialsMap::const_iterator const_iterator;
|
|
|
|
const_iterator begin() const { return specials_.begin(); }
|
|
|
|
const_iterator end() const { return specials_.end(); }
|
2004-10-26 18:39:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Mover default_;
|
|
|
|
SpecialsMap specials_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-01-18 08:42:53 +00:00
|
|
|
extern Movers & theMovers();
|
|
|
|
/// @c returns the Mover registered for format @c fmt.
|
|
|
|
extern Mover const & getMover(std::string const & fmt);
|
|
|
|
/** Register a specialised @c command to be used to copy a file
|
|
|
|
* of format @c fmt.
|
|
|
|
*/
|
|
|
|
extern void setMover(std::string const & fmt, std::string const & command);
|
|
|
|
extern Movers & theSystemMovers();
|
2004-10-26 18:39:13 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2004-10-26 18:39:13 +00:00
|
|
|
#endif // MOVER_H
|