]> git.lyx.org Git - lyx.git/blobdiff - src/Format.cpp
Compile fix for qt versions below 4.6.
[lyx.git] / src / Format.cpp
index 74a19eaf23596d05c3127508e23b0ab8a725b679..cc85b8500008165cb586f6c2ebccb2fb80fefaf3 100644 (file)
@@ -24,6 +24,8 @@
 #include "support/lstrings.h"
 #include "support/os.h"
 #include "support/Systemcall.h"
+#include "support/textutils.h"
+#include "support/Translator.h"
 
 #include <algorithm>
 
@@ -102,7 +104,7 @@ bool Format::isChildFormat() const
 {
        if (name_.empty())
                return false;
-       return isdigit(name_[name_.length() - 1]);
+       return isDigitASCII(name_[name_.length() - 1]);
 }
 
 
@@ -258,28 +260,6 @@ void Formats::setEditor(string const & name, string const & command)
                it->setEditor(command);
 }
 
-bool Formats::viewURL(string const &url){
-       Format const * format = getFormat("html");
-       string command = libScriptSearch(format->viewer());
-
-       if (!contains(command, token_from_format))
-               command += ' ' + token_from_format;
-       command = subst(command, token_from_format, quoteName(url));
-
-       LYXERR(Debug::FILES, "Executing command: " << command);
-       //buffer.message(_("Executing command: ") + from_utf8(command));
-
-       Systemcall one;
-       int const res = one.startscript(Systemcall::DontWait, command);
-
-       if (res) {
-               Alert::error(_("Cannot view URL"),
-                            bformat(_("An error occurred whilst running %1$s"),
-                              makeDisplayPath(command, 50)));
-               return false;
-       }
-       return true;
-}
 
 bool Formats::view(Buffer const & buffer, FileName const & filename,
                   string const & format_name) const
@@ -305,7 +285,7 @@ bool Formats::view(Buffer const & buffer, FileName const & filename,
        }
        // viewer is 'auto'
        if (format->viewer() == "auto") {
-               if (os::autoOpenFile(filename.absFileName(), os::VIEW))
+               if (os::autoOpenFile(filename.absFileName(), os::VIEW, buffer.filePath()))
                        return true;
                else {
                        Alert::error(_("Cannot view file"),
@@ -340,14 +320,9 @@ bool Formats::view(Buffer const & buffer, FileName const & filename,
        buffer.message(_("Executing command: ") + from_utf8(command));
 
        Systemcall one;
-       int const res = one.startscript(Systemcall::DontWait, command);
+       one.startscript(Systemcall::DontWait, command, buffer.filePath());
 
-       if (res) {
-               Alert::error(_("Cannot view file"),
-                            bformat(_("An error occurred whilst running %1$s"),
-                              makeDisplayPath(command, 50)));
-               return false;
-       }
+       // we can't report any sort of error, since we aren't waiting
        return true;
 }
 
@@ -386,10 +361,10 @@ bool Formats::edit(Buffer const & buffer, FileName const & filename,
                                prettyName(format_name)));
                return false;
        }
-       
+
        // editor is 'auto'
        if (format->editor() == "auto") {
-               if (os::autoOpenFile(filename.absFileName(), os::EDIT))
+               if (os::autoOpenFile(filename.absFileName(), os::EDIT, buffer.filePath()))
                        return true;
                else {
                        Alert::error(_("Cannot edit file"),
@@ -412,14 +387,9 @@ bool Formats::edit(Buffer const & buffer, FileName const & filename,
        buffer.message(_("Executing command: ") + from_utf8(command));
 
        Systemcall one;
-       int const res = one.startscript(Systemcall::DontWait, command);
+       one.startscript(Systemcall::DontWait, command, buffer.filePath());
 
-       if (res) {
-               Alert::error(_("Cannot edit file"),
-                            bformat(_("An error occurred whilst running %1$s"),
-                              makeDisplayPath(command, 50)));
-               return false;
-       }
+       // we can't report any sort of error, since we aren't waiting
        return true;
 }
 
@@ -444,7 +414,41 @@ string const Formats::extension(string const & name) const
 }
 
 
+namespace {
+typedef Translator<OutputParams::FLAVOR, string> FlavorTranslator;
 
+FlavorTranslator initFlavorTranslator()
+{
+       FlavorTranslator f(OutputParams::LATEX, "latex");
+       f.addPair(OutputParams::LUATEX, "luatex");
+       f.addPair(OutputParams::PDFLATEX, "pdflatex");
+       f.addPair(OutputParams::XETEX, "xetex");
+       f.addPair(OutputParams::XML, "docbook-xml");
+       f.addPair(OutputParams::HTML, "xhtml");
+       f.addPair(OutputParams::TEXT, "text");
+       return f;
+}
+
+
+FlavorTranslator const & flavorTranslator()
+{
+       static FlavorTranslator translator = initFlavorTranslator();
+       return translator;
+}
+}
+
+
+std::string flavor2format(OutputParams::FLAVOR flavor)
+{
+       return flavorTranslator().find(flavor);
+}
+
+
+/* Not currently needed, but I'll leave the code in case it is.
+OutputParams::FLAVOR format2flavor(std::string fmt)
+{
+       return flavorTranslator().find(fmt);
+} */
 
 Formats formats;