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 // we need to hide the default graphic export formats
74 // from the external menu, because we need them only
75 // for the internal lyx-view and external latex run
76 string const name = fo_it->name();
77 if (name != "eps" && name != "xpm" && name != "png" &&
78 converters.isReachable(*ex_it, name))
79 to.push_back(&(*fo_it));
83 // Remove repeated formats.
84 std::sort(to.begin(), to.end());
86 vector<Format const *>::iterator to_begin = to.begin();
87 vector<Format const *>::iterator to_end = to.end();
88 vector<Format const *>::iterator to_it =
89 std::unique(to_begin, to_end);
91 to.erase(to_it, to_end);
97 void ControlSendto::setFormat(Format const * fmt)
103 void ControlSendto::setCommand(string const & cmd)
105 command_ = strip(frontStrip(cmd));
109 void ControlSendto::apply()
111 if (!lv_.view()->available())
116 if (command_.empty() || !format_)
119 // The name of the file created by the conversion process
122 // Output to filename
123 if (format_->name() == "lyx") {
124 filename = ChangeExtension(lv_.buffer()->getLatexName(false),
125 format_->extension());
126 if (!lv_.buffer()->tmppath.empty())
127 filename = AddName(lv_.buffer()->tmppath, filename);
129 lv_.buffer()->writeFile(filename, true);
132 Exporter::Export(lv_.buffer(), format_->name(), true, filename);
135 // Substitute $$FName for filename
136 string command = command_;
137 if (!contains(command, "$$FName"))
138 command = "( " + command + " ) < $$FName";
139 command = subst(command, "$$FName", filename);
141 // Execute the command in the background
143 call.startscript(Systemcall::DontWait, command);