+ FormatList::const_iterator cit =
+ find_if(formatlist.begin(), formatlist.end(),
+ lyx::compare_memfun(&Format::name, name));
+ if (cit != formatlist.end())
+ return cit - formatlist.begin();
+ else
+ return -1;
+}
+
+
+void Formats::add(string const & name)
+{
+ if (!getFormat(name))
+ add(name, name, name, string());
+}
+
+
+void Formats::add(string const & name, string const & extension,
+ string const & prettyname, string const & shortcut)
+{
+ FormatList::iterator it =
+ find_if(formatlist.begin(), formatlist.end(),
+ lyx::compare_memfun(&Format::name, name));
+ if (it == formatlist.end())
+ formatlist.push_back(Format(name, extension, prettyname,
+ shortcut, ""));
+ else {
+ string viewer = it->viewer();
+ *it = Format(name, extension, prettyname, shortcut, viewer);
+ }
+}
+
+
+void Formats::erase(string const & name)
+{
+ FormatList::iterator it =
+ find_if(formatlist.begin(), formatlist.end(),
+ lyx::compare_memfun(&Format::name, name));
+ if (it != formatlist.end())
+ formatlist.erase(it);
+}
+
+
+void Formats::sort()
+{
+ std::sort(formatlist.begin(), formatlist.end());
+}
+
+
+void Formats::setViewer(string const & name, string const & command)
+{
+ add(name);
+ FormatList::iterator it =
+ find_if(formatlist.begin(), formatlist.end(),
+ lyx::compare_memfun(&Format::name, name));
+ if (it != formatlist.end())
+ it->setViewer(command);
+}
+
+
+bool Formats::view(Buffer const * buffer, string const & filename,
+ string const & format_name) const
+{
+ if (filename.empty())
+ return false;
+
+ Format const * format = getFormat(format_name);
+ if (format && format->viewer().empty() &&
+ format->isChildFormat())
+ format = getFormat(format->parentFormat());
+ if (!format || format->viewer().empty()) {
+#if USE_BOOST_FORMAT
+ Alert::alert(_("Cannot view file"),
+ boost::io::str(boost::format(_("No information for viewing %1$s"))
+ % prettyName(format_name)));
+#else
+ Alert::alert(_("Cannot view file"),
+ _("No information for viewing ")
+ + prettyName(format_name));
+#endif