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"
30 #include "TextClass.h"
32 #include "support/gettext.h"
33 #include "support/lstrings.h"
38 using namespace lyx::support;
42 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
43 : InsetCollapsable(buf)
49 void InsetERT::write(ostream & os) const
52 InsetCollapsable::write(os);
56 int InsetERT::plaintext(odocstringstream & os,
57 OutputParams const & rp, size_t max_length) const
60 // do not output TeX code
63 ParagraphList::const_iterator par = paragraphs().begin();
64 ParagraphList::const_iterator end = paragraphs().end();
66 while (par != end && os.str().size() <= max_length) {
67 pos_type siz = par->size();
68 for (pos_type i = 0; i < siz; ++i) {
69 char_type const c = par->getChar(i);
70 // output the active characters
87 int InsetERT::docbook(odocstream & os, OutputParams const &) const
89 // FIXME can we do the same thing here as for LaTeX?
90 ParagraphList::const_iterator par = paragraphs().begin();
91 ParagraphList::const_iterator end = paragraphs().end();
95 pos_type siz = par->size();
96 for (pos_type i = 0; i < siz; ++i)
97 os.put(par->getChar(i));
109 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
111 switch (cmd.action()) {
112 case LFUN_INSET_MODIFY:
113 if (cmd.getArg(0) == "ert") {
114 cur.recordUndoInset(ATOMIC_UNDO, this);
115 setStatus(cur, string2params(to_utf8(cmd.argument())));
120 InsetCollapsable::doDispatch(cur, cmd);
127 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
128 FuncStatus & status) const
130 switch (cmd.action()) {
131 case LFUN_INSET_MODIFY:
132 if (cmd.getArg(0) == "ert") {
133 status.setEnabled(true);
139 return InsetCollapsable::getStatus(cur, cmd, status);
144 docstring const InsetERT::buttonLabel(BufferView const & bv) const
146 if (decoration() == InsetLayout::CLASSIC)
147 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
149 return getNewLabel(_("ERT"));
153 InsetCollapsable::CollapseStatus InsetERT::string2params(string const & in)
157 istringstream data(in);
160 lex.setContext("InsetERT::string2params");
164 return static_cast<CollapseStatus>(s);
168 string InsetERT::params2string(CollapseStatus status)
171 data << "ert" << ' ' << status;
176 docstring InsetERT::xhtml(XHTMLStream &, OutputParams const &) const