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"
22 #include "support/filetools.h"
23 #include "support/lstrings.h"
24 #include "support/systemcall.h"
29 ControlSendto::ControlSendto(LyXView & lv, Dialogs & d)
30 : ControlDialogBD(lv, d),
32 command_(lyxrc.custom_export_command)
36 vector<Format const *> const ControlSendto::allFormats() const
38 // What formats can we output natively?
39 vector<string> exports;
40 exports.push_back("lyx");
41 exports.push_back("text");
43 if (buffer()->isLatex())
44 exports.push_back("latex");
45 if (buffer()->isLinuxDoc())
46 exports.push_back("linuxdoc");
47 if (buffer()->isDocBook())
48 exports.push_back("docbook");
49 if (buffer()->isLiterate())
50 exports.push_back("literate");
52 // Loop over these native formats and ascertain what formats we
54 vector<Format const *> to;
56 vector<string>::const_iterator ex_it = exports.begin();
57 vector<string>::const_iterator ex_end = exports.end();
58 for (; ex_it != ex_end; ++ex_it) {
59 // Start off with the native export format.
60 // "formats" is LyX's list of recognised formats
61 to.push_back(formats.getFormat(*ex_it));
63 Formats::const_iterator fo_it = formats.begin();
64 Formats::const_iterator fo_end = formats.end();
65 for (; fo_it != fo_end; ++fo_it) {
66 // we need to hide the default graphic export formats
67 // from the external menu, because we need them only
68 // for the internal lyx-view and external latex run
69 string const name = fo_it->name();
70 if (name != "eps" && name != "xpm" && name != "png" &&
71 converters.isReachable(*ex_it, name))
72 to.push_back(&(*fo_it));
76 // Remove repeated formats.
77 std::sort(to.begin(), to.end());
79 vector<Format const *>::iterator to_begin = to.begin();
80 vector<Format const *>::iterator to_end = to.end();
81 vector<Format const *>::iterator to_it =
82 std::unique(to_begin, to_end);
84 to.erase(to_it, to_end);
90 void ControlSendto::setFormat(Format const * fmt)
96 void ControlSendto::setCommand(string const & cmd)
102 void ControlSendto::apply()
104 if (!bufferIsAvailable())
109 if (command_.empty() || !format_)
112 // The name of the file created by the conversion process
115 // Output to filename
116 if (format_->name() == "lyx") {
117 filename = ChangeExtension(buffer()->getLatexName(false),
118 format_->extension());
119 if (!buffer()->tmppath.empty())
120 filename = AddName(buffer()->tmppath, filename);
122 buffer()->writeFile(filename);
125 Exporter::Export(buffer(), format_->name(), true, filename);
128 // Substitute $$FName for filename
129 string command = command_;
130 if (!contains(command, "$$FName"))
131 command = "( " + command + " ) < $$FName";
132 command = subst(command, "$$FName", filename);
134 // Execute the command in the background
136 call.startscript(Systemcall::DontWait, command);