mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
* mover.h
- SpecialisedMover(): add virtual destructor (fix bug 2916) - Movers: rename iterator to const_iterator. - theMovers(), theSystemMovers(), getMover(), setMover(): new extern definitions. * mover.C: - SpecialisedMover::operator(): get rid of bogus MSVC warning. - delete global variable movers and system_movers. * lyx_main.C: - LyX::Singletons: new movers_ ans system_movers members. - implement Movers access functions. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16743 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
8f7b5e4952
commit
3d2184730a
@ -226,7 +226,7 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format,
|
|||||||
CacheItem * item = pimpl_->find(orig_from, to_format);
|
CacheItem * item = pimpl_->find(orig_from, to_format);
|
||||||
|
|
||||||
time_t const timestamp = fs::last_write_time(orig_from.toFilesystemEncoding());
|
time_t const timestamp = fs::last_write_time(orig_from.toFilesystemEncoding());
|
||||||
Mover const & mover = movers(to_format);
|
Mover const & mover = getMover(to_format);
|
||||||
if (item) {
|
if (item) {
|
||||||
lyxerr[Debug::FILES] << "ConverterCache::add(" << orig_from << "):\n"
|
lyxerr[Debug::FILES] << "ConverterCache::add(" << orig_from << "):\n"
|
||||||
"The file is already in the cache."
|
"The file is already in the cache."
|
||||||
@ -337,7 +337,7 @@ bool ConverterCache::copy(FileName const & orig_from, string const & to_format,
|
|||||||
|
|
||||||
CacheItem * const item = pimpl_->find(orig_from, to_format);
|
CacheItem * const item = pimpl_->find(orig_from, to_format);
|
||||||
BOOST_ASSERT(item);
|
BOOST_ASSERT(item);
|
||||||
Mover const & mover = movers(to_format);
|
Mover const & mover = getMover(to_format);
|
||||||
return mover.copy(item->cache_name, dest);
|
return mover.copy(item->cache_name, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ bool Converters::convert(Buffer const * buffer,
|
|||||||
res = one.startscript(type, command);
|
res = one.startscript(type, command);
|
||||||
|
|
||||||
if (!real_outfile.empty()) {
|
if (!real_outfile.empty()) {
|
||||||
Mover const & mover = movers(conv.to);
|
Mover const & mover = getMover(conv.to);
|
||||||
if (!mover.rename(outfile, real_outfile))
|
if (!mover.rename(outfile, real_outfile))
|
||||||
res = -1;
|
res = -1;
|
||||||
else
|
else
|
||||||
@ -483,7 +483,7 @@ bool Converters::convert(Buffer const * buffer,
|
|||||||
token_base, from_base);
|
token_base, from_base);
|
||||||
string const to = subst(conv.result_dir,
|
string const to = subst(conv.result_dir,
|
||||||
token_base, to_base);
|
token_base, to_base);
|
||||||
Mover const & mover = movers(conv.from);
|
Mover const & mover = getMover(conv.from);
|
||||||
if (!mover.rename(FileName(from), FileName(to))) {
|
if (!mover.rename(FileName(from), FileName(to))) {
|
||||||
Alert::error(_("Cannot convert file"),
|
Alert::error(_("Cannot convert file"),
|
||||||
bformat(_("Could not move a temporary directory from %1$s to %2$s."),
|
bformat(_("Could not move a temporary directory from %1$s to %2$s."),
|
||||||
@ -525,7 +525,7 @@ bool Converters::move(string const & fmt,
|
|||||||
lyxerr[Debug::FILES] << "moving " << from2
|
lyxerr[Debug::FILES] << "moving " << from2
|
||||||
<< " to " << to2 << endl;
|
<< " to " << to2 << endl;
|
||||||
|
|
||||||
Mover const & mover = movers(fmt);
|
Mover const & mover = getMover(fmt);
|
||||||
bool const moved = copy
|
bool const moved = copy
|
||||||
? mover.copy(*it, FileName(to2))
|
? mover.copy(*it, FileName(to2))
|
||||||
: mover.rename(*it, FileName(to2));
|
: mover.rename(*it, FileName(to2));
|
||||||
|
@ -132,7 +132,7 @@ CopyStatus copyFile(string const & format,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mover const & mover = movers(format);
|
Mover const & mover = getMover(format);
|
||||||
if (!mover.copy(sourceFile, destFile, latexFile))
|
if (!mover.copy(sourceFile, destFile, latexFile))
|
||||||
Alert::error(_("Couldn't copy file"),
|
Alert::error(_("Couldn't copy file"),
|
||||||
bformat(_("Copying %1$s to %2$s failed."),
|
bformat(_("Copying %1$s to %2$s failed."),
|
||||||
|
@ -50,7 +50,7 @@ bool ControlPrefs::initialiseParams(std::string const &)
|
|||||||
formats_ = lyx::formats;
|
formats_ = lyx::formats;
|
||||||
converters_ = theConverters();
|
converters_ = theConverters();
|
||||||
converters_.update(formats_);
|
converters_.update(formats_);
|
||||||
movers_ = lyx::movers;
|
movers_ = theMovers();
|
||||||
colors_.clear();
|
colors_.clear();
|
||||||
update_screen_font_ = false;
|
update_screen_font_ = false;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ void ControlPrefs::dispatchParams()
|
|||||||
theConverters().update(lyx::formats);
|
theConverters().update(lyx::formats);
|
||||||
theConverters().buildGraph();
|
theConverters().buildGraph();
|
||||||
|
|
||||||
lyx::movers = movers_;
|
theMovers() = movers_;
|
||||||
|
|
||||||
vector<string>::const_iterator it = colors_.begin();
|
vector<string>::const_iterator it = colors_.begin();
|
||||||
vector<string>::const_iterator const end = colors_.end();
|
vector<string>::const_iterator const end = colors_.end();
|
||||||
|
@ -1066,7 +1066,7 @@ void PrefCopiers::update()
|
|||||||
// The browser widget
|
// The browser widget
|
||||||
AllCopiersLW->clear();
|
AllCopiersLW->clear();
|
||||||
|
|
||||||
for (Movers::iterator it = form_->movers().begin(),
|
for (Movers::const_iterator it = form_->movers().begin(),
|
||||||
end = form_->movers().end();
|
end = form_->movers().end();
|
||||||
it != end; ++it) {
|
it != end; ++it) {
|
||||||
std::string const & command = it->second.command();
|
std::string const & command = it->second.command();
|
||||||
|
@ -252,7 +252,7 @@ void updateExternal(InsetExternalParams const & params,
|
|||||||
unsigned long const temp_checksum = support::sum(temp_file);
|
unsigned long const temp_checksum = support::sum(temp_file);
|
||||||
|
|
||||||
if (from_checksum != temp_checksum) {
|
if (from_checksum != temp_checksum) {
|
||||||
Mover const & mover = movers(from_format);
|
Mover const & mover = getMover(from_format);
|
||||||
if (!mover.copy(params.filename, temp_file)) {
|
if (!mover.copy(params.filename, temp_file)) {
|
||||||
lyxerr[Debug::EXTERNAL]
|
lyxerr[Debug::EXTERNAL]
|
||||||
<< "external::updateExternal. "
|
<< "external::updateExternal. "
|
||||||
|
@ -464,7 +464,7 @@ copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
|
|||||||
// Nothing to do...
|
// Nothing to do...
|
||||||
return std::make_pair(IDENTICAL_CONTENTS, file_out);
|
return std::make_pair(IDENTICAL_CONTENTS, file_out);
|
||||||
|
|
||||||
Mover const & mover = movers(formats.getFormatFromFile(file_in));
|
Mover const & mover = getMover(formats.getFormatFromFile(file_in));
|
||||||
bool const success = mover.copy(file_in, file_out);
|
bool const success = mover.copy(file_in, file_out);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
// FIXME UNICODE
|
// FIXME UNICODE
|
||||||
|
@ -184,6 +184,12 @@ struct LyX::Singletons
|
|||||||
|
|
||||||
// The system converters copy after reading lyxrc.defaults.
|
// The system converters copy after reading lyxrc.defaults.
|
||||||
Converters system_converters_;
|
Converters system_converters_;
|
||||||
|
|
||||||
|
///
|
||||||
|
Movers movers_;
|
||||||
|
|
||||||
|
///
|
||||||
|
Movers system_movers_;
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -857,7 +863,7 @@ bool LyX::init()
|
|||||||
system_lyxrc = lyxrc;
|
system_lyxrc = lyxrc;
|
||||||
system_formats = formats;
|
system_formats = formats;
|
||||||
pimpl_->system_converters_ = pimpl_->converters_;
|
pimpl_->system_converters_ = pimpl_->converters_;
|
||||||
system_movers = movers;
|
pimpl_->system_movers_ = pimpl_->movers_;
|
||||||
system_lcolor = lcolor;
|
system_lcolor = lcolor;
|
||||||
|
|
||||||
// This one is edited through the preferences dialog.
|
// This one is edited through the preferences dialog.
|
||||||
@ -1472,6 +1478,30 @@ Converters & theSystemConverters()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Movers & theMovers()
|
||||||
|
{
|
||||||
|
return LyX::ref().pimpl_->movers_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Mover const & getMover(std::string const & fmt)
|
||||||
|
{
|
||||||
|
return LyX::ref().pimpl_->movers_(fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setMover(std::string const & fmt, std::string const & command)
|
||||||
|
{
|
||||||
|
LyX::ref().pimpl_->movers_.set(fmt, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Movers & theSystemMovers()
|
||||||
|
{
|
||||||
|
return LyX::ref().pimpl_->system_movers_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
IconvProcessor & utf8ToUcs4()
|
IconvProcessor & utf8ToUcs4()
|
||||||
{
|
{
|
||||||
return LyX::ref().iconvProcessor();
|
return LyX::ref().iconvProcessor();
|
||||||
|
@ -32,6 +32,8 @@ class LyXServer;
|
|||||||
class LyXServerSocket;
|
class LyXServerSocket;
|
||||||
class LyXView;
|
class LyXView;
|
||||||
class Messages;
|
class Messages;
|
||||||
|
class Mover;
|
||||||
|
class Movers;
|
||||||
class Session;
|
class Session;
|
||||||
class kb_keymap;
|
class kb_keymap;
|
||||||
|
|
||||||
@ -162,6 +164,11 @@ private:
|
|||||||
/// Use the Pimpl idiom to hide the internals.
|
/// Use the Pimpl idiom to hide the internals.
|
||||||
struct Singletons;
|
struct Singletons;
|
||||||
boost::scoped_ptr<Singletons> pimpl_;
|
boost::scoped_ptr<Singletons> pimpl_;
|
||||||
|
|
||||||
|
friend Movers & theMovers();
|
||||||
|
friend Mover const & getMover(std::string const & fmt);
|
||||||
|
friend void setMover(std::string const & fmt, std::string const & command);
|
||||||
|
friend Movers & theSystemMovers();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
13
src/lyxrc.C
13
src/lyxrc.C
@ -1033,7 +1033,7 @@ int LyXRC::read(LyXLex & lexrc)
|
|||||||
if (lexrc.next()) {
|
if (lexrc.next()) {
|
||||||
command = lexrc.getString();
|
command = lexrc.getString();
|
||||||
}
|
}
|
||||||
movers.set(fmt, command);
|
setMover(fmt, command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2111,12 +2111,13 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
|
|||||||
<< "#\n\n";
|
<< "#\n\n";
|
||||||
|
|
||||||
// Look for new movers
|
// Look for new movers
|
||||||
Movers::iterator const sysbegin = system_movers.begin();
|
Movers::const_iterator const sysbegin = theSystemMovers().begin();
|
||||||
Movers::iterator const sysend = system_movers.end();
|
Movers::const_iterator const sysend = theSystemMovers().end();
|
||||||
|
Movers::const_iterator it = theMovers().begin();
|
||||||
|
Movers::const_iterator end = theMovers().end();
|
||||||
|
|
||||||
for (Movers::iterator it = movers.begin(), end = movers.end();
|
for (; it != end; ++it) {
|
||||||
it != end; ++it) {
|
Movers::const_iterator const sysit =
|
||||||
Movers::iterator const sysit =
|
|
||||||
std::find_if(sysbegin, sysend, SameMover(*it));
|
std::find_if(sysbegin, sysend, SameMover(*it));
|
||||||
if (sysit == sysend) {
|
if (sysit == sysend) {
|
||||||
std::string const & fmt = it->first;
|
std::string const & fmt = it->first;
|
||||||
|
11
src/mover.C
11
src/mover.C
@ -20,15 +20,10 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
|
||||||
|
|
||||||
using std::ios;
|
using std::ios;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
Movers movers;
|
namespace lyx {
|
||||||
Movers system_movers;
|
|
||||||
|
|
||||||
|
|
||||||
bool Mover::copy(support::FileName const & from, support::FileName const & to,
|
bool Mover::copy(support::FileName const & from, support::FileName const & to,
|
||||||
unsigned long int mode) const
|
unsigned long int mode) const
|
||||||
@ -104,7 +99,9 @@ void Movers::set(string const & fmt, string const & command)
|
|||||||
Mover const & Movers::operator()(string const & fmt) const
|
Mover const & Movers::operator()(string const & fmt) const
|
||||||
{
|
{
|
||||||
SpecialsMap::const_iterator const it = specials_.find(fmt);
|
SpecialsMap::const_iterator const it = specials_.find(fmt);
|
||||||
return (it == specials_.end()) ? default_ : it->second;
|
if (it == specials_.end())
|
||||||
|
return default_;
|
||||||
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
18
src/mover.h
18
src/mover.h
@ -104,6 +104,8 @@ class SpecialisedMover : public Mover
|
|||||||
public:
|
public:
|
||||||
SpecialisedMover() {}
|
SpecialisedMover() {}
|
||||||
|
|
||||||
|
virtual ~SpecialisedMover() {}
|
||||||
|
|
||||||
/** @c command should be of the form
|
/** @c command should be of the form
|
||||||
* <code>
|
* <code>
|
||||||
* python $$s/scripts/fig_copy.py $$i $$o $$l
|
* python $$s/scripts/fig_copy.py $$i $$o $$l
|
||||||
@ -162,9 +164,9 @@ private:
|
|||||||
typedef std::map<std::string, SpecialisedMover> SpecialsMap;
|
typedef std::map<std::string, SpecialisedMover> SpecialsMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef SpecialsMap::const_iterator iterator;
|
typedef SpecialsMap::const_iterator const_iterator;
|
||||||
iterator begin() const { return specials_.begin(); }
|
const_iterator begin() const { return specials_.begin(); }
|
||||||
iterator end() const { return specials_.end(); }
|
const_iterator end() const { return specials_.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mover default_;
|
Mover default_;
|
||||||
@ -172,8 +174,14 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
extern Movers movers;
|
extern Movers & theMovers();
|
||||||
extern Movers system_movers;
|
/// @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();
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
Loading…
Reference in New Issue
Block a user