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_QUOTE_INSERT: {
113 // We need to bypass the fancy quotes in Text
114 FuncRequest f(LFUN_SELF_INSERT, "\"");
118 case LFUN_INSET_MODIFY: {
119 setStatus(cur, string2params(to_utf8(cmd.argument())));
123 // Force any new text to latex_language
124 // FIXME: This should not be necessary but
125 // new paragraphs that are created by pressing enter at the
126 // start of an existing paragraph get the buffer language
127 // and not latex_language, so we take this brute force
129 cur.current_font.fontInfo() = layout.font;
130 cur.real_current_font.fontInfo() = layout.font;
131 InsetCollapsable::doDispatch(cur, cmd);
137 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
138 FuncStatus & status) const
140 switch (cmd.action) {
141 case LFUN_CLIPBOARD_PASTE:
142 case LFUN_INSET_MODIFY:
144 case LFUN_PRIMARY_SELECTION_PASTE:
145 case LFUN_QUOTE_INSERT:
146 status.setEnabled(true);
149 // this one is difficult to get right. As a half-baked
150 // solution, we consider only the first action of the sequence
151 case LFUN_COMMAND_SEQUENCE: {
152 // argument contains ';'-terminated commands
153 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
154 FuncRequest func(lyxaction.lookupFunc(firstcmd));
155 func.origin = cmd.origin;
156 return getStatus(cur, func, status);
160 return InsetCollapsable::getStatus(cur, cmd, status);
165 void InsetERT::setButtonLabel()
167 if (decoration() == InsetLayout::CLASSIC)
168 setLabel(isOpen() ? _("ERT") : getNewLabel(_("ERT")));
170 setLabel(getNewLabel(_("ERT")));
174 bool InsetERT::insetAllowed(InsetCode /* code */) const
180 bool InsetERT::showInsetDialog(BufferView * bv) const
182 bv->showDialog("ert", params2string(status()),
183 const_cast<InsetERT *>(this));
188 InsetCollapsable::CollapseStatus InsetERT::string2params(string const & in)
192 istringstream data(in);
195 lex.setContext("InsetERT::string2params");
199 return static_cast<CollapseStatus>(s);
203 string InsetERT::params2string(CollapseStatus status)
206 data << "ert" << ' ' << status;