2 * \file ControlSendto.C
3 * Copyright 2002 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming, a.leeming@.ac.uk
13 #pragma implementation
17 #include "ButtonControllerBase.h"
18 #include "ControlSendto.h"
21 #include "BufferView.h"
23 #include "converter.h"
27 #include "support/filetools.h"
28 #include "support/lstrings.h"
29 #include "support/systemcall.h"
34 ControlSendto::ControlSendto(LyXView & lv, Dialogs & d)
35 : ControlDialogBD(lv, d),
37 command_(lyxrc.custom_export_command)
39 d_.showSendto.connect(SigC::slot(this, &ControlSendto::show));
43 vector<Format const *> const ControlSendto::allFormats() const
45 // What formats can we output natively?
46 vector<string> exports;
47 exports.push_back("lyx");
48 exports.push_back("text");
50 if (lv_.buffer()->isLatex())
51 exports.push_back("latex");
52 if (lv_.buffer()->isLinuxDoc())
53 exports.push_back("linuxdoc");
54 if (lv_.buffer()->isDocBook())
55 exports.push_back("docbook");
56 if (lv_.buffer()->isLiterate())
57 exports.push_back("literate");
59 // Loop over these native formats and ascertain what formats we
61 vector<Format const *> to;
63 vector<string>::const_iterator ex_it = exports.begin();
64 vector<string>::const_iterator ex_end = exports.end();
65 for (; ex_it != ex_end; ++ex_it) {
66 // Start off with the native export format.
67 // "formats" is LyX's list of recognised formats
68 to.push_back(formats.getFormat(*ex_it));
70 Formats::const_iterator fo_it = formats.begin();
71 Formats::const_iterator fo_end = formats.end();
72 for (; fo_it != fo_end; ++fo_it) {
73 if (converters.isReachable(*ex_it, fo_it->name())) {
74 to.push_back(&(*fo_it));
79 // Remove repeated formats.
80 std::sort(to.begin(), to.end());
82 vector<Format const *>::iterator to_begin = to.begin();
83 vector<Format const *>::iterator to_end = to.end();
84 vector<Format const *>::iterator to_it =
85 std::unique(to_begin, to_end);
87 to.erase(to_it, to_end);
93 void ControlSendto::setFormat(Format const * fmt)
99 void ControlSendto::setCommand(string const & cmd)
101 command_ = strip(frontStrip(cmd));
105 void ControlSendto::apply()
107 if (!lv_.view()->available())
112 if (command_.empty() || !format_)
115 // The name of the file created by the conversion process
118 // Output to filename
119 if (format_->name() == "lyx") {
120 filename = ChangeExtension(lv_.buffer()->getLatexName(false),
121 format_->extension());
122 if (!lv_.buffer()->tmppath.empty())
123 filename = AddName(lv_.buffer()->tmppath, filename);
125 lv_.buffer()->writeFile(filename, true);
128 Exporter::Export(lv_.buffer(), format_->name(), true, filename);
131 // Substitute $$FName for filename
132 string command = command_;
133 if (!contains(command, "$$FName"))
134 command = "( " + command + " ) < $$FName";
135 command = subst(command, "$$FName", filename);
137 // Execute the command in the background
139 call.startscript(Systemcall::DontWait, command);