]> git.lyx.org Git - lyx.git/blob - src/insets/InsetERT.cpp
remove all trace of editMessage
[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 "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 const & buf, CollapseStatus status)
47         : InsetCollapsable(buf)
48 {
49         status_ = status;
50 }
51
52
53 InsetERT::~InsetERT()
54 {
55         hideDialogs("ert", this);
56 }
57
58
59 void InsetERT::write(ostream & os) const
60 {
61         os << "ERT" << "\n";
62         InsetCollapsable::write(os);
63 }
64
65
66 int InsetERT::plaintext(odocstream &, OutputParams const &) const
67 {
68         return 0; // do not output TeX code
69 }
70
71
72 int InsetERT::docbook(odocstream & os, OutputParams const &) const
73 {
74         // FIXME can we do the same thing here as for LaTeX?
75         ParagraphList::const_iterator par = paragraphs().begin();
76         ParagraphList::const_iterator end = paragraphs().end();
77
78         int lines = 0;
79         while (par != end) {
80                 pos_type siz = par->size();
81                 for (pos_type i = 0; i < siz; ++i)
82                         os.put(par->getChar(i));
83                 ++par;
84                 if (par != end) {
85                         os << "\n";
86                         ++lines;
87                 }
88         }
89
90         return lines;
91 }
92
93
94 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
95 {
96         switch (cmd.action) {
97         case LFUN_INSET_MODIFY: {
98                 setStatus(cur, string2params(to_utf8(cmd.argument())));
99                 break;
100         }
101         default:
102                 InsetCollapsable::doDispatch(cur, cmd);
103                 break;
104         }
105 }
106
107
108 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
109         FuncStatus & status) const
110 {
111         switch (cmd.action) {
112         case LFUN_INSET_MODIFY:
113                 status.setEnabled(true);
114                 return true;
115                 
116         default:
117                 return InsetCollapsable::getStatus(cur, cmd, status);
118         }
119 }
120
121
122 docstring const InsetERT::buttonLabel(BufferView const & bv) const
123 {
124         if (decoration() == InsetLayout::CLASSIC)
125                 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
126         else
127                 return getNewLabel(_("ERT"));
128 }
129
130
131 bool InsetERT::insetAllowed(InsetCode /* code */) const
132 {
133         return false;
134 }
135
136
137 bool InsetERT::showInsetDialog(BufferView * bv) const
138 {
139         bv->showDialog("ert", params2string(status(*bv)), 
140                 const_cast<InsetERT *>(this));
141         return true;
142 }
143
144
145 InsetCollapsable::CollapseStatus InsetERT::string2params(string const & in)
146 {
147         if (in.empty())
148                 return Collapsed;
149         istringstream data(in);
150         Lexer lex;
151         lex.setStream(data);
152         lex.setContext("InsetERT::string2params");
153         lex >> "ert";
154         int s;
155         lex >> s;
156         return static_cast<CollapseStatus>(s);
157 }
158
159
160 string InsetERT::params2string(CollapseStatus status)
161 {
162         ostringstream data;
163         data << "ert" << ' ' << status;
164         return data.str();
165 }
166
167
168 docstring InsetERT::xhtml(odocstream &, OutputParams const &) const
169 {
170         return docstring();
171 }
172
173 } // namespace lyx