mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-04 08:37:52 +00:00
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:
parent
3931b65341
commit
74f3ca3246
@ -697,12 +697,4 @@ Converters::getPath(string const & from, string const & to)
|
|||||||
formats.getNumber(to));
|
formats.getNumber(to));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// The global instance
|
|
||||||
Converters converters;
|
|
||||||
|
|
||||||
// The global copy after reading lyxrc.defaults
|
|
||||||
Converters system_converters;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -161,10 +161,13 @@ private:
|
|||||||
Graph G_;
|
Graph G_;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Converters converters;
|
/// The global instance.
|
||||||
|
/// Implementation is in lyx_main.C.
|
||||||
extern Converters system_converters;
|
extern Converters & theConverters();
|
||||||
|
|
||||||
|
/// The global copy after reading lyxrc.defaults.
|
||||||
|
/// Implementation is in lyx_main.C.
|
||||||
|
extern Converters & theSystemConverters();
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
|
@ -161,14 +161,14 @@ bool Exporter::Export(Buffer * buffer, string const & format,
|
|||||||
// which returns the shortest path from one of the formats in 'from'
|
// which returns the shortest path from one of the formats in 'from'
|
||||||
// to 'to'.
|
// to 'to'.
|
||||||
if ((format == "lyx13x" || format == "lyx14x") &&
|
if ((format == "lyx13x" || format == "lyx14x") &&
|
||||||
!converters.getPath("lyx", format).empty())
|
!theConverters().getPath("lyx", format).empty())
|
||||||
backend_format = "lyx";
|
backend_format = "lyx";
|
||||||
else if (find(backends.begin(), backends.end(), format) == backends.end()) {
|
else if (find(backends.begin(), backends.end(), format) == backends.end()) {
|
||||||
for (vector<string>::const_iterator it = backends.begin();
|
for (vector<string>::const_iterator it = backends.begin();
|
||||||
it != backends.end(); ++it) {
|
it != backends.end(); ++it) {
|
||||||
Graph::EdgePath p = converters.getPath(*it, format);
|
Graph::EdgePath p = theConverters().getPath(*it, format);
|
||||||
if (!p.empty()) {
|
if (!p.empty()) {
|
||||||
runparams.flavor = converters.getFlavor(p);
|
runparams.flavor = theConverters().getFlavor(p);
|
||||||
backend_format = *it;
|
backend_format = *it;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
|
|||||||
string const error_type = (format == "program")? "Build" : bufferFormat(*buffer);
|
string const error_type = (format == "program")? "Build" : bufferFormat(*buffer);
|
||||||
string const ext = formats.extension(format);
|
string const ext = formats.extension(format);
|
||||||
FileName const tmp_result_file(changeExtension(filename, ext));
|
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,
|
tmp_result_file, FileName(buffer->fileName()), backend_format, format,
|
||||||
buffer->errorList(error_type));
|
buffer->errorList(error_type));
|
||||||
// Emit the signal to show the error list.
|
// 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);
|
vector<string> backends = Backends(buffer);
|
||||||
for (vector<string>::const_iterator it = backends.begin();
|
for (vector<string>::const_iterator it = backends.begin();
|
||||||
it != backends.end(); ++it)
|
it != backends.end(); ++it)
|
||||||
if (converters.isReachable(*it, format))
|
if (theConverters().isReachable(*it, format))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -302,11 +302,11 @@ Exporter::getExportableFormats(Buffer const & buffer, bool only_viewable)
|
|||||||
{
|
{
|
||||||
vector<string> backends = Backends(buffer);
|
vector<string> backends = Backends(buffer);
|
||||||
vector<Format const *> result =
|
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;
|
for (vector<string>::const_iterator it = backends.begin() + 1;
|
||||||
it != backends.end(); ++it) {
|
it != backends.end(); ++it) {
|
||||||
vector<Format const *> r =
|
vector<Format const *> r =
|
||||||
converters.getReachable(*it, only_viewable, false);
|
theConverters().getReachable(*it, only_viewable, false);
|
||||||
result.insert(result.end(), r.begin(), r.end());
|
result.insert(result.end(), r.begin(), r.end());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -48,7 +48,7 @@ bool ControlPrefs::initialiseParams(std::string const &)
|
|||||||
{
|
{
|
||||||
rc_ = lyxrc;
|
rc_ = lyxrc;
|
||||||
formats_ = lyx::formats;
|
formats_ = lyx::formats;
|
||||||
converters_ = lyx::converters;
|
converters_ = theConverters();
|
||||||
converters_.update(formats_);
|
converters_.update(formats_);
|
||||||
movers_ = lyx::movers;
|
movers_ = lyx::movers;
|
||||||
colors_.clear();
|
colors_.clear();
|
||||||
@ -70,9 +70,9 @@ void ControlPrefs::dispatchParams()
|
|||||||
|
|
||||||
lyx::formats = formats_;
|
lyx::formats = formats_;
|
||||||
|
|
||||||
lyx::converters = converters_;
|
theConverters() = converters_;
|
||||||
lyx::converters.update(lyx::formats);
|
theConverters().update(lyx::formats);
|
||||||
lyx::converters.buildGraph();
|
theConverters().buildGraph();
|
||||||
|
|
||||||
lyx::movers = movers_;
|
lyx::movers = movers_;
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ vector<Format const *> const ControlSendto::allFormats() const
|
|||||||
// for the internal lyx-view and external latex run
|
// for the internal lyx-view and external latex run
|
||||||
string const name = fo_it->name();
|
string const name = fo_it->name();
|
||||||
if (name != "eps" && name != "xpm" && name != "png" &&
|
if (name != "eps" && name != "xpm" && name != "png" &&
|
||||||
converters.isReachable(*ex_it, name))
|
theConverters().isReachable(*ex_it, name))
|
||||||
to.push_back(&(*fo_it));
|
to.push_back(&(*fo_it));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public:
|
|||||||
bool Converter::isReachable(string const & from_format_name,
|
bool Converter::isReachable(string const & from_format_name,
|
||||||
string const & to_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 const edgepath = from_format.empty() ?
|
||||||
EdgePath() :
|
EdgePath() :
|
||||||
converters.getPath(from_format, to_format);
|
theConverters().getPath(from_format, to_format);
|
||||||
|
|
||||||
// Create a temporary base file-name for all intermediate steps.
|
// Create a temporary base file-name for all intermediate steps.
|
||||||
// Remember to remove the temp file because we only want the name...
|
// 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();
|
EdgePath::const_iterator end = edgepath.end();
|
||||||
|
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
lyx::Converter const & conv = converters.get(*it);
|
lyx::Converter const & conv = theConverters().get(*it);
|
||||||
|
|
||||||
// Build the conversion command
|
// Build the conversion command
|
||||||
string const infile = outfile;
|
string const infile = outfile;
|
||||||
|
@ -94,7 +94,7 @@ lyx::Converter const * setConverter()
|
|||||||
if (from == to)
|
if (from == to)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
lyx::Converter const * ptr = lyx::converters.getConverter(from, to);
|
lyx::Converter const * ptr = lyx::theConverters().getConverter(from, to);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -53,11 +53,11 @@ bool Importer::Import(LyXView * lv, FileName const & filename,
|
|||||||
if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
|
if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
|
||||||
for (vector<string>::const_iterator it = loaders.begin();
|
for (vector<string>::const_iterator it = loaders.begin();
|
||||||
it != loaders.end(); ++it) {
|
it != loaders.end(); ++it) {
|
||||||
if (converters.isReachable(format, *it)) {
|
if (theConverters().isReachable(format, *it)) {
|
||||||
string const tofile =
|
string const tofile =
|
||||||
changeExtension(filename.absFilename(),
|
changeExtension(filename.absFilename(),
|
||||||
formats.extension(*it));
|
formats.extension(*it));
|
||||||
if (!converters.convert(0, filename, FileName(tofile),
|
if (!theConverters().convert(0, filename, FileName(tofile),
|
||||||
filename, format, *it, errorList))
|
filename, format, *it, errorList))
|
||||||
return false;
|
return false;
|
||||||
loader_format = *it;
|
loader_format = *it;
|
||||||
@ -101,11 +101,11 @@ vector<Format const *> const Importer::GetImportableFormats()
|
|||||||
{
|
{
|
||||||
vector<string> loaders = Loaders();
|
vector<string> loaders = Loaders();
|
||||||
vector<Format const *> result =
|
vector<Format const *> result =
|
||||||
converters.getReachableTo(loaders[0], true);
|
theConverters().getReachableTo(loaders[0], true);
|
||||||
for (vector<string>::const_iterator it = loaders.begin() + 1;
|
for (vector<string>::const_iterator it = loaders.begin() + 1;
|
||||||
it != loaders.end(); ++it) {
|
it != loaders.end(); ++it) {
|
||||||
vector<Format const *> r =
|
vector<Format const *> r =
|
||||||
converters.getReachableTo(*it, false);
|
theConverters().getReachableTo(*it, false);
|
||||||
result.insert(result.end(), r.begin(), r.end());
|
result.insert(result.end(), r.begin(), r.end());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -230,7 +230,7 @@ void updateExternal(InsetExternalParams const & params,
|
|||||||
if (to_format.empty())
|
if (to_format.empty())
|
||||||
return; // NOT_NEEDED
|
return; // NOT_NEEDED
|
||||||
|
|
||||||
if (!converters.isReachable(from_format, to_format)) {
|
if (!theConverters().isReachable(from_format, to_format)) {
|
||||||
lyxerr[Debug::EXTERNAL]
|
lyxerr[Debug::EXTERNAL]
|
||||||
<< "external::updateExternal. "
|
<< "external::updateExternal. "
|
||||||
<< "Unable to convert from "
|
<< "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?
|
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
|
||||||
ErrorList el;
|
ErrorList el;
|
||||||
/* bool const success = */
|
/* 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,
|
params.filename, from_format, to_format, el,
|
||||||
Converters::try_default | Converters::try_cache);
|
Converters::try_default | Converters::try_cache);
|
||||||
// return success
|
// return success
|
||||||
|
@ -721,7 +721,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
|
|||||||
|
|
||||||
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
|
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
|
||||||
ErrorList el;
|
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,
|
from, to, el,
|
||||||
Converters::try_default | Converters::try_cache)) {
|
Converters::try_default | Converters::try_cache)) {
|
||||||
runparams.exportdata->addExternalFile(tex_format,
|
runparams.exportdata->addExternalFile(tex_format,
|
||||||
|
@ -150,6 +150,10 @@ struct LyX::Singletons
|
|||||||
{
|
{
|
||||||
Singletons(): iconv(ucs4_codeset, "UTF-8")
|
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
|
/// our function handler
|
||||||
LyXFunc lyxfunc_;
|
LyXFunc lyxfunc_;
|
||||||
@ -172,8 +176,14 @@ struct LyX::Singletons
|
|||||||
/// Files to load at start.
|
/// Files to load at start.
|
||||||
vector<FileName> files_to_load_;
|
vector<FileName> files_to_load_;
|
||||||
|
|
||||||
///
|
/// The messages translators.
|
||||||
map<string, Messages> messages_;
|
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()
|
IconvProcessor & LyX::iconvProcessor()
|
||||||
{
|
{
|
||||||
return pimpl_->iconv;
|
return pimpl_->iconv;
|
||||||
@ -800,8 +822,8 @@ bool LyX::init()
|
|||||||
if (!readRcFile("lyxrc.dist"))
|
if (!readRcFile("lyxrc.dist"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Set the User Interface language.
|
// Set the language defined by the distributor.
|
||||||
pimpl_->messages_["GUI"] = Messages();
|
//setGuiLanguage(lyxrc.gui_language);
|
||||||
|
|
||||||
// Set the PATH correctly.
|
// Set the PATH correctly.
|
||||||
#if !defined (USE_POSIX_PACKAGING)
|
#if !defined (USE_POSIX_PACKAGING)
|
||||||
@ -834,7 +856,7 @@ bool LyX::init()
|
|||||||
|
|
||||||
system_lyxrc = lyxrc;
|
system_lyxrc = lyxrc;
|
||||||
system_formats = formats;
|
system_formats = formats;
|
||||||
system_converters = converters;
|
pimpl_->system_converters_ = pimpl_->converters_;
|
||||||
system_movers = movers;
|
system_movers = movers;
|
||||||
system_lcolor = lcolor;
|
system_lcolor = lcolor;
|
||||||
|
|
||||||
@ -853,6 +875,9 @@ bool LyX::init()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (use_gui) {
|
if (use_gui) {
|
||||||
|
// Set the language defined by the user.
|
||||||
|
//setGuiLanguage(lyxrc.gui_language);
|
||||||
|
|
||||||
// Set up bindings
|
// Set up bindings
|
||||||
pimpl_->toplevel_keymap_.reset(new kb_keymap);
|
pimpl_->toplevel_keymap_.reset(new kb_keymap);
|
||||||
defaultKeyBindings(pimpl_->toplevel_keymap_.get());
|
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()
|
IconvProcessor & utf8ToUcs4()
|
||||||
{
|
{
|
||||||
return LyX::ref().iconvProcessor();
|
return LyX::ref().iconvProcessor();
|
||||||
|
@ -23,6 +23,7 @@ namespace lyx {
|
|||||||
|
|
||||||
class Buffer;
|
class Buffer;
|
||||||
class BufferList;
|
class BufferList;
|
||||||
|
class Converters;
|
||||||
class ErrorItem;
|
class ErrorItem;
|
||||||
class IconvProcessor;
|
class IconvProcessor;
|
||||||
class InsetBase;
|
class InsetBase;
|
||||||
@ -77,6 +78,10 @@ public:
|
|||||||
///
|
///
|
||||||
kb_keymap & topLevelKeymap();
|
kb_keymap & topLevelKeymap();
|
||||||
kb_keymap const & topLevelKeymap() const;
|
kb_keymap const & topLevelKeymap() const;
|
||||||
|
|
||||||
|
///
|
||||||
|
Converters & converters();
|
||||||
|
Converters & systemConverters();
|
||||||
|
|
||||||
///
|
///
|
||||||
Messages & getMessages(std::string const & language);
|
Messages & getMessages(std::string const & language);
|
||||||
|
22
src/lyxrc.C
22
src/lyxrc.C
@ -1052,9 +1052,9 @@ int LyXRC::read(LyXLex & lexrc)
|
|||||||
flags = lexrc.getString();
|
flags = lexrc.getString();
|
||||||
}
|
}
|
||||||
if (command.empty()) {
|
if (command.empty()) {
|
||||||
converters.erase(from, to);
|
theConverters().erase(from, to);
|
||||||
} else {
|
} else {
|
||||||
converters.add(from, to, command, flags);
|
theConverters().add(from, to, command, flags);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1118,7 +1118,7 @@ int LyXRC::read(LyXLex & lexrc)
|
|||||||
<< format << "'." << endl;
|
<< format << "'." << endl;
|
||||||
}
|
}
|
||||||
if (prettyname.empty()) {
|
if (prettyname.empty()) {
|
||||||
if (converters.formatIsUsed(format)) {
|
if (theConverters().formatIsUsed(format)) {
|
||||||
lyxerr << "Can't delete format "
|
lyxerr << "Can't delete format "
|
||||||
<< format << endl;
|
<< format << endl;
|
||||||
} else {
|
} else {
|
||||||
@ -1208,8 +1208,8 @@ int LyXRC::read(LyXLex & lexrc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Update converters data-structures
|
/// Update converters data-structures
|
||||||
converters.update(formats);
|
theConverters().update(formats);
|
||||||
converters.buildGraph();
|
theConverters().buildGraph();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2084,10 +2084,10 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
|
|||||||
|
|
||||||
case RC_CONVERTER:
|
case RC_CONVERTER:
|
||||||
// Look for new converters
|
// Look for new converters
|
||||||
for (Converters::const_iterator cit = converters.begin();
|
for (Converters::const_iterator cit = theConverters().begin();
|
||||||
cit != converters.end(); ++cit) {
|
cit != theConverters().end(); ++cit) {
|
||||||
Converter const * converter =
|
Converter const * converter =
|
||||||
system_converters.getConverter(cit->from,
|
theSystemConverters().getConverter(cit->from,
|
||||||
cit->to);
|
cit->to);
|
||||||
if (!converter ||
|
if (!converter ||
|
||||||
converter->command != cit->command ||
|
converter->command != cit->command ||
|
||||||
@ -2099,9 +2099,9 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New/modifed converters
|
// New/modifed converters
|
||||||
for (Converters::const_iterator cit = system_converters.begin();
|
for (Converters::const_iterator cit = theSystemConverters().begin();
|
||||||
cit != system_converters.end(); ++cit)
|
cit != theSystemConverters().end(); ++cit)
|
||||||
if (!converters.getConverter(cit->from, cit->to))
|
if (!theConverters().getConverter(cit->from, cit->to))
|
||||||
os << "\\converter \"" << cit->from
|
os << "\\converter \"" << cit->from
|
||||||
<< "\" \"" << cit->to << "\" \"\" \"\"\n";
|
<< "\" \"" << cit->to << "\" \"\" \"\"\n";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user