]> git.lyx.org Git - lyx.git/blob - src/insets/InsetERT.cpp
3de5ccaf50423a17a02e517ef986e1e66967b016
[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 "MetricsInfo.h"
28 #include "OutputParams.h"
29 #include "ParagraphParameters.h"
30 #include "Paragraph.h"
31 #include "TextClass.h"
32
33 #include "frontends/alert.h"
34 #include "frontends/Application.h"
35
36 #include "support/debug.h"
37 #include "support/gettext.h"
38 #include "support/lstrings.h"
39
40 #include <sstream>
41
42 using namespace std;
43 using namespace lyx::support;
44
45 namespace lyx {
46
47 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
48         : InsetCollapsable(buf)
49 {
50         status_ = status;
51 }
52
53
54 void InsetERT::write(ostream & os) const
55 {
56         os << "ERT" << "\n";
57         InsetCollapsable::write(os);
58 }
59
60
61 int InsetERT::plaintext(odocstream & os, OutputParams const & rp) const
62 {
63         if (!rp.inIndexEntry)
64                 // do not output TeX code
65                 return 0;
66
67         ParagraphList::const_iterator par = paragraphs().begin();
68         ParagraphList::const_iterator end = paragraphs().end();
69
70         while (par != end) {
71                 pos_type siz = par->size();
72                 for (pos_type i = 0; i < siz; ++i) {
73                         char_type const c = par->getChar(i);
74                         // output the active characters
75                         switch (c) {
76                         case '|':
77                         case '!':
78                         case '@':
79                                 os.put(c);
80                                 break;
81                         default:
82                                 break;
83                         }
84                 }
85                 ++par;
86         }
87         return 0;
88 }
89
90
91 int InsetERT::docbook(odocstream & os, OutputParams const &) const
92 {
93         // FIXME can we do the same thing here as for LaTeX?
94         ParagraphList::const_iterator par = paragraphs().begin();
95         ParagraphList::const_iterator end = paragraphs().end();
96
97         int lines = 0;
98         while (par != end) {
99                 pos_type siz = par->size();
100                 for (pos_type i = 0; i < siz; ++i)
101                         os.put(par->getChar(i));
102                 ++par;
103                 if (par != end) {
104                         os << "\n";
105                         ++lines;
106                 }
107         }
108
109         return lines;
110 }
111
112
113 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
114 {
115         switch (cmd.action) {
116         case LFUN_INSET_MODIFY: {
117                 setStatus(cur, string2params(to_utf8(cmd.argument())));
118                 break;
119         }
120         default:
121                 InsetCollapsable::doDispatch(cur, cmd);
122                 break;
123         }
124 }
125
126
127 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
128         FuncStatus & status) const
129 {
130         switch (cmd.action) {
131         case LFUN_INSET_MODIFY:
132                 status.setEnabled(true);
133                 return true;
134                 
135         default:
136                 return InsetCollapsable::getStatus(cur, cmd, status);
137         }
138 }
139
140
141 docstring const InsetERT::buttonLabel(BufferView const & bv) const
142 {
143         if (decoration() == InsetLayout::CLASSIC)
144                 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
145         else
146                 return getNewLabel(_("ERT"));
147 }
148
149
150 InsetCollapsable::CollapseStatus InsetERT::string2params(string const & in)
151 {
152         if (in.empty())
153                 return Collapsed;
154         istringstream data(in);
155         Lexer lex;
156         lex.setStream(data);
157         lex.setContext("InsetERT::string2params");
158         lex >> "ert";
159         int s;
160         lex >> s;
161         return static_cast<CollapseStatus>(s);
162 }
163
164
165 string InsetERT::params2string(CollapseStatus status)
166 {
167         ostringstream data;
168         data << "ert" << ' ' << status;
169         return data.str();
170 }
171
172
173 docstring InsetERT::xhtml(XHTMLStream &, OutputParams const &) const
174 {
175         return docstring();
176 }
177
178 } // namespace lyx