3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
17 #include "BufferParams.h"
18 #include "BufferView.h"
20 #include "DispatchResult.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
26 #include "LyXAction.h"
27 #include "MetricsInfo.h"
28 #include "ParagraphParameters.h"
29 #include "Paragraph.h"
30 #include "TextClass.h"
32 #include "frontends/alert.h"
33 #include "frontends/Application.h"
35 #include "support/debug.h"
36 #include "support/gettext.h"
37 #include "support/lstrings.h"
42 using namespace lyx::support;
46 InsetERT::InsetERT(Buffer const & buf, CollapseStatus status)
47 : InsetCollapsable(buf)
55 hideDialogs("ert", this);
59 void InsetERT::write(ostream & os) const
62 InsetCollapsable::write(os);
66 docstring InsetERT::editMessage() const
68 return _("Opened ERT Inset");
72 int InsetERT::latex(odocstream & os, OutputParams const & op) const
74 return InsetCollapsable::latex(os, op);
78 int InsetERT::plaintext(odocstream &, OutputParams const &) const
80 return 0; // do not output TeX code
84 int InsetERT::docbook(odocstream & os, OutputParams const &) const
86 // FIXME can we do the same thing here as for LaTeX?
87 ParagraphList::const_iterator par = paragraphs().begin();
88 ParagraphList::const_iterator end = paragraphs().end();
92 pos_type siz = par->size();
93 for (pos_type i = 0; i < siz; ++i)
94 os.put(par->getChar(i));
106 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
108 BufferParams const & bp = cur.buffer()->params();
109 Layout const layout = bp.documentClass().plainLayout();
110 //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl;
111 switch (cmd.action) {
112 case LFUN_INSET_MODIFY: {
113 setStatus(cur, string2params(to_utf8(cmd.argument())));
117 // Force any new text to latex_language
118 // FIXME: This should not be necessary but
119 // new paragraphs that are created by pressing enter at the
120 // start of an existing paragraph get the buffer language
121 // and not latex_language, so we take this brute force
123 cur.current_font.fontInfo() = layout.font;
124 cur.real_current_font.fontInfo() = layout.font;
125 InsetCollapsable::doDispatch(cur, cmd);
131 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
132 FuncStatus & status) const
134 switch (cmd.action) {
135 case LFUN_CLIPBOARD_PASTE:
136 case LFUN_INSET_MODIFY:
138 case LFUN_PRIMARY_SELECTION_PASTE:
139 case LFUN_QUOTE_INSERT:
140 status.setEnabled(true);
143 // this one is difficult to get right. As a half-baked
144 // solution, we consider only the first action of the sequence
145 case LFUN_COMMAND_SEQUENCE: {
146 // argument contains ';'-terminated commands
147 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
148 FuncRequest func(lyxaction.lookupFunc(firstcmd));
149 func.origin = cmd.origin;
150 return getStatus(cur, func, status);
154 return InsetCollapsable::getStatus(cur, cmd, status);
159 docstring const InsetERT::buttonLabel(BufferView const & bv) const
161 if (decoration() == InsetLayout::CLASSIC)
162 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
164 return getNewLabel(_("ERT"));
168 bool InsetERT::insetAllowed(InsetCode /* code */) const
174 bool InsetERT::showInsetDialog(BufferView * bv) const
176 bv->showDialog("ert", params2string(status(*bv)),
177 const_cast<InsetERT *>(this));
182 InsetCollapsable::CollapseStatus InsetERT::string2params(string const & in)
186 istringstream data(in);
189 lex.setContext("InsetERT::string2params");
193 return static_cast<CollapseStatus>(s);
197 string InsetERT::params2string(CollapseStatus status)
200 data << "ert" << ' ' << status;
205 docstring InsetERT::xhtml(odocstream &, OutputParams const &) const