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