#include "gettext.h"
#include "lyxsocket.h"
+#include "frontends/Application.h"
#include "frontends/Alert.h" //to be removed?
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/os.h"
-#include "support/path.h"
#include "support/systemcall.h"
#include <boost/filesystem/operations.hpp>
-using lyx::support::bformat;
-using lyx::support::compare_ascii_no_case;
-using lyx::support::contains;
-using lyx::support::libScriptSearch;
-using lyx::support::makeDisplayPath;
-using lyx::support::onlyFilename;
-using lyx::support::onlyPath;
-using lyx::support::Path;
-using lyx::support::quoteName;
-using lyx::support::subst;
-using lyx::support::Systemcall;
-using lyx::support::token;
+
+namespace lyx {
+
+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;
using std::string;
using std::distance;
+namespace Alert = frontend::Alert;
namespace fs = boost::filesystem;
-namespace os = lyx::support::os;
-
-extern LyXServerSocket * lyxsocket;
+namespace os = support::os;
namespace {
-string const token_from("$$i");
-string const token_path("$$p");
-string const token_socket("$$a");
+string const token_from_format("$$i");
+string const token_path_format("$$p");
+string const token_socket_format("$$a");
class FormatNamesEqual : public std::unary_function<Format, bool> {
return compare_ascii_no_case(a.prettyname(), b.prettyname()) < 0;
}
+
Format::Format(string const & n, string const & e, string const & p,
- string const & s, string const & v, string const & ed)
- : name_(n), extension_(e), prettyname_(p), shortcut_(s), viewer_(v), editor_(ed)
+ string const & s, string const & v, string const & ed,
+ int flags)
+ : name_(n), extension_(e), prettyname_(p), shortcut_(s), viewer_(v),
+ editor_(ed), flags_(flags)
{}
}
-string Formats::getFormatFromFile(string const & filename) const
+string Formats::getFormatFromFile(FileName const & filename) const
{
if (filename.empty())
return string();
- string const format = lyx::support::getFormatFromContents(filename);
+ string const format = support::getFormatFromContents(filename);
if (!format.empty())
return format;
// try to find a format from the file extension.
- string const ext(lyx::support::getExtension(filename));
+ string const ext(support::getExtension(filename.absFilename()));
if (!ext.empty()) {
// this is ambigous if two formats have the same extension,
// but better than nothing
find_if(formatlist.begin(), formatlist.end(),
FormatExtensionsEqual(ext));
if (cit != formats.end()) {
- lyxerr[Debug::GRAPHICS]
+ LYXERR(Debug::GRAPHICS)
<< "\twill guess format from file extension: "
<< ext << " -> " << cit->name() << std::endl;
return cit->name();
namespace {
-string fixCommand(string const & cmd, string const & ext,
+string fixCommand(string const & cmd, string const & ext,
os::auto_open_mode mode)
{
// configure.py says we do not want a viewer/editor
return "auto";
// if configure.py found nothing, clear the command
- if (token(cmd, ' ', 0) == "none")
+ if (token(cmd, ' ', 0) == "auto")
return string();
// use the command found by configure.py
void Formats::add(string const & name)
{
if (!getFormat(name))
- add(name, name, name, string(), string(), string());
+ add(name, name, name, string(), string(), string(),
+ Format::document);
}
void Formats::add(string const & name, string const & extension,
string const & prettyname, string const & shortcut,
- string const & viewer, string const & editor)
+ string const & viewer, string const & editor,
+ int flags)
{
FormatList::iterator it =
find_if(formatlist.begin(), formatlist.end(),
FormatNamesEqual(name));
if (it == formatlist.end())
formatlist.push_back(Format(name, extension, prettyname,
- shortcut, viewer, editor));
+ shortcut, viewer, editor, flags));
else
- *it = Format(name, extension, prettyname, shortcut, viewer, editor);
+ *it = Format(name, extension, prettyname, shortcut, viewer,
+ editor, flags);
}
}
-bool Formats::view(Buffer const & buffer, string const & filename,
+bool Formats::view(Buffer const & buffer, FileName const & filename,
string const & format_name) const
{
- if (filename.empty() || !fs::exists(filename)) {
+ if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
Alert::error(_("Cannot view file"),
bformat(_("File does not exist: %1$s"),
- filename));
+ from_utf8(filename.absFilename())));
return false;
}
}
// viewer is 'auto'
if (format->viewer() == "auto") {
- if (os::autoOpenFile(filename, os::VIEW))
+ if (os::autoOpenFile(filename.absFilename(), os::VIEW))
return true;
else {
Alert::error(_("Cannot view file"),
bformat(_("Auto-view file %1$s failed"),
- filename));
+ from_utf8(filename.absFilename())));
return false;
}
}
command += 'r';
}
- if (!contains(command, token_from))
- command += ' ' + token_from;
+ if (!contains(command, token_from_format))
+ command += ' ' + token_from_format;
- command = subst(command, token_from,
- quoteName(onlyFilename(filename)));
- command = subst(command, token_path, quoteName(onlyPath(filename)));
- command = subst(command, token_socket, quoteName(lyxsocket->address()));
- lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
- buffer.message(_("Executing command: ") + command);
+ 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(theLyXServerSocket().address()));
+ LYXERR(Debug::FILES) << "Executing command: " << command << std::endl;
+ // FIXME UNICODE utf8 can be wrong for files
+ buffer.message(_("Executing command: ") + from_utf8(command));
- Path p(onlyPath(filename));
Systemcall one;
int const res = one.startscript(Systemcall::DontWait, command);
}
-bool Formats::edit(Buffer const & buffer, string const & filename,
+bool Formats::edit(Buffer const & buffer, FileName const & filename,
string const & format_name) const
{
- if (filename.empty() || !fs::exists(filename)) {
+ if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
Alert::error(_("Cannot edit file"),
bformat(_("File does not exist: %1$s"),
- filename));
+ from_utf8(filename.absFilename())));
return false;
}
}
// editor is 'auto'
if (format->editor() == "auto") {
- if (os::autoOpenFile(filename, os::EDIT))
+ if (os::autoOpenFile(filename.absFilename(), os::EDIT))
return true;
else {
Alert::error(_("Cannot edit file"),
bformat(_("Auto-edit file %1$s failed"),
- filename));
+ from_utf8(filename.absFilename())));
return false;
}
}
string command = format->editor();
- if (!contains(command, token_from))
- command += ' ' + token_from;
+ if (!contains(command, token_from_format))
+ command += ' ' + token_from_format;
- command = subst(command, token_from,
- quoteName(onlyFilename(filename)));
- command = subst(command, token_path, quoteName(onlyPath(filename)));
- command = subst(command, token_socket, quoteName(lyxsocket->address()));
- lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
- buffer.message(_("Executing command: ") + command);
+ 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(theLyXServerSocket().address()));
+ LYXERR(Debug::FILES) << "Executing command: " << command << std::endl;
+ // FIXME UNICODE utf8 can be wrong for files
+ buffer.message(_("Executing command: ") + from_utf8(command));
- Path p(onlyPath(filename));
Systemcall one;
int const res = one.startscript(Systemcall::DontWait, command);
}
-string const Formats::prettyName(string const & name) const
+docstring const Formats::prettyName(string const & name) const
{
Format const * format = getFormat(name);
if (format)
- return format->prettyname();
+ return from_utf8(format->prettyname());
else
- return name;
+ return from_utf8(name);
}
Formats formats;
Formats system_formats;
+
+
+} // namespace lyx