Transfer the global converters and system_converters variables to LyX::Singletons class.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16725 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-01-17 13:18:16 +00:00
parent 3931b65341
commit 74f3ca3246
13 changed files with 86 additions and 49 deletions

View File

@ -697,12 +697,4 @@ Converters::getPath(string const & from, string const & to)
formats.getNumber(to));
}
/// The global instance
Converters converters;
// The global copy after reading lyxrc.defaults
Converters system_converters;
} // namespace lyx

View File

@ -161,10 +161,13 @@ private:
Graph G_;
};
extern Converters converters;
extern Converters system_converters;
/// The global instance.
/// Implementation is in lyx_main.C.
extern Converters & theConverters();
/// The global copy after reading lyxrc.defaults.
/// Implementation is in lyx_main.C.
extern Converters & theSystemConverters();
} // namespace lyx

View File

@ -161,14 +161,14 @@ bool Exporter::Export(Buffer * buffer, string const & format,
// which returns the shortest path from one of the formats in 'from'
// to 'to'.
if ((format == "lyx13x" || format == "lyx14x") &&
!converters.getPath("lyx", format).empty())
!theConverters().getPath("lyx", format).empty())
backend_format = "lyx";
else if (find(backends.begin(), backends.end(), format) == backends.end()) {
for (vector<string>::const_iterator it = backends.begin();
it != backends.end(); ++it) {
Graph::EdgePath p = converters.getPath(*it, format);
Graph::EdgePath p = theConverters().getPath(*it, format);
if (!p.empty()) {
runparams.flavor = converters.getFlavor(p);
runparams.flavor = theConverters().getFlavor(p);
backend_format = *it;
break;
}
@ -221,7 +221,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
string const error_type = (format == "program")? "Build" : bufferFormat(*buffer);
string const ext = formats.extension(format);
FileName const tmp_result_file(changeExtension(filename, ext));
bool const success = converters.convert(buffer, FileName(filename),
bool const success = theConverters().convert(buffer, FileName(filename),
tmp_result_file, FileName(buffer->fileName()), backend_format, format,
buffer->errorList(error_type));
// Emit the signal to show the error list.
@ -291,7 +291,7 @@ bool Exporter::isExportable(Buffer const & buffer, string const & format)
vector<string> backends = Backends(buffer);
for (vector<string>::const_iterator it = backends.begin();
it != backends.end(); ++it)
if (converters.isReachable(*it, format))
if (theConverters().isReachable(*it, format))
return true;
return false;
}
@ -302,11 +302,11 @@ Exporter::getExportableFormats(Buffer const & buffer, bool only_viewable)
{
vector<string> backends = Backends(buffer);
vector<Format const *> result =
converters.getReachable(backends[0], only_viewable, true);
theConverters().getReachable(backends[0], only_viewable, true);
for (vector<string>::const_iterator it = backends.begin() + 1;
it != backends.end(); ++it) {
vector<Format const *> r =
converters.getReachable(*it, only_viewable, false);
theConverters().getReachable(*it, only_viewable, false);
result.insert(result.end(), r.begin(), r.end());
}
return result;

View File

@ -48,7 +48,7 @@ bool ControlPrefs::initialiseParams(std::string const &)
{
rc_ = lyxrc;
formats_ = lyx::formats;
converters_ = lyx::converters;
converters_ = theConverters();
converters_.update(formats_);
movers_ = lyx::movers;
colors_.clear();
@ -70,9 +70,9 @@ void ControlPrefs::dispatchParams()
lyx::formats = formats_;
lyx::converters = converters_;
lyx::converters.update(lyx::formats);
lyx::converters.buildGraph();
theConverters() = converters_;
theConverters().update(lyx::formats);
theConverters().buildGraph();
lyx::movers = movers_;

View File

@ -89,7 +89,7 @@ vector<Format const *> const ControlSendto::allFormats() const
// for the internal lyx-view and external latex run
string const name = fo_it->name();
if (name != "eps" && name != "xpm" && name != "png" &&
converters.isReachable(*ex_it, name))
theConverters().isReachable(*ex_it, name))
to.push_back(&(*fo_it));
}
}

View File

@ -92,7 +92,7 @@ public:
bool Converter::isReachable(string const & from_format_name,
string const & to_format_name)
{
return converters.isReachable(from_format_name, to_format_name);
return theConverters().isReachable(from_format_name, to_format_name);
}
@ -306,7 +306,7 @@ static void build_script(FileName const & from_file,
EdgePath const edgepath = from_format.empty() ?
EdgePath() :
converters.getPath(from_format, to_format);
theConverters().getPath(from_format, to_format);
// Create a temporary base file-name for all intermediate steps.
// Remember to remove the temp file because we only want the name...
@ -371,7 +371,7 @@ static void build_script(FileName const & from_file,
EdgePath::const_iterator end = edgepath.end();
for (; it != end; ++it) {
lyx::Converter const & conv = converters.get(*it);
lyx::Converter const & conv = theConverters().get(*it);
// Build the conversion command
string const infile = outfile;

View File

@ -94,7 +94,7 @@ lyx::Converter const * setConverter()
if (from == to)
continue;
lyx::Converter const * ptr = lyx::converters.getConverter(from, to);
lyx::Converter const * ptr = lyx::theConverters().getConverter(from, to);
if (ptr)
return ptr;
}

View File

@ -53,11 +53,11 @@ bool Importer::Import(LyXView * lv, FileName const & filename,
if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
for (vector<string>::const_iterator it = loaders.begin();
it != loaders.end(); ++it) {
if (converters.isReachable(format, *it)) {
if (theConverters().isReachable(format, *it)) {
string const tofile =
changeExtension(filename.absFilename(),
formats.extension(*it));
if (!converters.convert(0, filename, FileName(tofile),
if (!theConverters().convert(0, filename, FileName(tofile),
filename, format, *it, errorList))
return false;
loader_format = *it;
@ -101,11 +101,11 @@ vector<Format const *> const Importer::GetImportableFormats()
{
vector<string> loaders = Loaders();
vector<Format const *> result =
converters.getReachableTo(loaders[0], true);
theConverters().getReachableTo(loaders[0], true);
for (vector<string>::const_iterator it = loaders.begin() + 1;
it != loaders.end(); ++it) {
vector<Format const *> r =
converters.getReachableTo(*it, false);
theConverters().getReachableTo(*it, false);
result.insert(result.end(), r.begin(), r.end());
}
return result;

View File

@ -230,7 +230,7 @@ void updateExternal(InsetExternalParams const & params,
if (to_format.empty())
return; // NOT_NEEDED
if (!converters.isReachable(from_format, to_format)) {
if (!theConverters().isReachable(from_format, to_format)) {
lyxerr[Debug::EXTERNAL]
<< "external::updateExternal. "
<< "Unable to convert from "
@ -308,7 +308,7 @@ void updateExternal(InsetExternalParams const & params,
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
ErrorList el;
/* bool const success = */
converters.convert(&buffer, temp_file, abs_to_file,
theConverters().convert(&buffer, temp_file, abs_to_file,
params.filename, from_format, to_format, el,
Converters::try_default | Converters::try_cache);
// return success

View File

@ -721,7 +721,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
ErrorList el;
if (converters.convert(&buf, temp_file, to_file, params().filename,
if (theConverters().convert(&buf, temp_file, to_file, params().filename,
from, to, el,
Converters::try_default | Converters::try_cache)) {
runparams.exportdata->addExternalFile(tex_format,

View File

@ -150,6 +150,10 @@ struct LyX::Singletons
{
Singletons(): iconv(ucs4_codeset, "UTF-8")
{
// Set the default User Interface language as soon as possible.
// The language used will be derived from the environment
// variables.
messages_["GUI"] = Messages();
}
/// our function handler
LyXFunc lyxfunc_;
@ -172,8 +176,14 @@ struct LyX::Singletons
/// Files to load at start.
vector<FileName> files_to_load_;
///
/// The messages translators.
map<string, Messages> messages_;
/// The file converters.
Converters converters_;
// The system converters copy after reading lyxrc.defaults.
Converters system_converters_;
};
///
@ -301,6 +311,18 @@ kb_keymap & LyX::topLevelKeymap()
}
Converters & LyX::converters()
{
return pimpl_->converters_;
}
Converters & LyX::systemConverters()
{
return pimpl_->system_converters_;
}
IconvProcessor & LyX::iconvProcessor()
{
return pimpl_->iconv;
@ -800,8 +822,8 @@ bool LyX::init()
if (!readRcFile("lyxrc.dist"))
return false;
// Set the User Interface language.
pimpl_->messages_["GUI"] = Messages();
// Set the language defined by the distributor.
//setGuiLanguage(lyxrc.gui_language);
// Set the PATH correctly.
#if !defined (USE_POSIX_PACKAGING)
@ -834,7 +856,7 @@ bool LyX::init()
system_lyxrc = lyxrc;
system_formats = formats;
system_converters = converters;
pimpl_->system_converters_ = pimpl_->converters_;
system_movers = movers;
system_lcolor = lcolor;
@ -853,6 +875,9 @@ bool LyX::init()
return false;
if (use_gui) {
// Set the language defined by the user.
//setGuiLanguage(lyxrc.gui_language);
// Set up bindings
pimpl_->toplevel_keymap_.reset(new kb_keymap);
defaultKeyBindings(pimpl_->toplevel_keymap_.get());
@ -1435,6 +1460,18 @@ kb_keymap & theTopLevelKeymap()
}
Converters & theConverters()
{
return LyX::ref().converters();
}
Converters & theSystemConverters()
{
return LyX::ref().systemConverters();
}
IconvProcessor & utf8ToUcs4()
{
return LyX::ref().iconvProcessor();

View File

@ -23,6 +23,7 @@ namespace lyx {
class Buffer;
class BufferList;
class Converters;
class ErrorItem;
class IconvProcessor;
class InsetBase;
@ -78,6 +79,10 @@ public:
kb_keymap & topLevelKeymap();
kb_keymap const & topLevelKeymap() const;
///
Converters & converters();
Converters & systemConverters();
///
Messages & getMessages(std::string const & language);
///

View File

@ -1052,9 +1052,9 @@ int LyXRC::read(LyXLex & lexrc)
flags = lexrc.getString();
}
if (command.empty()) {
converters.erase(from, to);
theConverters().erase(from, to);
} else {
converters.add(from, to, command, flags);
theConverters().add(from, to, command, flags);
}
break;
}
@ -1118,7 +1118,7 @@ int LyXRC::read(LyXLex & lexrc)
<< format << "'." << endl;
}
if (prettyname.empty()) {
if (converters.formatIsUsed(format)) {
if (theConverters().formatIsUsed(format)) {
lyxerr << "Can't delete format "
<< format << endl;
} else {
@ -1208,8 +1208,8 @@ int LyXRC::read(LyXLex & lexrc)
}
/// Update converters data-structures
converters.update(formats);
converters.buildGraph();
theConverters().update(formats);
theConverters().buildGraph();
return 0;
}
@ -2084,10 +2084,10 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
case RC_CONVERTER:
// Look for new converters
for (Converters::const_iterator cit = converters.begin();
cit != converters.end(); ++cit) {
for (Converters::const_iterator cit = theConverters().begin();
cit != theConverters().end(); ++cit) {
Converter const * converter =
system_converters.getConverter(cit->from,
theSystemConverters().getConverter(cit->from,
cit->to);
if (!converter ||
converter->command != cit->command ||
@ -2099,9 +2099,9 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
}
// New/modifed converters
for (Converters::const_iterator cit = system_converters.begin();
cit != system_converters.end(); ++cit)
if (!converters.getConverter(cit->from, cit->to))
for (Converters::const_iterator cit = theSystemConverters().begin();
cit != theSystemConverters().end(); ++cit)
if (!theConverters().getConverter(cit->from, cit->to))
os << "\\converter \"" << cit->from
<< "\" \"" << cit->to << "\" \"\" \"\"\n";