diff --git a/src/Format.cpp b/src/Format.cpp index 2ef745e50d..1ae3960163 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -77,6 +77,19 @@ private: string extension_; }; + +class FormatPrettyNameEqual : public unary_function { +public: + FormatPrettyNameEqual(string const & prettyname) + : prettyname_(prettyname) {} + bool operator()(Format const & f) const + { + return f.prettyname() == prettyname_; + } +private: + string prettyname_; +}; + } //namespace anon @@ -192,6 +205,19 @@ string Formats::getFormatFromExtension(string const & ext) const } +string Formats::getFormatFromPrettyName(string const & prettyname) const +{ + if (!prettyname.empty()) { + Formats::const_iterator cit = + find_if(formatlist.begin(), formatlist.end(), + FormatPrettyNameEqual(prettyname)); + if (cit != formats.end()) + return cit->name(); + } + return string(); +} + + /// Used to store last timestamp of file and whether it is (was) zipped struct ZippedInfo { bool zipped; diff --git a/src/Format.h b/src/Format.h index e9ac7a47a9..12e14f9e15 100644 --- a/src/Format.h +++ b/src/Format.h @@ -141,6 +141,8 @@ public: std::string getFormatFromFile(support::FileName const & filename) const; /// Finds a format from a file extension. Returns string() if not found. std::string getFormatFromExtension(std::string const & ext) const; + /// Finds a format by pretty name. Returns string() if not found. + std::string getFormatFromPrettyName(std::string const & prettyname) const; /** Returns true if the file referenced by \p filename is zipped and ** needs to be unzipped for being handled ** @note For natively zipped formats, such as dia/odg, this returns false. diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 202b561bbb..4de2771414 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2314,10 +2314,17 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname) } +struct PrettyNameComparator +{ + bool operator()(Format const *first, Format const *second) const { + return compare_ascii_no_case(first->prettyname(), second->prettyname()) <= 0; + } +}; + + bool GuiView::exportBufferAs(Buffer & b) { FileName fname = b.fileName(); - FileName const oldname = fname; FileDialog dlg(qt_("Choose a filename to export the document as")); dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path)); @@ -2325,9 +2332,15 @@ bool GuiView::exportBufferAs(Buffer & b) QStringList types; types << "Any supported format (*.*)"; Formats::const_iterator it = formats.begin(); + vector export_formats; for (; it != formats.end(); ++it) - if (it->documentFormat()) - types << toqstr(it->name() + " (*." + it->extension() + ")"); + if (it->documentFormat() && it->inExportMenu()) + export_formats.push_back(&(*it)); + PrettyNameComparator cmp; + sort(export_formats.begin(), export_formats.end(), cmp); + vector::const_iterator fit = export_formats.begin(); + for (; fit != export_formats.end(); ++fit) + types << toqstr((*fit)->prettyname() + " (*." + (*fit)->extension() + ")"); QString filter; FileDialog::Result result = dlg.save(toqstr(fname.onlyPath().absFileName()), @@ -2338,15 +2351,19 @@ bool GuiView::exportBufferAs(Buffer & b) return false; string s = fromqstr(filter); - size_t pos = s.find(" ("); + size_t pos = s.find(" (*."); LASSERT(pos != string::npos, /**/); - string fmt_name = s.substr(0, pos); + string fmt_prettyname = s.substr(0, pos); + string fmt_name; fname.set(fromqstr(result.second)); - if (fmt_name == "Any supported format") + if (fmt_prettyname == "Any supported format") fmt_name = formats.getFormatFromExtension(fname.extension()); - LYXERR(Debug::FILES, "fmt_name=" << fmt_name << ", fname=" << fname.absFileName()); + else + fmt_name = formats.getFormatFromPrettyName(fmt_prettyname); + LYXERR(Debug::FILES, "fmt_prettyname=" << fmt_prettyname + << ", fmt_name=" << fmt_name << ", fname=" << fname.absFileName()); - if (fname.empty()) + if (fmt_name.empty() || fname.empty()) return false; // fname is now the new Buffer location.