+bool Formats::edit(Buffer const & buffer, FileName const & filename,
+ string const & format_name) const
+{
+ if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
+ Alert::error(_("Cannot edit file"),
+ bformat(_("File does not exist: %1$s"),
+ from_utf8(filename.absFilename())));
+ return false;
+ }
+
+ Format const * format = getFormat(format_name);
+ if (format && format->editor().empty() &&
+ format->isChildFormat())
+ format = getFormat(format->parentFormat());
+ if (!format || format->editor().empty()) {
+// FIXME: I believe this is the wrong place to show alerts, it should
+// be done by the caller (this should be "utility" code)
+ Alert::error(_("Cannot edit file"),
+ bformat(_("No information for editing %1$s"),
+ prettyName(format_name)));
+ return false;
+ }
+ // editor is 'auto'
+ if (format->editor() == "auto") {
+ 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())));
+ return false;
+ }
+ }
+
+ string command = format->editor();
+
+ if (!contains(command, token_from))
+ command += ' ' + token_from;
+
+ command = subst(command, token_from, quoteName(filename.toFilesystemEncoding()));
+ command = subst(command, token_path, quoteName(onlyPath(filename.toFilesystemEncoding())));
+ command = subst(command, token_socket, 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));
+
+ Systemcall one;
+ int const res = 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;
+ }
+ return true;
+}
+
+
+docstring const Formats::prettyName(string const & name) const