X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFormat.cpp;h=d639dbfd9fca1b9efe75ef91ac45a06fd5222284;hb=7470305720d7733a27e9c6e5ef13a0774f5d0f77;hp=0ec1de2d42074cbfd4a82f4214e91a67c7e549fe;hpb=c506f304bc522ea91ad5a7e97cd4e3c7d54376b0;p=lyx.git diff --git a/src/Format.cpp b/src/Format.cpp index 0ec1de2d42..d639dbfd9f 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -32,6 +32,7 @@ #include "support/Translator.h" #include +#include #include #include @@ -54,53 +55,9 @@ string const token_from_format("$$i"); string const token_path_format("$$p"); string const token_socket_format("$$a"); - -class FormatNamesEqual : public unary_function { -public: - FormatNamesEqual(string const & name) - : name_(name) - {} - bool operator()(Format const & f) const - { - return f.name() == name_; - } -private: - string name_; -}; - - -class FormatExtensionsEqual : public unary_function { -public: - FormatExtensionsEqual(string const & extension) - : extension_(extension) - {} - bool operator()(Format const & f) const - { - return f.hasExtension(extension_); - } -private: - string extension_; -}; - - -class FormatMimeEqual : public unary_function { -public: - FormatMimeEqual(string const & mime) - : mime_(mime) - {} - bool operator()(Format const & f) const - { - // The test for empty mime strings is needed since we allow - // formats with empty mime types. - return f.mime() == mime_ && !mime_.empty(); - } -private: - string mime_; -}; - - } // namespace + bool Format::formatSorter(Format const * lhs, Format const * rhs) { return compare_locale(translateIfPossible(lhs->prettyname()), @@ -164,13 +121,22 @@ void Format::setExtensions(string const & e) } +namespace { + +std::function FormatNameIs(string const & name) +{ + return [name](Format const & f){ return f.name() == name; }; +} + +} + // This method should return a reference, and throw an exception // if the format named name cannot be found (Lgb) Format const * Formats::getFormat(string const & name) const { FormatList::const_iterator cit = find_if(formatlist_.begin(), formatlist_.end(), - FormatNamesEqual(name)); + FormatNameIs(name)); if (cit != formatlist_.end()) return &(*cit); else @@ -182,7 +148,7 @@ Format * Formats::getFormat(string const & name) { FormatList::iterator it = find_if(formatlist_.begin(), formatlist_.end(), - [name](Format const & f) { return f.name() == name; }); + FormatNameIs(name)); if (it != formatlist_.end()) return &(*it); @@ -433,7 +399,7 @@ string Formats::getFormatFromFile(FileName const & filename) const mime != "text/plain") { Formats::const_iterator cit = find_if(formatlist_.begin(), formatlist_.end(), - FormatMimeEqual(mime)); + [mime](Format const & f){ return f.mime() == mime; }); if (cit != formatlist_.end()) { LYXERR(Debug::GRAPHICS, "\tgot format from MIME type: " << mime << " -> " << cit->name()); @@ -499,7 +465,7 @@ string Formats::getFormatFromExtension(string const & ext) const // but better than nothing Formats::const_iterator cit = find_if(formatlist_.begin(), formatlist_.end(), - FormatExtensionsEqual(ext)); + [ext](Format const & f){ return f.hasExtension(ext); }); if (cit != formatlist_.end()) { LYXERR(Debug::GRAPHICS, "\twill guess format from file extension: " << ext << " -> " << cit->name()); @@ -588,11 +554,11 @@ int Formats::getNumber(string const & name) const { FormatList::const_iterator cit = find_if(formatlist_.begin(), formatlist_.end(), - FormatNamesEqual(name)); - if (cit != formatlist_.end()) - return distance(formatlist_.begin(), cit); - else + FormatNameIs(name)); + if (cit == formatlist_.end()) return -1; + + return distance(formatlist_.begin(), cit); } @@ -623,7 +589,7 @@ void Formats::erase(string const & name) { FormatList::iterator it = find_if(formatlist_.begin(), formatlist_.end(), - FormatNamesEqual(name)); + FormatNameIs(name)); if (it != formatlist_.end()) formatlist_.erase(it); } @@ -676,7 +642,7 @@ bool Formats::view(Buffer const & buffer, FileName const & filename, // by the caller (this should be "utility" code) Alert::error(_("Cannot view file"), bformat(_("No information for viewing %1$s"), - prettyName(format_name))); + translateIfPossible(prettyName(format_name)))); return false; } // viewer is 'auto' @@ -780,7 +746,7 @@ bool Formats::edit(Buffer const & buffer, FileName const & filename, // be done by the caller (this should be "utility" code) Alert::error(_("Cannot edit file"), bformat(_("No information for editing %1$s"), - prettyName(format_name))); + translateIfPossible(prettyName(format_name)))); return false; } @@ -861,7 +827,7 @@ FlavorTranslator initFlavorTranslator() f.addPair(OutputParams::LUATEX, "luatex"); f.addPair(OutputParams::PDFLATEX, "pdflatex"); f.addPair(OutputParams::XETEX, "xetex"); - f.addPair(OutputParams::XML, "docbook-xml"); + f.addPair(OutputParams::DOCBOOK5, "docbook-xml"); f.addPair(OutputParams::HTML, "xhtml"); f.addPair(OutputParams::TEXT, "text"); f.addPair(OutputParams::LYX, "lyx");