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, status)
53 hideDialogs("ert", this);
57 void InsetERT::write(ostream & os) const
60 InsetCollapsable::write(os);
64 docstring InsetERT::editMessage() const
66 return _("Opened ERT Inset");
70 int InsetERT::latex(odocstream & os, OutputParams const & op) const
72 return InsetCollapsable::latex(os, op);
76 int InsetERT::plaintext(odocstream &, OutputParams const &) const
78 return 0; // do not output TeX code
82 int InsetERT::docbook(odocstream & os, OutputParams const &) const
84 // FIXME can we do the same thing here as for LaTeX?
85 ParagraphList::const_iterator par = paragraphs().begin();
86 ParagraphList::const_iterator end = paragraphs().end();
90 pos_type siz = par->size();
91 for (pos_type i = 0; i < siz; ++i)
92 os.put(par->getChar(i));
104 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
106 BufferParams const & bp = cur.buffer().params();
107 Layout const layout = bp.documentClass().plainLayout();
108 //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl;
109 switch (cmd.action) {
110 case LFUN_QUOTE_INSERT: {
111 // We need to bypass the fancy quotes in Text
112 FuncRequest f(LFUN_SELF_INSERT, "\"");
116 case LFUN_INSET_MODIFY: {
117 setStatus(cur, string2params(to_utf8(cmd.argument())));
121 // Force any new text to latex_language
122 // FIXME: This should not be necessary but
123 // new paragraphs that are created by pressing enter at the
124 // start of an existing paragraph get the buffer language
125 // and not latex_language, so we take this brute force
127 cur.current_font.fontInfo() = layout.font;
128 cur.real_current_font.fontInfo() = layout.font;
129 InsetCollapsable::doDispatch(cur, cmd);
135 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
136 FuncStatus & status) const
138 switch (cmd.action) {
139 case LFUN_CLIPBOARD_PASTE:
140 case LFUN_INSET_MODIFY:
142 case LFUN_PRIMARY_SELECTION_PASTE:
143 case LFUN_QUOTE_INSERT:
144 status.setEnabled(true);
147 // this one is difficult to get right. As a half-baked
148 // solution, we consider only the first action of the sequence
149 case LFUN_COMMAND_SEQUENCE: {
150 // argument contains ';'-terminated commands
151 string const firstcmd = token(to_utf8(cmd.argument()), ';', 0);
152 FuncRequest func(lyxaction.lookupFunc(firstcmd));
153 func.origin = cmd.origin;
154 return getStatus(cur, func, status);
158 return InsetCollapsable::getStatus(cur, cmd, status);
163 void InsetERT::setButtonLabel()
165 if (decoration() == InsetLayout::Classic)
166 setLabel(isOpen() ? _("ERT") : getNewLabel(_("ERT")));
168 setLabel(getNewLabel(_("ERT")));
172 bool InsetERT::insetAllowed(InsetCode /* code */) const
178 void InsetERT::draw(PainterInfo & pi, int x, int y) const
180 const_cast<InsetERT &>(*this).setButtonLabel();
181 InsetCollapsable::draw(pi, x, y);
185 bool InsetERT::showInsetDialog(BufferView * bv) const
187 bv->showDialog("ert", params2string(status()),
188 const_cast<InsetERT *>(this));
193 InsetCollapsable::CollapseStatus InsetERT::string2params(string const & in)
197 istringstream data(in);
200 lex.setContext("InsetERT::string2params");
204 return static_cast<CollapseStatus>(s);
208 string InsetERT::params2string(CollapseStatus status)
211 data << "ert" << ' ' << status;