#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"
-using std::find_if;
-using std::string;
-using std::distance;
+#include <algorithm>
+// 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;
string const token_socket_format("$$a");
-class FormatNamesEqual : public std::unary_function<Format, bool> {
+class FormatNamesEqual : public unary_function<Format, bool> {
public:
FormatNamesEqual(string const & name)
: name_(name) {}
};
-class FormatExtensionsEqual : public std::unary_function<Format, bool> {
+class FormatExtensionsEqual : public unary_function<Format, bool> {
public:
FormatExtensionsEqual(string const & extension)
: extension_(extension) {}
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
}
+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;
}
}
// 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;
}
}
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))
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);
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;
}
}