]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlSendto.C
some support for pch
[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 std::vector;
24 using std::string;
25
26 namespace lyx {
27
28 using support::AddName;
29 using support::trim;
30
31 namespace frontend {
32
33
34 ControlSendto::ControlSendto(Dialog & parent)
35         : Dialog::Controller(parent)
36 {}
37
38
39 bool ControlSendto::initialiseParams(std::string const &)
40 {
41         format_ = 0;
42         command_ = lyxrc.custom_export_command;
43         return true;
44 }
45
46
47 void ControlSendto::dispatchParams()
48 {
49         if (command_.empty() || !format_ || format_->name().empty())
50                 return;
51
52         string const data = format_->name() + " " + command_;
53         kernel().dispatch(FuncRequest(LFUN_EXPORT_CUSTOM, data));
54 }
55
56
57 vector<Format const *> const ControlSendto::allFormats() const
58 {
59         // What formats can we output natively?
60         vector<string> exports;
61         exports.push_back("lyx");
62         exports.push_back("text");
63
64         Buffer const & buffer = kernel().buffer();
65
66         if (buffer.isLatex())
67                 exports.push_back("latex");
68         else if (buffer.isLinuxDoc())
69                 exports.push_back("linuxdoc");
70         else if (buffer.isDocBook())
71                 exports.push_back("docbook");
72         else if (buffer.isLiterate())
73                 exports.push_back("literate");
74
75         // Loop over these native formats and ascertain what formats we
76         // can convert to
77         vector<Format const *> to;
78
79         vector<string>::const_iterator ex_it  = exports.begin();
80         vector<string>::const_iterator ex_end = exports.end();
81         for (; ex_it != ex_end; ++ex_it) {
82                 // Start off with the native export format.
83                 // "formats" is LyX's list of recognised formats
84                 to.push_back(formats.getFormat(*ex_it));
85
86                 Formats::const_iterator fo_it  = formats.begin();
87                 Formats::const_iterator fo_end = formats.end();
88                 for (; fo_it != fo_end; ++fo_it) {
89                         // we need to hide the default graphic export formats
90                         // from the external menu, because we need them only
91                         // for the internal lyx-view and external latex run
92                         string const name = fo_it->name();
93                         if (name != "eps" && name != "xpm" && name != "png" &&
94                             converters.isReachable(*ex_it, name))
95                                 to.push_back(&(*fo_it));
96                 }
97         }
98
99         // Remove repeated formats.
100         std::sort(to.begin(), to.end());
101         to.erase(std::unique(to.begin(), to.end()), to.end());
102
103         return to;
104 }
105
106
107 void ControlSendto::setFormat(Format const * fmt)
108 {
109         format_ = fmt;
110 }
111
112
113 void ControlSendto::setCommand(string const & cmd)
114 {
115         command_ = trim(cmd);
116 }
117
118 } // namespace frontend
119 } // namespace lyx