X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFormat.cpp;h=050af1414f69ae0058849c9f26e35af9c68ca961;hb=66ca99798bff016b0a60cb10bd2124c5c228c8b6;hp=a28629fad1c149c369ac691b60ea0a3c80df2676;hpb=107568e9feb01e4f9407b1b353035c02336a367b;p=lyx.git diff --git a/src/Format.cpp b/src/Format.cpp index a28629fad1..050af1414f 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -14,36 +14,29 @@ #include "Buffer.h" #include "BufferParams.h" #include "LyXRC.h" -#include "debug.h" -#include "gettext.h" #include "ServerSocket.h" #include "frontends/alert.h" //to be removed? +#include "support/debug.h" #include "support/filetools.h" +#include "support/gettext.h" #include "support/lstrings.h" #include "support/os.h" #include "support/Systemcall.h" +#include "support/textutils.h" -using std::find_if; -using std::string; -using std::distance; +#include +// FIXME: Q_WS_MACX is not available, it's in Qt +#ifdef USE_MACOSX_PACKAGING +#include "support/linkback/LinkBackProxy.h" +#endif -namespace lyx { +using namespace std; +using namespace lyx::support; -using support::absolutePath; -using support::bformat; -using support::compare_ascii_no_case; -using support::contains; -using support::FileName; -using support::libScriptSearch; -using support::makeDisplayPath; -using support::onlyPath; -using support::quoteName; -using support::subst; -using support::Systemcall; -using support::token; +namespace lyx { namespace Alert = frontend::Alert; namespace os = support::os; @@ -55,7 +48,7 @@ string const token_path_format("$$p"); string const token_socket_format("$$a"); -class FormatNamesEqual : public std::unary_function { +class FormatNamesEqual : public unary_function { public: FormatNamesEqual(string const & name) : name_(name) {} @@ -68,7 +61,7 @@ private: }; -class FormatExtensionsEqual : public std::unary_function { +class FormatExtensionsEqual : public unary_function { public: FormatExtensionsEqual(string const & extension) : extension_(extension) {} @@ -110,7 +103,7 @@ bool Format::isChildFormat() const { if (name_.empty()) return false; - return isdigit(name_[name_.length() - 1]); + return isDigitASCII(name_[name_.length() - 1]); } @@ -144,7 +137,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 @@ -152,9 +145,8 @@ string Formats::getFormatFromFile(FileName const & filename) const find_if(formatlist.begin(), formatlist.end(), FormatExtensionsEqual(ext)); if (cit != formats.end()) { - LYXERR(Debug::GRAPHICS) - << "\twill guess format from file extension: " - << ext << " -> " << cit->name() << std::endl; + LYXERR(Debug::GRAPHICS, "\twill guess format from file extension: " + << ext << " -> " << cit->name()); return cit->name(); } } @@ -257,13 +249,24 @@ 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::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; } @@ -281,12 +284,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; } } @@ -295,13 +298,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)) @@ -310,19 +314,14 @@ bool Formats::view(Buffer const & buffer, FileName const & filename, command = subst(command, token_from_format, quoteName(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 << std::endl; + LYXERR(Debug::FILES, "Executing command: " << command); // FIXME UNICODE utf8 can be wrong for files 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; } @@ -333,10 +332,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()) @@ -349,14 +360,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; } } @@ -369,19 +381,14 @@ bool Formats::edit(Buffer const & buffer, FileName const & filename, command = subst(command, token_from_format, quoteName(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 << std::endl; + LYXERR(Debug::FILES, "Executing command: " << command); // FIXME UNICODE utf8 can be wrong for files 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; }