3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
15 #include "insetnote.h"
20 #include "BufferView.h"
23 #include "insets/insettext.h"
24 #include "support/LOstream.h"
25 #include "support/lstrings.h"
32 void InsetNote::init()
39 InsetNote::InsetNote(BufferParams const & bp, string const & label)
40 : InsetCollapsable(bp)
48 InsetNote::InsetNote(InsetNote const & in)
49 : InsetCollapsable(in), params_(in.params_)
55 InsetNote::~InsetNote() // MV
57 InsetNoteMailer mailer("note", *this);
62 auto_ptr<InsetBase> InsetNote::clone() const
64 return auto_ptr<InsetBase>(new InsetNote(*this));
68 string const InsetNote::editMessage() const
70 return _("Opened Note Inset");
74 void InsetNote::write(Buffer const * buf, ostream & os) const
77 InsetCollapsable::write(buf, os);
81 void InsetNote::read(Buffer const * buf, LyXLex & lex)
83 InsetCollapsable::read(buf, lex);
88 void InsetNote::setButtonLabel()
90 LyXFont font(LyXFont::ALL_SANE);
94 if (params_.type == "Note") {
95 setLabel(_("LyX Note"));
96 font.setColor(LColor::note);
97 setBackgroundColor(LColor::notebg);
98 } else if (params_.type == "Comment") {
99 setLabel(_("Comment"));
100 font.setColor(LColor::comment);
101 setBackgroundColor(LColor::commentbg);
103 setLabel(_("Greyed Out"));
104 font.setColor(LColor::greyedout);
105 setBackgroundColor(LColor::greyedoutbg);
111 bool InsetNote::showInsetDialog(BufferView * bv) const
113 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
118 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
120 BufferView * bv = cmd.view();
122 switch (cmd.action) {
123 case LFUN_INSET_MODIFY:
125 InsetNoteParams params;
126 InsetNoteMailer::string2params(cmd.argument, params);
127 params_.type = params.type;
129 bv->updateInset(this);
132 case LFUN_INSET_EDIT:
133 if (cmd.button() != mouse_button::button3)
134 return InsetCollapsable::localDispatch(cmd);
136 case LFUN_INSET_DIALOG_UPDATE:
137 InsetNoteMailer("note", *this).updateDialog(bv);
139 case LFUN_MOUSE_RELEASE:
140 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
141 InsetNoteMailer("note", *this).showDialog(bv);
146 return InsetCollapsable::localDispatch(cmd);
151 int InsetNote::latex(Buffer const * buf, ostream & os,
152 LatexRunParams const & runparams) const
154 string const pt = params_.type;
159 os << "%\n\\begin{comment}\n";
160 else if (pt == "Greyedout")
161 // we roll our own macro
162 os << "%\n\\begin{lyxgreyedout}\n";
165 i = inset.latex(buf, os, runparams);
167 if (pt == "Comment") {
168 os << "%\n\\end{comment}\n";
170 } else if (pt == "Greyedout") {
171 os << "%\n\\end{lyxgreyedout}\n";
178 int InsetNote::linuxdoc(Buffer const * buf, std::ostream & os) const
180 string const pt = params_.type;
187 i = inset.linuxdoc(buf, os);
189 if (pt == "Comment") {
190 os << "\n</comment>\n";
197 int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
199 string const pt = params_.type;
206 i = inset.docbook(buf, os, mixcont);
208 if (pt == "Comment") {
209 os << "\n</remark>\n";
216 int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
219 string const pt = params_.type;
222 i = inset.ascii(buf, os, ll);
229 void InsetNote::validate(LaTeXFeatures & features) const
231 if (params_.type == "Comment")
232 features.require("verbatim");
233 if (params_.type == "Greyedout") {
234 features.require("color");
235 features.require("lyxgreyedout");
237 inset.validate(features);
242 InsetNoteMailer::InsetNoteMailer(string const & name,
244 : name_(name), inset_(inset)
249 string const InsetNoteMailer::inset2string(Buffer const &) const
251 return params2string(name_, inset_.params());
255 string const InsetNoteMailer::params2string(string const & name,
256 InsetNoteParams const & params)
261 return STRCONV(data.str());
265 void InsetNoteMailer::string2params(string const & in,
266 InsetNoteParams & params)
268 params = InsetNoteParams();
273 istringstream data(STRCONV(in));
280 void InsetNoteParams::write(ostream & os) const
286 void InsetNoteParams::read(LyXLex & lex)
290 string token = lex.getString();
295 type = lex.getString();