commit 50060053e36b3e9dfe03bc33ed3abac1eacc54b0
Author: Richard Heck <[email protected]>
Date: Mon Mar 13 23:33:40 2017 -0400
Move the global formats and system_formats variables into the
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.
---
src/Buffer.cpp | 24 ++++++++++----------
src/Converter.cpp | 40 +++++++++++++++++-----------------
src/ConverterCache.cpp | 4 +-
src/Format.cpp | 5 ----
src/Format.h | 9 +++++--
src/Graph.cpp | 6 ++--
src/Lexer.cpp | 2 +-
src/LyX.cpp | 31 +++++++++++++++++++++-----
src/LyX.h | 3 ++
src/LyXRC.cpp | 20 ++++++++--------
src/frontends/qt4/GuiPrefs.cpp | 6 ++--
src/frontends/qt4/GuiView.cpp | 18 +++++++-------
src/frontends/qt4/GuiViewSource.cpp | 4 +-
src/frontends/qt4/Menus.cpp | 2 +-
src/graphics/GraphicsCache.cpp | 4 +-
src/graphics/GraphicsCacheItem.cpp | 14 ++++++------
src/graphics/GraphicsConverter.cpp | 2 +-
src/graphics/epstools.cpp | 4 +-
src/insets/ExternalSupport.cpp | 8 +++---
src/insets/InsetBibtex.cpp | 4 +-
src/insets/InsetGraphics.cpp | 24 ++++++++++----------
src/insets/InsetHyperlink.cpp | 4 +-
src/insets/InsetInclude.cpp | 4 +-
src/tex2lyx/dummy_impl.cpp | 7 +++++-
24 files changed, 137 insertions(+), 112 deletions(-)
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 84b5e6c..a20b4da 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -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?
diff --git a/src/Converter.cpp b/src/Converter.cpp
index 9d9d602..2c1ae2d 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -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));
}
diff --git a/src/ConverterCache.cpp b/src/ConverterCache.cpp
index 7590336..3842ebb 100644
--- a/src/ConverterCache.cpp
+++ b/src/ConverterCache.cpp
@@ -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"
diff --git a/src/Format.cpp b/src/Format.cpp
index d0f83a2..4a33eb0 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -872,9 +872,4 @@ OutputParams::FLAVOR format2flavor(std::string fmt)
return flavorTranslator().find(fmt);
} */
-Formats formats;
-
-Formats system_formats;
-
-
} // namespace lyx
diff --git a/src/Format.h b/src/Format.h
index e076934..cc383c0 100644
--- a/src/Format.h
+++ b/src/Format.h
@@ -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
diff --git a/src/Graph.cpp b/src/Graph.cpp
index 97427bc..0573cd2 100644
--- a/src/Graph.cpp
+++ b/src/Graph.cpp
@@ -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);
}
diff --git a/src/Lexer.cpp b/src/Lexer.cpp
index 78bf9f4..bbae124 100644
--- a/src/Lexer.cpp
+++ b/src/Lexer.cpp
@@ -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
diff --git a/src/LyX.cpp b/src/LyX.cpp
index c88e205..f0fc71c 100644
--- a/src/LyX.cpp
+++ b/src/LyX.cpp
@@ -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_;
}
diff --git a/src/LyX.h b/src/LyX.h
index 85decbc..1621512 100644
--- 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();
diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp
index 34998f2..94e7837 100644
--- a/src/LyXRC.cpp
+++ b/src/LyXRC.cpp
@@ -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)
diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp
index de3fcfd..1d8bb20 100644
--- a/src/frontends/qt4/GuiPrefs.cpp
+++ b/src/frontends/qt4/GuiPrefs.cpp
@@ -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();
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 1f1ec61..fe2646a 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -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)
diff --git a/src/frontends/qt4/GuiViewSource.cpp
b/src/frontends/qt4/GuiViewSource.cpp
index fe59387..03b7d60 100644
--- a/src/frontends/qt4/GuiViewSource.cpp
+++ b/src/frontends/qt4/GuiViewSource.cpp
@@ -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;
diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp
index e510054..faab339 100644
--- a/src/frontends/qt4/Menus.cpp
+++ b/src/frontends/qt4/Menus.cpp
@@ -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),
diff --git a/src/graphics/GraphicsCache.cpp b/src/graphics/GraphicsCache.cpp
index a3b8ebd..c915938 100644
--- a/src/graphics/GraphicsCache.cpp
+++ b/src/graphics/GraphicsCache.cpp
@@ -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();
diff --git a/src/graphics/GraphicsCacheItem.cpp
b/src/graphics/GraphicsCacheItem.cpp
index 9eb449a..0bd3779 100644
--- a/src/graphics/GraphicsCacheItem.cpp
+++ b/src/graphics/GraphicsCacheItem.cpp
@@ -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.");
diff --git a/src/graphics/GraphicsConverter.cpp
b/src/graphics/GraphicsConverter.cpp
index 55ae246..84cbaf9 100644
--- a/src/graphics/GraphicsConverter.cpp
+++ b/src/graphics/GraphicsConverter.cpp
@@ -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;
diff --git a/src/graphics/epstools.cpp b/src/graphics/epstools.cpp
index 2fd67dc..d5674ba 100644
--- a/src/graphics/epstools.cpp
+++ b/src/graphics/epstools.cpp
@@ -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");
diff --git a/src/insets/ExternalSupport.cpp b/src/insets/ExternalSupport.cpp
index 37c382a..469df20 100644
--- a/src/insets/ExternalSupport.cpp
+++ b/src/insets/ExternalSupport.cpp
@@ -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
}
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index 45b2971..ef79481 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -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));
}
}
diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp
index b41d72b..1582874 100644
--- a/src/insets/InsetGraphics.cpp
+++ b/src/insets/InsetGraphics.cpp
@@ -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));
}
diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp
index e036574..275276b 100644
--- a/src/insets/InsetHyperlink.cpp
+++ b/src/insets/InsetHyperlink.cpp
@@ -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);
}
}
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 4820301..9b5c3f0 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -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
diff --git a/src/tex2lyx/dummy_impl.cpp b/src/tex2lyx/dummy_impl.cpp
index 6c8d13c..f697740 100644
--- a/src/tex2lyx/dummy_impl.cpp
+++ b/src/tex2lyx/dummy_impl.cpp
@@ -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
{