]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlSendto.C
5 new lfuns, move all apply code out of ControlDocument and into the core.
[lyx.git] / src / frontends / controllers / ControlSendto.C
1 /**
2  * \file ControlSendto.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlSendto.h"
14 #include "buffer.h"
15 #include "converter.h"
16 #include "format.h"
17 #include "funcrequest.h"
18 #include "lyxrc.h"
19
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
22
23 using lyx::support::AddName;
24 using lyx::support::trim;
25
26 using std::vector;
27 using std::string;
28
29
30 ControlSendto::ControlSendto(Dialog & parent)
31         : Dialog::Controller(parent)
32 {}
33
34
35 bool ControlSendto::initialiseParams(std::string const &)
36 {
37         format_ = 0;
38         command_ = lyxrc.custom_export_command;
39         return true;
40 }
41
42
43 void ControlSendto::dispatchParams()
44 {
45         if (command_.empty() || !format_ || format_->name().empty())
46                 return;
47
48         string const data = format_->name() + " " + command_;
49         kernel().dispatch(FuncRequest(LFUN_EXPORT_CUSTOM, data));
50 }
51
52
53 vector<Format const *> const ControlSendto::allFormats() const
54 {
55         // What formats can we output natively?
56         vector<string> exports;
57         exports.push_back("lyx");
58         exports.push_back("text");
59
60         Buffer const & buffer = kernel().buffer();
61
62         if (buffer.isLatex())
63                 exports.push_back("latex");
64         else if (buffer.isLinuxDoc())
65                 exports.push_back("linuxdoc");
66         else if (buffer.isDocBook())
67                 exports.push_back("docbook");
68         else if (buffer.isLiterate())
69                 exports.push_back("literate");
70
71         // Loop over these native formats and ascertain what formats we
72         // can convert to
73         vector<Format const *> to;
74
75         vector<string>::const_iterator ex_it  = exports.begin();
76         vector<string>::const_iterator ex_end = exports.end();
77         for (; ex_it != ex_end; ++ex_it) {
78                 // Start off with the native export format.
79                 // "formats" is LyX's list of recognised formats
80                 to.push_back(formats.getFormat(*ex_it));
81
82                 Formats::const_iterator fo_it  = formats.begin();
83                 Formats::const_iterator fo_end = formats.end();
84                 for (; fo_it != fo_end; ++fo_it) {
85                         // we need to hide the default graphic export formats
86                         // from the external menu, because we need them only
87                         // for the internal lyx-view and external latex run
88                         string const name = fo_it->name();
89                         if (name != "eps" && name != "xpm" && name != "png" &&
90                             converters.isReachable(*ex_it, name))
91                                 to.push_back(&(*fo_it));
92                 }
93         }
94
95         // Remove repeated formats.
96         std::sort(to.begin(), to.end());
97         to.erase(std::unique(to.begin(), to.end()), to.end());
98
99         return to;
100 }
101
102
103 void ControlSendto::setFormat(Format const * fmt)
104 {
105         format_ = fmt;
106 }
107
108
109 void ControlSendto::setCommand(string const & cmd)
110 {
111         command_ = trim(cmd);
112 }