]> git.lyx.org Git - features.git/commitdiff
Move the global formats and system_formats variables into the
authorRichard Heck <rgheck@lyx.org>
Tue, 14 Mar 2017 03:33:40 +0000 (23:33 -0400)
committerRichard Heck <rgheck@lyx.org>
Tue, 14 Mar 2017 03:40:29 +0000 (23:40 -0400)
LyX singleton.

Mostly, this is very boring, but it might be good if someone would
check what I did about the dummy implementation in tex2lyx.

24 files changed:
src/Buffer.cpp
src/Converter.cpp
src/ConverterCache.cpp
src/Format.cpp
src/Format.h
src/Graph.cpp
src/Lexer.cpp
src/LyX.cpp
src/LyX.h
src/LyXRC.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiViewSource.cpp
src/frontends/qt4/Menus.cpp
src/graphics/GraphicsCache.cpp
src/graphics/GraphicsCacheItem.cpp
src/graphics/GraphicsConverter.cpp
src/graphics/epstools.cpp
src/insets/ExternalSupport.cpp
src/insets/InsetBibtex.cpp
src/insets/InsetGraphics.cpp
src/insets/InsetHyperlink.cpp
src/insets/InsetInclude.cpp
src/tex2lyx/dummy_impl.cpp

index 84b5e6ced529dd6d6d1c87379490d9eb4664bac2..a20b4da3db5abdc18e77603eb21493e267e159b9 100644 (file)
@@ -834,7 +834,7 @@ string Buffer::logName(LogType * type) const
        FileName const bname(
                addName(path, onlyFileName(
                        changeExtension(filename,
-                                       formats.extension(params().bufferFormat()) + ".out"))));
+                                       theFormats().extension(params().bufferFormat()) + ".out"))));
 
        // Also consider the master buffer log file
        FileName masterfname = fname;
@@ -1085,7 +1085,7 @@ bool Buffer::readDocument(Lexer & lex)
 
 bool Buffer::importString(string const & format, docstring const & contents, ErrorList & errorList)
 {
-       Format const * fmt = formats.getFormat(format);
+       Format const * fmt = theFormats().getFormat(format);
        if (!fmt)
                return false;
        // It is important to use the correct extension here, since some
@@ -1199,7 +1199,7 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn)
 
        d->file_fully_loaded = true;
        d->read_only = !d->filename.isWritable();
-       params().compressed = formats.isZippedFile(d->filename);
+       params().compressed = theFormats().isZippedFile(d->filename);
        saveCheckSum();
        return ReadSuccess;
 }
@@ -2689,7 +2689,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
        case LFUN_BUFFER_EXPORT_CUSTOM: {
                string format_name;
                string command = split(argument, format_name, ' ');
-               Format const * format = formats.getFormat(format_name);
+               Format const * format = theFormats().getFormat(format_name);
                if (!format) {
                        lyxerr << "Format \"" << format_name
                                << "\" not recognized!"
@@ -2848,7 +2848,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
        }
 
        case LFUN_BUFFER_VIEW_CACHE:
-               if (!formats.view(*this, d->preview_file_,
+               if (!theFormats().view(*this, d->preview_file_,
                                  d->preview_format_))
                        dr.setMessage(_("Error viewing the output file."));
                break;
@@ -4281,7 +4281,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
                                // file (not for previewing).
                                Alert::error(_("Couldn't export file"), bformat(
                                        _("No information for exporting the format %1$s."),
-                                       formats.prettyName(format)));
+                                       theFormats().prettyName(format)));
                        }
                        return ExportNoPathToFormat;
                }
@@ -4311,7 +4311,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
        string filename = latexName(false);
        filename = addName(temppath(), filename);
        filename = changeExtension(filename,
-                                  formats.extension(backend_format));
+                                  theFormats().extension(backend_format));
        LYXERR(Debug::FILES, "filename=" << filename);
 
        // Plain text backend
@@ -4357,7 +4357,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
        string const error_type = (format == "program")
                ? "Build" : params().bufferFormat();
        ErrorList & error_list = d->errorLists[error_type];
-       string const ext = formats.extension(format);
+       string const ext = theFormats().extension(format);
        FileName const tmp_result_file(changeExtension(filename, ext));
        bool const success = converters.convert(this, FileName(filename),
                tmp_result_file, FileName(absFileName()), backend_format, format,
@@ -4425,7 +4425,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
        vector<ExportedFile>::const_iterator it = files.begin();
        vector<ExportedFile>::const_iterator const en = files.end();
        for (; it != en && status != CANCEL; ++it) {
-               string const fmt = formats.getFormatFromFile(it->sourceName);
+               string const fmt = theFormats().getFormatFromFile(it->sourceName);
                string fixedName = it->exportName;
                if (!runparams.export_folder.empty()) {
                        // Relative pathnames starting with ../ will be sanitized
@@ -4461,13 +4461,13 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
                } else {
                        message(bformat(_("Document exported as %1$s "
                                "to file `%2$s'"),
-                               formats.prettyName(format),
+                               theFormats().prettyName(format),
                                makeDisplayPath(result_file)));
                }
        } else {
                // This must be a dummy converter like fax (bug 1888)
                message(bformat(_("Document exported as %1$s"),
-                       formats.prettyName(format)));
+                       theFormats().prettyName(format)));
        }
 
        return success ? ExportSuccess : ExportConverterError;
@@ -4506,7 +4506,7 @@ Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) con
                return status;
 
        if (previewFile.exists())
-               return formats.view(*this, previewFile, format) ?
+               return theFormats().view(*this, previewFile, format) ?
                        PreviewSuccess : PreviewError;
 
        // Successful export but no output file?
index 9d9d602ec572eaa8df2b58321a0bb8a90cd19e81..2c1ae2d87827a17e9464d3a7b99c6d7b9ebbf42f 100644 (file)
@@ -134,7 +134,7 @@ void Converter::readFlags()
                        need_auth_ = true;
        }
        if (!result_dir_.empty() && result_file_.empty())
-               result_file_ = "index." + formats.extension(to_);
+               result_file_ = "index." + theFormats().extension(to_);
        //if (!contains(command, token_from))
        //      latex = true;
 }
@@ -168,8 +168,8 @@ int Converters::getNumber(string const & from, string const & to) const
 void Converters::add(string const & from, string const & to,
                     string const & command, string const & flags)
 {
-       formats.add(from);
-       formats.add(to);
+       theFormats().add(from);
+       theFormats().add(to);
        ConverterList::iterator it = find_if(converterlist_.begin(),
                                             converterlist_.end(),
                                             ConverterEqual(from , to));
@@ -235,8 +235,8 @@ void Converters::update(Formats const & formats)
        ConverterList::iterator it = converterlist_.begin();
        ConverterList::iterator end = converterlist_.end();
        for (; it != end; ++it) {
-               it->setFrom(formats.getFormat(it->from()));
-               it->setTo(formats.getFormat(it->to()));
+               it->setFrom(theFormats().getFormat(it->from()));
+               it->setTo(theFormats().getFormat(it->to()));
        }
 }
 
@@ -247,8 +247,8 @@ void Converters::updateLast(Formats const & formats)
 {
        if (converterlist_.begin() != converterlist_.end()) {
                ConverterList::iterator it = converterlist_.end() - 1;
-               it->setFrom(formats.getFormat(it->from()));
-               it->setTo(formats.getFormat(it->to()));
+               it->setFrom(theFormats().getFormat(it->from()));
+               it->setTo(theFormats().getFormat(it->to()));
        }
 }
 
@@ -350,8 +350,8 @@ bool Converters::convert(Buffer const * buffer,
                        // default one from ImageMagic.
                        string const from_ext = from_format.empty() ?
                                getExtension(from_file.absFileName()) :
-                               formats.extension(from_format);
-                       string const to_ext = formats.extension(to_format);
+                               theFormats().extension(from_format);
+                       string const to_ext = theFormats().extension(to_format);
                        string const command =
                                os::python() + ' ' +
                                quoteName(libFileSearch("scripts", "convertDefault.py").toFilesystemEncoding()) +
@@ -761,15 +761,15 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command,
 void Converters::buildGraph()
 {
        // clear graph's data structures
-       G_.init(formats.size());
+       G_.init(theFormats().size());
        // each of the converters knows how to convert one format to another
        // so, for each of them, we create an arrow on the graph, going from
        // the one to the other
        ConverterList::iterator it = converterlist_.begin();
        ConverterList::iterator const end = converterlist_.end();
        for (; it != end ; ++it) {
-               int const from = formats.getNumber(it->from());
-               int const to   = formats.getNumber(it->to());
+               int const from = theFormats().getNumber(it->from());
+               int const to   = theFormats().getNumber(it->to());
                LASSERT(from >= 0, continue);
                LASSERT(to >= 0, continue);
                G_.addEdge(from, to);
@@ -785,7 +785,7 @@ FormatList const Converters::intToFormat(vector<int> const & input)
        vector<int>::const_iterator const end = input.end();
        FormatList::iterator rit = result.begin();
        for ( ; it != end; ++it, ++rit) {
-               *rit = &formats.get(*it);
+               *rit = &theFormats().get(*it);
        }
        return result;
 }
@@ -795,7 +795,7 @@ FormatList const Converters::getReachableTo(string const & target,
                bool const clear_visited)
 {
        vector<int> const & reachablesto =
-               G_.getReachableTo(formats.getNumber(target), clear_visited);
+               G_.getReachableTo(theFormats().getNumber(target), clear_visited);
 
        return intToFormat(reachablesto);
 }
@@ -810,10 +810,10 @@ FormatList const Converters::getReachable(string const & from,
        set<string>::const_iterator sit = excludes.begin();
        set<string>::const_iterator const end = excludes.end();
        for (; sit != end; ++sit)
-               excluded_numbers.insert(formats.getNumber(*sit));
+               excluded_numbers.insert(theFormats().getNumber(*sit));
 
        vector<int> const & reachables =
-               G_.getReachable(formats.getNumber(from),
+               G_.getReachable(theFormats().getNumber(from),
                                only_viewable,
                                clear_visited,
                                excluded_numbers);
@@ -824,15 +824,15 @@ FormatList const Converters::getReachable(string const & from,
 
 bool Converters::isReachable(string const & from, string const & to)
 {
-       return G_.isReachable(formats.getNumber(from),
-                             formats.getNumber(to));
+       return G_.isReachable(theFormats().getNumber(from),
+                             theFormats().getNumber(to));
 }
 
 
 Graph::EdgePath Converters::getPath(string const & from, string const & to)
 {
-       return G_.getPath(formats.getNumber(from),
-                         formats.getNumber(to));
+       return G_.getPath(theFormats().getNumber(from),
+                         theFormats().getNumber(to));
 }
 
 
index 7590336411548428ea2f8020ecd85026a49af5bb..3842ebb419d23075580abf37e62d7b3a418571e7 100644 (file)
@@ -163,7 +163,7 @@ void ConverterCache::Impl::readIndex()
                                // cached files on opening. This slows LyX startup a lot. It
                                // would be better if this information was retrieved in a
                                // delayed fashion.
-                               formats.getFormatFromFile(orig_from_name);
+                               theFormats().getFormatFromFile(orig_from_name);
                format_cache.cache[to_format] = item;
        }
        is.close();
@@ -320,7 +320,7 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format,
                        FormatCache & format_cache = pimpl_->cache[orig_from];
                        if (format_cache.from_format.empty())
                                format_cache.from_format =
-                                       formats.getFormatFromFile(orig_from);
+                                       theFormats().getFormatFromFile(orig_from);
                        format_cache.cache[to_format] = new_item;
                } else
                        LYXERR(Debug::FILES, "ConverterCache::add(" << orig_from << "):\n"
index d0f83a20046ebb04eed7be53c1ed9feefb98fab5..4a33eb07c49e97c80ef4548979b00029500c9dc4 100644 (file)
@@ -872,9 +872,4 @@ OutputParams::FLAVOR format2flavor(std::string fmt)
        return flavorTranslator().find(fmt);
 } */
 
-Formats formats;
-
-Formats system_formats;
-
-
 } // namespace lyx
index e076934cb5935ec3055d37f45b09401afa5beed5..cc383c02497820d8a127b56a29afcf79c607abe9 100644 (file)
@@ -217,10 +217,13 @@ std::string flavor2format(OutputParams::FLAVOR flavor);
 // Not currently used.
 // OutputParams::FLAVOR format2flavor(std::string fmt);
 
-extern Formats formats;
-
-extern Formats system_formats;
+/// The global instance.
+/// Implementation is in LyX.cpp.
+extern Formats & theFormats();
 
+/// The global copy after reading lyxrc.defaults.
+/// Implementation is in LyX.cpp.
+extern Formats & theSystemFormats();
 
 } // namespace lyx
 
index 97427bcf1a662566b720ca1a89612099523eb072..0573cd2162bdcba8bbf80083305ef9e818da98aa 100644 (file)
@@ -63,7 +63,7 @@ Graph::EdgePath const
        while (!Q.empty()) {
                int const current = Q.front();
                Q.pop();
-               if (current != target || formats.get(target).name() != "lyx")
+               if (current != target || theFormats().get(target).name() != "lyx")
                        result.push_back(current);
 
                vector<Arrow *>::iterator it = vertices_[current].in_arrows.begin();
@@ -93,12 +93,12 @@ Graph::EdgePath const
        while (!Q.empty()) {
                int const current = Q.front();
                Q.pop();
-               Format const & format = formats.get(current);
+               Format const & format = theFormats().get(current);
                if (!only_viewable || !format.viewer().empty())
                        result.push_back(current);
                else if (format.isChildFormat()) {
                        Format const * const parent =
-                               formats.getFormat(format.parentFormat());
+                               theFormats().getFormat(format.parentFormat());
                        if (parent && !parent->viewer().empty())
                                result.push_back(current);
                }
index 78bf9f49c23394c86c265eabbadebd911d349b67..bbae12418c0bd1da6abfd542a6cdbc63b2e1976b 100644 (file)
@@ -239,7 +239,7 @@ void Lexer::Pimpl::popTable()
 bool Lexer::Pimpl::setFile(FileName const & filename)
 {
        // Check the format of the file.
-       if (formats.isZippedFile(filename)) {
+       if (theFormats().isZippedFile(filename)) {
                LYXERR(Debug::LYXLEX, "lyxlex: compressed");
                // The check only outputs a debug message, because it triggers
                // a bug in compaq cxx 6.2, where is_open() returns 'true' for
index c88e205919b79e62481088751ca54095961959d1..f0fc71cfe955654c8ec4b00b1d96403382f11b8b 100644 (file)
@@ -190,9 +190,14 @@ struct LyX::Impl {
 
        /// The file converters.
        Converters converters_;
-
-       // The system converters copy after reading lyxrc.defaults.
+       /// The system converters after reading lyxrc.defaults.
        Converters system_converters_;
+       
+       /// Global format information
+       Formats formats_;
+       /// The system formats after reading lyxrc.defaults.
+       Formats system_formats_;
+
 
        ///
        Movers movers_;
@@ -938,13 +943,13 @@ bool LyX::init()
                return false;
 
        // Query the OS to know what formats are viewed natively
-       formats.setAutoOpen();
+       theFormats().setAutoOpen();
 
        // Read lyxrc.dist again to be able to override viewer auto-detection.
        readRcFile("lyxrc.dist");
 
        system_lyxrc = lyxrc;
-       system_formats = formats;
+       theSystemFormats() = theFormats();
        pimpl_->system_converters_ = pimpl_->converters_;
        pimpl_->system_movers_ = pimpl_->movers_;
        system_lcolor = lcolor;
@@ -1499,17 +1504,31 @@ KeyMap & theTopLevelKeymap()
 }
 
 
+Formats & theFormats()
+{
+       LAPPERR(singleton_);
+       return singleton_->pimpl_->formats_;
+}
+
+
+Formats & theSystemFormats()
+{
+       LAPPERR(singleton_);
+       return singleton_->pimpl_->system_formats_;
+}
+
+
 Converters & theConverters()
 {
        LAPPERR(singleton_);
-       return  singleton_->pimpl_->converters_;
+       return singleton_->pimpl_->converters_;
 }
 
 
 Converters & theSystemConverters()
 {
        LAPPERR(singleton_);
-       return  singleton_->pimpl_->system_converters_;
+       return singleton_->pimpl_->system_converters_;
 }
 
 
index 85decbc6d66e3837eb6e36e38bc2ed4e1cbdd190..162151286aafe72ecc736621141c04a42b839611 100644 (file)
--- a/src/LyX.h
+++ b/src/LyX.h
@@ -25,6 +25,7 @@ class CmdDef;
 class Converters;
 class DispatchResult;
 class ErrorItem;
+class Formats;
 class FuncRequest;
 class FuncStatus;
 class KeyMap;
@@ -139,6 +140,8 @@ private:
        friend ServerSocket & theServerSocket();
        friend Converters & theConverters();
        friend Converters & theSystemConverters();
+       friend Formats & theFormats();
+       friend Formats & theSystemFormats();
        friend Messages const & getMessages(std::string const & language);
        friend Messages const & getGuiMessages();
        friend KeyMap & theTopLevelKeymap();
index 34998f2b63ff1d5796eaae90fa1fe1915e5920c2..94e78376f5a3fbe0de9abe829df5eb7616bb346e 100644 (file)
@@ -994,7 +994,7 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
                case RC_VIEWER: {
                        string format, command;
                        lexrc >> format >> command;
-                       formats.setViewer(format, command);
+                       theFormats().setViewer(format, command);
                        break;
                }
                case RC_FILEFORMAT: {
@@ -1045,9 +1045,9 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
                                if (theConverters().formatIsUsed(format))
                                        LYXERR0("Can't delete format " << format);
                                else
-                                       formats.erase(format);
+                                       theFormats().erase(format);
                        } else {
-                               formats.add(format, extensions, prettyname,
+                               theFormats().add(format, extensions, prettyname,
                                            shortcut, viewer, editor, mime, flgs);
                        }
                        break;
@@ -1227,7 +1227,7 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
        }
 
        /// Update converters data-structures
-       theConverters().update(formats);
+       theConverters().update(theFormats());
        theConverters().buildGraph();
        theBufferList().invalidateConverterCache();
 
@@ -2558,10 +2558,10 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
 
        case RC_FILEFORMAT:
                // New/modified formats
-               for (Formats::const_iterator cit = formats.begin();
-                    cit != formats.end(); ++cit) {
+               for (Formats::const_iterator cit = theFormats().begin(); 
+                    cit != theFormats().end(); ++cit) {
                        Format const * format =
-                               system_formats.getFormat(cit->name());
+                               theSystemFormats().getFormat(cit->name());
                        if (!format ||
                            format->extensions() != cit->extensions() ||
                            format->prettyname() != cit->prettyname() ||
@@ -2594,9 +2594,9 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
 
                // Look for deleted formats
-               for (Formats::const_iterator cit = system_formats.begin();
-                    cit != system_formats.end(); ++cit)
-                       if (!formats.getFormat(cit->name()))
+               for (Formats::const_iterator cit = theSystemFormats().begin(); 
+                    cit != theSystemFormats().end(); ++cit)
+                       if (!theFormats().getFormat(cit->name()))
                                os << "\\format \"" << cit->name()
                                   << "\" \"\" \"\" \"\" \"\" \"\" \"\" \"\"\n";
                if (tag != RC_LAST)
index de3fcfdde5bcfd1c8132e66658e7cd14c404fc32..1d8bb201ff0dfc813a9e14d5d83acf749e115023 100644 (file)
@@ -3491,7 +3491,7 @@ void GuiPreferences::applyView()
 bool GuiPreferences::initialiseParams(string const &)
 {
        rc_ = lyxrc;
-       formats_ = lyx::formats;
+       formats_ = theFormats();
        converters_ = theConverters();
        converters_.update(formats_);
        movers_ = theMovers();
@@ -3522,10 +3522,10 @@ void GuiPreferences::dispatchParams()
                Author(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
        theBufferList().recordCurrentAuthor(author);
 
-       lyx::formats = formats_;
+       theFormats() = formats_;
 
        theConverters() = converters_;
-       theConverters().update(lyx::formats);
+       theConverters().update(formats_);
        theConverters().buildGraph();
        theBufferList().invalidateConverterCache();
        
index 1f1ec6126d38fa87056be2c032142a92c488f272..fe2646acdfe9af09b4ae5137410a6704664c6f8b 100644 (file)
@@ -652,7 +652,7 @@ QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
 static void handleExportStatus(GuiView * view, Buffer::ExportStatus status,
        string const & format)
 {
-       docstring const fmt = formats.prettyName(format);
+       docstring const fmt = theFormats().prettyName(format);
        docstring msg;
        switch (status) {
        case Buffer::ExportSuccess:
@@ -2231,7 +2231,7 @@ static bool import(GuiView * lv, FileName const & filename,
 
                        string const tofile =
                                support::changeExtension(filename.absFileName(),
-                               formats.extension(*it));
+                               theFormats().extension(*it));
                        if (!theConverters().convert(0, filename, FileName(tofile),
                                filename, format, *it, errorList))
                                return false;
@@ -2241,7 +2241,7 @@ static bool import(GuiView * lv, FileName const & filename,
                if (loader_format.empty()) {
                        frontend::Alert::error(_("Couldn't import file"),
                                         bformat(_("No information for importing the format %1$s."),
-                                        formats.prettyName(format)));
+                                        theFormats().prettyName(format)));
                        return false;
                }
        } else
@@ -2259,7 +2259,7 @@ static bool import(GuiView * lv, FileName const & filename,
                bool as_paragraphs = loader_format == "textparagraph";
                string filename2 = (loader_format == format) ? filename.absFileName()
                        : support::changeExtension(filename.absFileName(),
-                                         formats.extension(loader_format));
+                                         theFormats().extension(loader_format));
                lv->currentBufferView()->insertPlaintextFile(FileName(filename2),
                        as_paragraphs);
                guiApp->setCurrentView(lv);
@@ -2288,17 +2288,17 @@ void GuiView::importDocument(string const & argument)
                }
 
                docstring const text = bformat(_("Select %1$s file to import"),
-                       formats.prettyName(format));
+                       theFormats().prettyName(format));
 
                FileDialog dlg(toqstr(text));
                dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
                dlg.setButton2(qt_("Examples|#E#e"),
                        toqstr(addPath(package().system_support().absFileName(), "examples")));
 
-               docstring filter = formats.prettyName(format);
+               docstring filter = theFormats().prettyName(format);
                filter += " (*.{";
                // FIXME UNICODE
-               filter += from_utf8(formats.extensions(format));
+               filter += from_utf8(theFormats().extensions(format));
                filter += "})";
 
                FileDialog::Result result =
@@ -2592,7 +2592,7 @@ bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat)
        types << anyformat;
 
        vector<Format const *> export_formats;
-       for (Format const & f : formats)
+       for (Format const & f : theFormats())
                if (f.documentFormat())
                        export_formats.push_back(&f);
        sort(export_formats.begin(), export_formats.end(), Format::formatSorter);
@@ -2625,7 +2625,7 @@ bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat)
        string fmt_name;
        fname.set(fromqstr(result.second));
        if (filter == anyformat)
-               fmt_name = formats.getFormatFromExtension(fname.extension());
+               fmt_name = theFormats().getFormatFromExtension(fname.extension());
        else
                fmt_name = fmap[filter];
        LYXERR(Debug::FILES, "filter=" << fromqstr(filter)
index fe593875e6585e9fab6d368fb607ff03158cd5f1..03b7d60b8f9baca8a569ab86444b8b677d72b6c7 100644 (file)
@@ -303,7 +303,7 @@ docstring ViewSourceWidget::currentFormatName(BufferView const * bv) const
        // Compute the actual format used
        string const format = !bv ? ""
                : flavor2format(bv->buffer().params().getOutputFlavor(view_format_));
-       Format const * f = formats.getFormat(format.empty() ? view_format_ : format);
+       Format const * f = theFormats().getFormat(format.empty() ? view_format_ : format);
        return f ? f->prettyname() : from_utf8(view_format_);
 }
 
@@ -343,7 +343,7 @@ void ViewSourceWidget::updateDefaultFormat(BufferView const & bv)
        vector<string>::const_iterator en = tmp.end();
        for (; it != en; ++it) {
                string const format = *it;
-               Format const * fmt = formats.getFormat(format);
+               Format const * fmt = theFormats().getFormat(format);
                if (!fmt) {
                        LYXERR0("Can't find format for backend " << format << "!");
                        continue;
index e510054328c873738418aaf9d6ed3478325306e8..faab3390014938d21bb64c7a112df2fcefbfd2c8 100644 (file)
@@ -2192,7 +2192,7 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
                        if (!buf)
                                break;
                        string const format = buf->params().getDefaultOutputFormat();
-                       Format const * f = formats.getFormat(format);
+                       Format const * f = theFormats().getFormat(format);
                        docstring const name = f ? f->prettyname() : from_utf8(format);
                        docstring const label = bformat(_("Export [%1$s]|E"), name);
                        MenuItem item(MenuItem::Command, toqstr(label),
index a3b8ebd3a9e835fbb106ba26586211532f0c057f..c915938884c6b80b6545b9a7b1a6989fac2d56da 100644 (file)
@@ -71,8 +71,8 @@ vector<string> const & Cache::loadableFormats() const
                return fmts;
 
        // The formats recognised by LyX
-       Formats::const_iterator begin = formats.begin();
-       Formats::const_iterator end   = formats.end();
+       Formats::const_iterator begin = theFormats().begin();
+       Formats::const_iterator end   = theFormats().end();
 
        // The formats natively loadable.
        vector<string> nformat = frontend::loadableImageFormats();
index 9eb449a1f85cfefcefdda3c531c7314be6f58b11..0bd3779a4f0042a4ce052215dae962afb62e1531 100644 (file)
@@ -318,10 +318,10 @@ bool CacheItem::Impl::loadImage()
 
 typedef vector<string> FormatList;
 
-static string const findTargetFormat(FormatList const & formats, string const & from)
+static string const findTargetFormat(FormatList const & format_list, string const & from)
 {
         // There must be a format to load from.
-       LASSERT(!formats.empty(), return string());
+       LASSERT(!theFormats().empty(), return string());
 
        // Use the standard converter if we don't know the format to load
        // from.
@@ -329,15 +329,15 @@ static string const findTargetFormat(FormatList const & formats, string const &
                return string("ppm");
 
        // First ascertain if we can load directly with no conversion
-       FormatList::const_iterator it  = formats.begin();
-       FormatList::const_iterator end = formats.end();
+       FormatList::const_iterator it  = format_list.begin();
+       FormatList::const_iterator end = format_list.end();
        for (; it != end; ++it) {
                if (from == *it)
                        return *it;
        }
 
        // So, we have to convert to a loadable format. Can we?
-       it = formats.begin();
+       it = format_list.begin();
        for (; it != end; ++it) {
                if (lyx::graphics::Converter::isReachable(from, *it))
                        return *it;
@@ -364,7 +364,7 @@ bool CacheItem::Impl::tryDisplayFormat(FileName & filename, string & from)
                return false;
        }
 
-       zipped_ = formats.isZippedFile(filename_);
+       zipped_ = theFormats().isZippedFile(filename_);
        if (zipped_) {
                string tempname = unzippedFileName(filename_.toFilesystemEncoding());
                string const ext = getExtension(tempname);
@@ -389,7 +389,7 @@ bool CacheItem::Impl::tryDisplayFormat(FileName & filename, string & from)
                << "\tAttempting to convert image file: " << filename
                << "\n\twith displayed filename: " << to_utf8(displayed_filename));
 
-       from = formats.getFormatFromFile(filename);
+       from = theFormats().getFormatFromFile(filename);
        if (from.empty()) {
                status_ = ErrorConverting;
                LYXERR(Debug::GRAPHICS, "\tCould not determine file format.");
index 55ae24624b0992334b4623a6f9495b04bfb68b7b..84cbaf9b1aa1dd26de64052fb5f179ce278b8a2d 100644 (file)
@@ -139,7 +139,7 @@ Converter::Impl::Impl(FileName const & doc_fname,
        // The converted image is to be stored in this file (we do not
        // use ChangeExtension because this is a basename which may
        // nevertheless contain a '.')
-       to_file_ = FileName(to_file_base + '.' +  formats.extension(to_format));
+       to_file_ = FileName(to_file_base + '.' +  theFormats().extension(to_format));
 
        // The conversion commands are stored in a stringstream
        ostringstream script;
index 2fd67dcf8a8b095a7374c56338ea3e6513bd7301..d5674ba7d18205c168bb05318e9165ba34469bc6 100644 (file)
@@ -47,9 +47,9 @@ string const readBB_from_PSFile(FileName const & file)
        // end of the file. Than we have in the header:
        // %%BoundingBox: (atend)
        // In this case we must check the end.
-       bool const zipped = formats.isZippedFile(file);
+       bool const zipped = theFormats().isZippedFile(file);
        FileName const file_ = zipped ? unzipFile(file) : file;
-       string const format = formats.getFormatFromFile(file_);
+       string const format = theFormats().getFormatFromFile(file_);
 
        if (!Formats::isPostScriptFileFormat(format)) {
                LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] no(e)ps-format");
index 37c382a37f64cf6b8a4636c95f3b946a9024a7a7..469df20cb92aea63577826e49cafc200f08aac30 100644 (file)
@@ -51,8 +51,8 @@ Template const * getTemplatePtr(InsetExternalParams const & params)
 
 void editExternal(InsetExternalParams const & params, Buffer const & buffer)
 {
-       formats.edit(buffer, params.filename, 
-               formats.getFormatFromFile(params.filename));
+       theFormats().edit(buffer, params.filename, 
+               theFormats().getFormatFromFile(params.filename));
 }
 
 
@@ -89,7 +89,7 @@ string const doSubstitution(InsetExternalParams const & params,
                // This is for raster images and pdflatex:
                // Since pdflatex supports both jpg and png, we choose the best format:
                // jpg if the original file is jpg to retain the compression, else png.
-               string format = formats.getFormatFromFile(params.filename);
+               string format = theFormats().getFormatFromFile(params.filename);
                if (format == "jpg")
                        result = subst(result, "$$pngOrjpg", "jpg");
                else
@@ -245,7 +245,7 @@ void updateExternal(InsetExternalParams const & params,
                        return; // NOT_NEEDED
 
                // Try and ascertain the file format from its contents.
-               from_format = formats.getFormatFromFile(params.filename);
+               from_format = theFormats().getFormatFromFile(params.filename);
                if (from_format.empty())
                        return; // FAILURE
        }
index 45b297111e00973321fee20f6f5d4146839eee7b..ef794814aea8fb3bb4c8e671d04cc1a6b5e311bf 100644 (file)
@@ -164,8 +164,8 @@ void InsetBibtex::editDatabases() const
        vector<docstring>::const_iterator en = bibfilelist.end();
        for (; it != en; ++it) {
                FileName const bibfile = getBibTeXPath(*it, buffer());
-               formats.edit(buffer(), bibfile,
-                    formats.getFormatFromFile(bibfile));
+               theFormats().edit(buffer(), bibfile,
+                    theFormats().getFormatFromFile(bibfile));
        }
 }
 
index b41d72bc70083d132742ee48ef3b851aeb576251..1582874211b83d64acd08b3d495d75c08af28dcf 100644 (file)
@@ -107,7 +107,7 @@ string findTargetFormat(string const & format, OutputParams const & runparams)
            || runparams.flavor == OutputParams::XETEX
            || runparams.flavor == OutputParams::LUATEX) {
                LYXERR(Debug::GRAPHICS, "findTargetFormat: PDF mode");
-               Format const * const f = formats.getFormat(format);
+               Format const * const f = theFormats().getFormat(format);
                // Convert vector graphics to pdf
                if (f && f->vectorFormat())
                        return "pdf6";
@@ -119,7 +119,7 @@ string findTargetFormat(string const & format, OutputParams const & runparams)
        }
        // for HTML, we leave the known formats and otherwise convert to png
        if (runparams.flavor == OutputParams::HTML) {
-               Format const * const f = formats.getFormat(format);
+               Format const * const f = theFormats().getFormat(format);
                // Convert vector graphics to svg
                if (f && f->vectorFormat() && theConverters().isReachable(format, "svg"))
                        return "svg";
@@ -483,7 +483,7 @@ copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
                // Nothing to do...
                return make_pair(IDENTICAL_CONTENTS, file_out);
 
-       Mover const & mover = getMover(formats.getFormatFromFile(file_in));
+       Mover const & mover = getMover(theFormats().getFormatFromFile(file_in));
        bool const success = mover.copy(file_in, file_out);
        if (!success) {
                // FIXME UNICODE
@@ -507,7 +507,7 @@ copyToDirIfNeeded(DocFileName const & file, string const & dir)
                return make_pair(IDENTICAL_PATHS, FileName(file_in));
 
        string mangled = file.mangledFileName();
-       if (formats.isZippedFile(file)) {
+       if (theFormats().isZippedFile(file)) {
                // We need to change _eps.gz to .eps.gz. The mangled name is
                // still unique because of the counter in mangledFileName().
                // We can't just call mangledFileName() with the zip
@@ -548,7 +548,7 @@ string const stripExtensionIfPossible(string const & file, string const & to, bo
 {
        // No conversion is needed. LaTeX can handle the graphic file as is.
        // This is true even if the orig_file is compressed.
-       string const to_format = formats.getFormat(to)->extension();
+       string const to_format = theFormats().getFormat(to)->extension();
        string const file_format = getExtension(file);
        // for latex .ps == .eps
        if (to_format == file_format ||
@@ -629,7 +629,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
        // determine the export format
        string const tex_format = flavor2format(runparams.flavor);
 
-       if (formats.isZippedFile(params().filename)) {
+       if (theFormats().isZippedFile(params().filename)) {
                FileName const unzipped_temp_file =
                        FileName(unzippedFileName(temp_file.absFileName()));
                output_file = unzippedFileName(output_file);
@@ -646,12 +646,12 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
                }
        }
 
-       string const from = formats.getFormatFromFile(temp_file);
+       string const from = theFormats().getFormatFromFile(temp_file);
        if (from.empty())
                LYXERR(Debug::GRAPHICS, "\tCould not get file format.");
 
        string const to   = findTargetFormat(from, runparams);
-       string const ext  = formats.extension(to);
+       string const ext  = theFormats().extension(to);
        LYXERR(Debug::GRAPHICS, "\t we have: from " << from << " to " << to);
 
        // We're going to be running the exported buffer through the LaTeX
@@ -893,14 +893,14 @@ string InsetGraphics::prepareHTMLFile(OutputParams const & runparams) const
        if (status == FAILURE)
                return string();
 
-       string const from = formats.getFormatFromFile(temp_file);
+       string const from = theFormats().getFormatFromFile(temp_file);
        if (from.empty()) {
                LYXERR(Debug::GRAPHICS, "\tCould not get file format.");
                return string();
        }
 
        string const to   = findTargetFormat(from, runparams);
-       string const ext  = formats.extension(to);
+       string const ext  = theFormats().extension(to);
        string const orig_file = params().filename.absFileName();
        string output_file = onlyFileName(temp_file.absFileName());
        LYXERR(Debug::GRAPHICS, "\t we have: from " << from << " to " << to);
@@ -1030,8 +1030,8 @@ InsetGraphicsParams const & InsetGraphics::params() const
 
 void InsetGraphics::editGraphics(InsetGraphicsParams const & p) const
 {
-       formats.edit(buffer(), p.filename,
-                    formats.getFormatFromFile(p.filename));
+       theFormats().edit(buffer(), p.filename,
+                    theFormats().getFormatFromFile(p.filename));
 }
 
 
index e036574cd294dceccf2a196cf16ea33675bb1429..275276b973e6f217a1907555e5c003d59e615aea 100644 (file)
@@ -110,8 +110,8 @@ void InsetHyperlink::viewTarget() const
 {
        if (getParam("type") == "file:") {
                FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
-               string const format = formats.getFormatFromFile(url);
-               formats.view(buffer(), url, format);
+               string const format = theFormats().getFormatFromFile(url);
+               theFormats().view(buffer(), url, format);
        }
 }
 
index 482030120084cd420af63772dcdd672e68d1f98a..9b5c3f0961f119f2ed6ff50e38d4cb9dd4d40feb 100644 (file)
@@ -310,7 +310,7 @@ void InsetInclude::editIncluded(string const & file)
                lyx::dispatch(fr);
        } else
                // tex file or other text file in verbatim mode
-               formats.edit(buffer(),
+               theFormats().edit(buffer(),
                        support::makeAbsPath(file, support::onlyPath(buffer().absFileName())),
                        "text");
 }
@@ -696,7 +696,7 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
                // Don't assume the child's format is latex
                string const inc_format = tmp->params().bufferFormat();
                FileName const tmpwritefile(changeExtension(writefile.absFileName(),
-                       formats.extension(inc_format)));
+                       theFormats().extension(inc_format)));
 
                // FIXME: handle non existing files
                // The included file might be written in a different encoding
index 6c8d13c3677cafa80014f6cb20e82a5a85b52a8b..f6977403770ee463b54b464a5ec67c235c89bd88 100644 (file)
@@ -83,7 +83,12 @@ Messages const & getGuiMessages()
 // Dummy formats support (needed by Lexer)
 //
 
-Formats formats;
+
+Formats & theFormats() 
+{
+       static Formats dummy_formats;
+       return dummy_formats;
+}
 
 bool Formats::isZippedFile(support::FileName const&) const
 {