From 74f3ca32464641e84e67016cf664ec4316b4234e Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 17 Jan 2007 13:18:16 +0000 Subject: [PATCH] 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 --- src/converter.C | 8 ---- src/converter.h | 9 +++-- src/exporter.C | 14 +++---- src/frontends/controllers/ControlPrefs.C | 8 ++-- src/frontends/controllers/ControlSendto.C | 2 +- src/graphics/GraphicsConverter.C | 6 +-- src/graphics/PreviewLoader.C | 2 +- src/importer.C | 8 ++-- src/insets/ExternalSupport.C | 4 +- src/insets/insetgraphics.C | 2 +- src/lyx_main.C | 45 +++++++++++++++++++++-- src/lyx_main.h | 5 +++ src/lyxrc.C | 22 +++++------ 13 files changed, 86 insertions(+), 49 deletions(-) diff --git a/src/converter.C b/src/converter.C index 200e0a5a07..cfdf54ba01 100644 --- a/src/converter.C +++ b/src/converter.C @@ -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 diff --git a/src/converter.h b/src/converter.h index 0b75473c95..6350fd5fdc 100644 --- a/src/converter.h +++ b/src/converter.h @@ -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 diff --git a/src/exporter.C b/src/exporter.C index c45256208d..6121131b53 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -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::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 backends = Backends(buffer); for (vector::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 backends = Backends(buffer); vector result = - converters.getReachable(backends[0], only_viewable, true); + theConverters().getReachable(backends[0], only_viewable, true); for (vector::const_iterator it = backends.begin() + 1; it != backends.end(); ++it) { vector r = - converters.getReachable(*it, only_viewable, false); + theConverters().getReachable(*it, only_viewable, false); result.insert(result.end(), r.begin(), r.end()); } return result; diff --git a/src/frontends/controllers/ControlPrefs.C b/src/frontends/controllers/ControlPrefs.C index 5d8c2e2259..bdfd0a1e50 100644 --- a/src/frontends/controllers/ControlPrefs.C +++ b/src/frontends/controllers/ControlPrefs.C @@ -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_; diff --git a/src/frontends/controllers/ControlSendto.C b/src/frontends/controllers/ControlSendto.C index 0f979c6999..83570dc198 100644 --- a/src/frontends/controllers/ControlSendto.C +++ b/src/frontends/controllers/ControlSendto.C @@ -89,7 +89,7 @@ vector 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)); } } diff --git a/src/graphics/GraphicsConverter.C b/src/graphics/GraphicsConverter.C index 64b23bb38d..3a11012ba7 100644 --- a/src/graphics/GraphicsConverter.C +++ b/src/graphics/GraphicsConverter.C @@ -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; diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 840914a971..978355a8d8 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -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; } diff --git a/src/importer.C b/src/importer.C index ae07b15a5b..6b27af5191 100644 --- a/src/importer.C +++ b/src/importer.C @@ -53,11 +53,11 @@ bool Importer::Import(LyXView * lv, FileName const & filename, if (find(loaders.begin(), loaders.end(), format) == loaders.end()) { for (vector::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 const Importer::GetImportableFormats() { vector loaders = Loaders(); vector result = - converters.getReachableTo(loaders[0], true); + theConverters().getReachableTo(loaders[0], true); for (vector::const_iterator it = loaders.begin() + 1; it != loaders.end(); ++it) { vector r = - converters.getReachableTo(*it, false); + theConverters().getReachableTo(*it, false); result.insert(result.end(), r.begin(), r.end()); } return result; diff --git a/src/insets/ExternalSupport.C b/src/insets/ExternalSupport.C index 7b769cd956..fd3727242e 100644 --- a/src/insets/ExternalSupport.C +++ b/src/insets/ExternalSupport.C @@ -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 diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index a012012cf3..8f527bd701 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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, diff --git a/src/lyx_main.C b/src/lyx_main.C index c0fbb68ab6..95b1a85772 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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 files_to_load_; - /// + /// The messages translators. map 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(); diff --git a/src/lyx_main.h b/src/lyx_main.h index 01357b8853..78427b7573 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -23,6 +23,7 @@ namespace lyx { class Buffer; class BufferList; +class Converters; class ErrorItem; class IconvProcessor; class InsetBase; @@ -77,6 +78,10 @@ public: /// kb_keymap & topLevelKeymap(); kb_keymap const & topLevelKeymap() const; + + /// + Converters & converters(); + Converters & systemConverters(); /// Messages & getMessages(std::string const & language); diff --git a/src/lyxrc.C b/src/lyxrc.C index 439317d9f1..6c204543c1 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -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";