X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFormat.cpp;h=7e82f9a3b073756f4eadaed6ebc4bc702f9ed9d7;hb=dad3c8ce74d1ebea92973bea5ca44f97d660d38e;hp=2ece9f874205208533e91f9f29d56cf480e22a40;hpb=9abb7db46800e554f57e865a3e768602ffd9d6f1;p=lyx.git diff --git a/src/Format.cpp b/src/Format.cpp index 2ece9f8742..7e82f9a3b0 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -25,6 +25,13 @@ #include "support/os.h" #include "support/Systemcall.h" +#include + +// FIXME: Q_WS_MACX is not available, it's in Qt +#ifdef USE_MACOSX_PACKAGING +#include "support/linkback/LinkBackProxy.h" +#endif + using namespace std; using namespace lyx::support; @@ -129,7 +136,7 @@ string Formats::getFormatFromFile(FileName const & filename) const return format; // try to find a format from the file extension. - string const ext = support::getExtension(filename.absFilename()); + string const ext = getExtension(filename.absFileName()); if (!ext.empty()) { // this is ambigous if two formats have the same extension, // but better than nothing @@ -241,13 +248,45 @@ void Formats::setViewer(string const & name, string const & command) } +void Formats::setEditor(string const & name, string const & command) +{ + add(name); + FormatList::iterator it = + find_if(formatlist.begin(), formatlist.end(), + FormatNamesEqual(name)); + if (it != formatlist.end()) + it->setEditor(command); +} + + +bool Formats::viewURL(docstring const & url) { + Format const * format = getFormat("html"); + if (!format) + return false; + + string command = libScriptSearch(format->viewer()); + + if (!contains(command, token_from_format)) + command += ' ' + token_from_format; + command = subst(command, token_from_format, quoteName(to_utf8(url))); + + LYXERR(Debug::FILES, "Executing command: " << command); + + Systemcall one; + one.startscript(Systemcall::DontWait, command); + + // we can't report any sort of error, since we aren't waiting + return true; +} + + bool Formats::view(Buffer const & buffer, FileName const & filename, string const & format_name) const { if (filename.empty() || !filename.exists()) { Alert::error(_("Cannot view file"), bformat(_("File does not exist: %1$s"), - from_utf8(filename.absFilename()))); + from_utf8(filename.absFileName()))); return false; } @@ -265,12 +304,12 @@ 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)) return true; else { Alert::error(_("Cannot view file"), bformat(_("Auto-view file %1$s failed"), - from_utf8(filename.absFilename()))); + from_utf8(filename.absFileName()))); return false; } } @@ -279,13 +318,14 @@ bool Formats::view(Buffer const & buffer, FileName const & filename, if (format_name == "dvi" && !lyxrc.view_dvi_paper_option.empty()) { - command += ' ' + lyxrc.view_dvi_paper_option; - string paper_size = buffer.params().paperSizeName(); - if (paper_size == "letter") - paper_size = "us"; - command += ' ' + paper_size; - if (buffer.params().orientation == ORIENTATION_LANDSCAPE) - command += 'r'; + string paper_size = buffer.params().paperSizeName(BufferParams::XDVI); + if (!paper_size.empty()) { + command += ' ' + lyxrc.view_dvi_paper_option; + command += ' ' + paper_size; + if (buffer.params().orientation == ORIENTATION_LANDSCAPE && + buffer.params().papersize != PAPER_CUSTOM) + command += 'r'; + } } if (!contains(command, token_from_format)) @@ -299,14 +339,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); - 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; } @@ -317,10 +352,22 @@ bool Formats::edit(Buffer const & buffer, FileName const & filename, if (filename.empty() || !filename.exists()) { Alert::error(_("Cannot edit file"), bformat(_("File does not exist: %1$s"), - from_utf8(filename.absFilename()))); + from_utf8(filename.absFileName()))); return false; } + // LinkBack files look like PDF, but have the .linkback extension + string const ext = getExtension(filename.absFileName()); + if (format_name == "pdf" && ext == "linkback") { +#ifdef USE_MACOSX_PACKAGING + return editLinkBackFile(filename.absFileName().c_str()); +#else + Alert::error(_("Cannot edit file"), + _("LinkBack files can only be edited on Apple Mac OSX.")); + return false; +#endif // USE_MACOSX_PACKAGING + } + Format const * format = getFormat(format_name); if (format && format->editor().empty() && format->isChildFormat()) @@ -333,14 +380,15 @@ 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)) return true; else { Alert::error(_("Cannot edit file"), bformat(_("Auto-edit file %1$s failed"), - from_utf8(filename.absFilename()))); + from_utf8(filename.absFileName()))); return false; } } @@ -358,14 +406,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); - 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; }