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_EDIT:
138 status.setEnabled(tempfile_ == 0);
140 case LFUN_INSET_END_EDIT:
141 status.setEnabled(tempfile_ != 0);
143 case LFUN_INSET_INSERT:
144 status.setEnabled(false);
146 case LFUN_INSET_MODIFY:
147 if (cmd.getArg(0) == "ert") {
148 status.setEnabled(true);
154 return InsetCollapsible::getStatus(cur, cmd, status);
160 docstring const InsetERT::buttonLabel(BufferView const & bv) const
162 if (decoration() == InsetLayout::CLASSIC)
163 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
165 return getNewLabel(_("ERT"));
169 InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
173 istringstream data(in);
176 lex.setContext("InsetERT::string2params");
180 return static_cast<CollapseStatus>(s);
184 string InsetERT::params2string(CollapseStatus status)
187 data << "ert" << ' ' << status;
192 docstring InsetERT::xhtml(XHTMLStream &, OutputParams const &) const