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"
29 #include "ParagraphParameters.h"
30 #include "Paragraph.h"
32 #include "support/docstream.h"
33 #include "support/gettext.h"
34 #include "support/lstrings.h"
35 #include "support/TempFile.h"
40 using namespace lyx::support;
44 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
45 : InsetCollapsible(buf)
51 InsetERT::InsetERT(InsetERT const & old)
52 : InsetCollapsible(old)
56 void InsetERT::write(ostream & os) const
59 InsetCollapsible::write(os);
63 int InsetERT::plaintext(odocstringstream & os,
64 OutputParams const & rp, size_t max_length) const
67 // do not output TeX code
70 ParagraphList::const_iterator par = paragraphs().begin();
71 ParagraphList::const_iterator end = paragraphs().end();
73 while (par != end && os.str().size() <= max_length) {
74 pos_type siz = par->size();
75 for (pos_type i = 0; i < siz; ++i) {
76 char_type const c = par->getChar(i);
77 // output the active characters
94 void InsetERT::docbook(XMLStream & xs, OutputParams const &) const
96 // FIXME can we do the same thing here as for LaTeX?
97 ParagraphList::const_iterator par = paragraphs().begin();
98 ParagraphList::const_iterator end = paragraphs().end();
100 xs << XMLStream::ESCAPE_NONE << "<!-- ";
102 pos_type siz = par->size();
103 for (pos_type i = 0; i < siz; ++i) {
104 xs << par->getChar(i);
111 xs << XMLStream::ESCAPE_NONE << " -->";
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