#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/os.h"
+#include "support/Path.h"
#include "support/Systemcall.h"
+#include "support/textutils.h"
+#include "support/Translator.h"
#include <algorithm>
{
if (name_.empty())
return false;
- return isdigit(name_[name_.length() - 1]);
+ return isDigitASCII(name_[name_.length() - 1]);
}
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
}
// 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"),
if (!contains(command, token_from_format))
command += ' ' + token_from_format;
- command = subst(command, token_from_format, quoteName(filename.toFilesystemEncoding()));
+ command = subst(command, token_from_format, quoteName(onlyFileName(filename.toFilesystemEncoding())));
command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
LYXERR(Debug::FILES, "Executing command: " << command);
// FIXME UNICODE utf8 can be wrong for files
buffer.message(_("Executing command: ") + from_utf8(command));
+ PathChanger p(filename.onlyPath());
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;
}
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"),
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;
}
}
+namespace {
+typedef Translator<OutputParams::FLAVOR, string> FlavorTranslator;
+
+FlavorTranslator initFlavorTranslator()
+{
+ FlavorTranslator f(OutputParams::LATEX, "latex");
+ f.addPair(OutputParams::DVILUATEX, "dviluatex");
+ 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;
Formats system_formats;