2 * \file ControlSendto.C
3 * See the file COPYING.
5 * \author Angus Leeming
7 * Full author contact details are available in file CREDITS
13 #pragma implementation
16 #include "ControlSendto.h"
19 #include "converter.h"
24 #include "support/filetools.h"
25 #include "support/lstrings.h"
26 #include "support/systemcall.h"
31 ControlSendto::ControlSendto(LyXView & lv, Dialogs & d)
32 : ControlDialogBD(lv, d),
34 command_(lyxrc.custom_export_command)
38 vector<Format const *> const ControlSendto::allFormats() const
40 // What formats can we output natively?
41 vector<string> exports;
42 exports.push_back("lyx");
43 exports.push_back("text");
45 if (buffer()->isLatex())
46 exports.push_back("latex");
47 if (buffer()->isLinuxDoc())
48 exports.push_back("linuxdoc");
49 if (buffer()->isDocBook())
50 exports.push_back("docbook");
51 if (buffer()->isLiterate())
52 exports.push_back("literate");
54 // Loop over these native formats and ascertain what formats we
56 vector<Format const *> to;
58 vector<string>::const_iterator ex_it = exports.begin();
59 vector<string>::const_iterator ex_end = exports.end();
60 for (; ex_it != ex_end; ++ex_it) {
61 // Start off with the native export format.
62 // "formats" is LyX's list of recognised formats
63 to.push_back(formats.getFormat(*ex_it));
65 Formats::const_iterator fo_it = formats.begin();
66 Formats::const_iterator fo_end = formats.end();
67 for (; fo_it != fo_end; ++fo_it) {
68 // we need to hide the default graphic export formats
69 // from the external menu, because we need them only
70 // for the internal lyx-view and external latex run
71 string const name = fo_it->name();
72 if (name != "eps" && name != "xpm" && name != "png" &&
73 converters.isReachable(*ex_it, name))
74 to.push_back(&(*fo_it));
78 // Remove repeated formats.
79 std::sort(to.begin(), to.end());
81 vector<Format const *>::iterator to_begin = to.begin();
82 vector<Format const *>::iterator to_end = to.end();
83 vector<Format const *>::iterator to_it =
84 std::unique(to_begin, to_end);
86 to.erase(to_it, to_end);
92 void ControlSendto::setFormat(Format const * fmt)
98 void ControlSendto::setCommand(string const & cmd)
100 command_ = trim(cmd);
104 void ControlSendto::apply()
106 if (!bufferIsAvailable())
111 if (command_.empty() || !format_)
114 // The name of the file created by the conversion process
117 // Output to filename
118 if (format_->name() == "lyx") {
119 filename = ChangeExtension(buffer()->getLatexName(false),
120 format_->extension());
121 if (!buffer()->tmppath.empty())
122 filename = AddName(buffer()->tmppath, filename);
124 buffer()->writeFile(filename);
127 Exporter::Export(buffer(), format_->name(), true, filename);
130 // Substitute $$FName for filename
131 string command = command_;
132 if (!contains(command, "$$FName"))
133 command = "( " + command + " ) < $$FName";
134 command = subst(command, "$$FName", filename);
136 // Execute the command in the background
138 call.startscript(Systemcall::DontWait, command);