2 * \file ControlSendto.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
14 #include "ControlSendto.h"
17 #include "converter.h"
23 #include "support/filetools.h"
24 #include "support/lstrings.h"
25 #include "support/systemcall.h"
30 ControlSendto::ControlSendto(LyXView & lv, Dialogs & d)
31 : ControlDialogBD(lv, d),
33 command_(lyxrc.custom_export_command)
37 vector<Format const *> const ControlSendto::allFormats() const
39 // What formats can we output natively?
40 vector<string> exports;
41 exports.push_back("lyx");
42 exports.push_back("text");
44 if (buffer()->isLatex())
45 exports.push_back("latex");
46 if (buffer()->isLinuxDoc())
47 exports.push_back("linuxdoc");
48 if (buffer()->isDocBook())
49 exports.push_back("docbook");
50 if (buffer()->isLiterate())
51 exports.push_back("literate");
53 // Loop over these native formats and ascertain what formats we
55 vector<Format const *> to;
57 vector<string>::const_iterator ex_it = exports.begin();
58 vector<string>::const_iterator ex_end = exports.end();
59 for (; ex_it != ex_end; ++ex_it) {
60 // Start off with the native export format.
61 // "formats" is LyX's list of recognised formats
62 to.push_back(formats.getFormat(*ex_it));
64 Formats::const_iterator fo_it = formats.begin();
65 Formats::const_iterator fo_end = formats.end();
66 for (; fo_it != fo_end; ++fo_it) {
67 // we need to hide the default graphic export formats
68 // from the external menu, because we need them only
69 // for the internal lyx-view and external latex run
70 string const name = fo_it->name();
71 if (name != "eps" && name != "xpm" && name != "png" &&
72 converters.isReachable(*ex_it, name))
73 to.push_back(&(*fo_it));
77 // Remove repeated formats.
78 std::sort(to.begin(), to.end());
80 vector<Format const *>::iterator to_begin = to.begin();
81 vector<Format const *>::iterator to_end = to.end();
82 vector<Format const *>::iterator to_it =
83 std::unique(to_begin, to_end);
85 to.erase(to_it, to_end);
91 void ControlSendto::setFormat(Format const * fmt)
97 void ControlSendto::setCommand(string const & cmd)
103 void ControlSendto::apply()
105 if (!bufferIsAvailable())
110 if (command_.empty() || !format_)
113 // The name of the file created by the conversion process
116 // Output to filename
117 if (format_->name() == "lyx") {
118 filename = ChangeExtension(buffer()->getLatexName(false),
119 format_->extension());
120 if (!buffer()->tmppath.empty())
121 filename = AddName(buffer()->tmppath, filename);
123 buffer()->writeFile(filename);
126 Exporter::Export(buffer(), format_->name(), true, filename);
129 // Substitute $$FName for filename
130 string command = command_;
131 if (!contains(command, "$$FName"))
132 command = "( " + command + " ) < $$FName";
133 command = subst(command, "$$FName", filename);
135 // Execute the command in the background
137 call.startscript(Systemcall::DontWait, command);