]> git.lyx.org Git - features.git/commitdiff
Transfer the global converters and system_converters variables to LyX::Singletons...
authorAbdelrazak Younes <younes@lyx.org>
Wed, 17 Jan 2007 13:18:16 +0000 (13:18 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 17 Jan 2007 13:18:16 +0000 (13:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16725 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/converter.C
src/converter.h
src/exporter.C
src/frontends/controllers/ControlPrefs.C
src/frontends/controllers/ControlSendto.C
src/graphics/GraphicsConverter.C
src/graphics/PreviewLoader.C
src/importer.C
src/insets/ExternalSupport.C
src/insets/insetgraphics.C
src/lyx_main.C
src/lyx_main.h
src/lyxrc.C

index 200e0a5a0714d68799a82ee226e8e019234e18d6..cfdf54ba016ed7ce8f37140195f0207ed20d885b 100644 (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
index 0b75473c95ab4645d81106384cb7ba8fb9eeed7b..6350fd5fdc98a623bb10e4af730386053bb309d4 100644 (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
 
index c45256208da4349ec139565e9a373f71580db98d..6121131b53959a44eaf3a40d0e6a97dac793d9ab 100644 (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;
index 5d8c2e2259b69d7183a9e8a91cd0dcf934fd0781..bdfd0a1e50763000f0f8470796d1857ea485aa51 100644 (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_;
 
index 0f979c69999dff6daa676b3fccc2dfcb62dd770b..83570dc1984cca48750cfc212af3b103153deb18 100644 (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));
                }
        }
index 64b23bb38d43a82ae4c3d914375bac318191f8e7..3a11012ba7ed81d67a7d7c73f8b54e0b652ae236 100644 (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;
index 840914a9719b6e1efc0186430142b5b04facf38b..978355a8d80ef4a081d961d8434e279af8541bc8 100644 (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;
        }
index ae07b15a5bd0c6c429f3cdb18888b61be804c6c9..6b27af5191ffbd19048abb7ce2ff46d388061659 100644 (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;
index 7b769cd9565664d28ee323f6bb4de90308ac2ff0..fd3727242e8f8168c7d5f366a44d9a41121509f9 100644 (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
index a012012cf302bb21c0cafd520d96648681ad196e..8f527bd701870f33cd0c5037544108b40de3f658 100644 (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,
index c0fbb68ab6c37ef9522d8e17da91edf439cf1b21..95b1a857723c7c8e979af4f2e652596d5f9a3e7e 100644 (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();
index 01357b88539e0adaf4bba3381263a54e9e8c3e0e..78427b757300e4be690209894fad001b8b242b9c 100644 (file)
@@ -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);
index 439317d9f1142173ea467b3c4eab1f909ddb6ba9..6c204543c1aeaded36a6314d811cd9cc868904a6 100644 (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";