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 // Well, we can start with "lyx"
46 vector<Format const *> lyx_formats;
47 lyx_formats.push_back(formats.getFormat("lyx"));
49 // lyx can export to latex, what formats can be reached from latex?
50 Formats::const_iterator it = formats.begin();
51 Formats::const_iterator end = formats.end();
52 vector<Format const *>::const_iterator lbegin = lyx_formats.begin();
53 for (; it != end; ++it) {
54 if (converters.isReachable("latex", it->name())) {
55 vector<Format const *>::const_iterator lend =
58 if (std::find(lbegin, lend, it) == lend)
59 lyx_formats.push_back(it);
67 void ControlSendto::setFormat(Format const * fmt)
73 void ControlSendto::setCommand(string const & cmd)
75 command_ = strip(frontStrip(cmd));
79 void ControlSendto::apply()
81 if (!lv_.view()->available())
86 if (command_.empty() || !format_)
89 // The name of the file created by the conversion process
90 string filename = lv_.buffer()->getLatexName(false);
91 if (!lv_.buffer()->tmppath.empty())
92 filename = AddName(lv_.buffer()->tmppath, filename);
93 filename = ChangeExtension(filename, format_->extension());
96 if (format_->name() == "lyx") {
97 lv_.buffer()->writeFile(filename, true);
100 Exporter::Export(lv_.buffer(), format_->name(), true,
104 // Substitute $$FName for filename
105 string command = command_;
106 if (!contains(command, "$$FName"))
107 command = "( " + command + " ) < $$FName";
108 command = subst(command, "$$FName", filename);
110 // Execute the command in the background
112 call.startscript(Systemcall::DontWait, command);