]> git.lyx.org Git - lyx.git/blob - src/insets/InsetERT.cpp
Do not output deleted rows columns if show changes in output is false
[lyx.git] / src / insets / InsetERT.cpp
1 /**
2  * \file InsetERT.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetERT.h"
15
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "BufferView.h"
19 #include "Cursor.h"
20 #include "DispatchResult.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
23 #include "Language.h"
24 #include "Layout.h"
25 #include "Lexer.h"
26 #include "LyXAction.h"
27 #include "OutputParams.h"
28 #include "ParagraphParameters.h"
29 #include "Paragraph.h"
30
31 #include "support/docstream.h"
32 #include "support/gettext.h"
33 #include "support/lstrings.h"
34 #include "support/TempFile.h"
35
36 #include <sstream>
37
38 using namespace std;
39 using namespace lyx::support;
40
41 namespace lyx {
42
43 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
44         : InsetCollapsible(buf)
45 {
46         status_ = status;
47 }
48
49
50 InsetERT::InsetERT(InsetERT const & old)
51         : InsetCollapsible(old)
52 {}
53
54
55 void InsetERT::write(ostream & os) const
56 {
57         os << "ERT" << "\n";
58         InsetCollapsible::write(os);
59 }
60
61
62 int InsetERT::plaintext(odocstringstream & os,
63         OutputParams const & rp, size_t max_length) const
64 {
65         if (!rp.inIndexEntry)
66                 // do not output TeX code
67                 return 0;
68
69         ParagraphList::const_iterator par = paragraphs().begin();
70         ParagraphList::const_iterator end = paragraphs().end();
71
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
77                         switch (c) {
78                         case '|':
79                         case '!':
80                         case '@':
81                                 os.put(c);
82                                 break;
83                         default:
84                                 break;
85                         }
86                 }
87                 ++par;
88         }
89         return 0;
90 }
91
92
93 int InsetERT::docbook(odocstream & os, OutputParams const &) const
94 {
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();
98
99         int lines = 0;
100         while (par != end) {
101                 pos_type siz = par->size();
102                 for (pos_type i = 0; i < siz; ++i)
103                         os.put(par->getChar(i));
104                 ++par;
105                 if (par != end) {
106                         os << "\n";
107                         ++lines;
108                 }
109         }
110
111         return lines;
112 }
113
114
115 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
116 {
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())));
122                         break;
123                 }
124                 //fall-through
125         default:
126                 InsetCollapsible::doDispatch(cur, cmd);
127                 break;
128         }
129
130 }
131
132
133 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
134         FuncStatus & status) const
135 {
136         switch (cmd.action()) {
137         case LFUN_INSET_INSERT:
138                 status.setEnabled(false);
139                 return true;
140         case LFUN_INSET_MODIFY:
141                 if (cmd.getArg(0) == "ert") {
142                         status.setEnabled(true);
143                         return true;
144                 }
145                 //fall through
146
147         default:
148                 return InsetCollapsible::getStatus(cur, cmd, status);
149         }
150 }
151
152
153
154 docstring const InsetERT::buttonLabel(BufferView const & bv) const
155 {
156         if (decoration() == InsetLayout::CLASSIC)
157                 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
158         else
159                 return getNewLabel(_("ERT"));
160 }
161
162
163 InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
164 {
165         if (in.empty())
166                 return Collapsed;
167         istringstream data(in);
168         Lexer lex;
169         lex.setStream(data);
170         lex.setContext("InsetERT::string2params");
171         lex >> "ert";
172         int s;
173         lex >> s;
174         return static_cast<CollapseStatus>(s);
175 }
176
177
178 string InsetERT::params2string(CollapseStatus status)
179 {
180         ostringstream data;
181         data << "ert" << ' ' << status;
182         return data.str();
183 }
184
185
186 docstring InsetERT::xhtml(XHTMLStream &, OutputParams const &) const
187 {
188         return docstring();
189 }
190
191 } // namespace lyx