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 "OutputParams.h"
28 #include "ParagraphParameters.h"
29 #include "Paragraph.h"
31 #include "support/docstream.h"
32 #include "support/gettext.h"
33 #include "support/lstrings.h"
34 #include "support/TempFile.h"
39 using namespace lyx::support;
43 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
44 : InsetCollapsible(buf)
50 InsetERT::InsetERT(InsetERT const & old)
51 : InsetCollapsible(old)
55 void InsetERT::write(ostream & os) const
58 InsetCollapsible::write(os);
62 int InsetERT::plaintext(odocstringstream & os,
63 OutputParams const & rp, size_t max_length) const
66 // do not output TeX code
69 ParagraphList::const_iterator par = paragraphs().begin();
70 ParagraphList::const_iterator end = paragraphs().end();
72 while (par != end && os.str().size() <= max_length) {
73 pos_type siz = par->size();
74 for (pos_type i = 0; i < siz; ++i) {
75 char_type const c = par->getChar(i);
76 // output the active characters
93 int InsetERT::docbook(odocstream & os, OutputParams const &) const
95 // FIXME can we do the same thing here as for LaTeX?
96 ParagraphList::const_iterator par = paragraphs().begin();
97 ParagraphList::const_iterator end = paragraphs().end();
101 pos_type siz = par->size();
102 for (pos_type i = 0; i < siz; ++i)
103 os.put(par->getChar(i));
115 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
117 switch (cmd.action()) {
118 case LFUN_INSET_MODIFY:
119 if (cmd.getArg(0) == "ert") {
120 cur.recordUndoInset(this);
121 setStatus(cur, string2params(to_utf8(cmd.argument())));
126 InsetCollapsible::doDispatch(cur, cmd);
133 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
134 FuncStatus & status) const
136 switch (cmd.action()) {
137 case LFUN_INSET_INSERT:
138 status.setEnabled(false);
140 case LFUN_INSET_MODIFY:
141 if (cmd.getArg(0) == "ert") {
142 status.setEnabled(true);
148 return InsetCollapsible::getStatus(cur, cmd, status);
154 docstring const InsetERT::buttonLabel(BufferView const & bv) const
156 if (decoration() == InsetLayout::CLASSIC)
157 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
159 return getNewLabel(_("ERT"));
163 InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
167 istringstream data(in);
170 lex.setContext("InsetERT::string2params");
174 return static_cast<CollapseStatus>(s);
178 string InsetERT::params2string(CollapseStatus status)
181 data << "ert" << ' ' << status;
186 docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const