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 setLabel(params_.type);
95 if (params_.type == "Note" || params_.type == "Comment") {
96 font.setColor(LColor::note);
97 setBackgroundColor(LColor::notebg);
99 font.setColor(LColor::red);
100 setBackgroundColor(LColor::background);
106 bool InsetNote::showInsetDialog(BufferView * bv) const
108 InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
113 dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
115 BufferView * bv = cmd.view();
117 switch (cmd.action) {
118 case LFUN_INSET_MODIFY:
120 InsetNoteParams params;
121 InsetNoteMailer::string2params(cmd.argument, params);
122 params_.type = params.type;
124 bv->updateInset(this);
127 case LFUN_INSET_EDIT:
128 if (cmd.button() != mouse_button::button3)
129 return InsetCollapsable::localDispatch(cmd);
131 case LFUN_INSET_DIALOG_UPDATE:
132 InsetNoteMailer("note", *this).updateDialog(bv);
134 case LFUN_MOUSE_RELEASE:
135 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
136 InsetNoteMailer("note", *this).showDialog(bv);
141 return InsetCollapsable::localDispatch(cmd);
146 int InsetNote::latex(Buffer const * buf, ostream & os,
147 LatexRunParams const & runparams) const
149 string const pt = params_.type;
154 os << "%\n\\begin{comment}\n";
155 else if (pt == "Greyedout")
156 // we roll our own macro
157 os << "%\n\\begin{lyxgreyedout}\n";
160 i = inset.latex(buf, os, runparams);
162 if (pt == "Comment") {
163 os << "%\n\\end{comment}\n";
165 } else if (pt == "Greyedout") {
166 os << "%\n\\end{lyxgreyedout}\n";
173 int InsetNote::linuxdoc(Buffer const * buf, std::ostream & os) const
175 string const pt = params_.type;
182 i = inset.linuxdoc(buf, os);
184 if (pt == "Comment") {
185 os << "\n</comment>\n";
192 int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
194 string const pt = params_.type;
201 i = inset.docbook(buf, os, mixcont);
203 if (pt == "Comment") {
204 os << "\n</remark>\n";
211 int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
214 string const pt = params_.type;
217 i = inset.ascii(buf, os, ll);
224 void InsetNote::validate(LaTeXFeatures & features) const
226 if (params_.type == "Comment")
227 features.require("verbatim");
228 if (params_.type == "Greyedout") {
229 features.require("color");
230 features.require("lyxgreyedout");
232 inset.validate(features);
237 InsetNoteMailer::InsetNoteMailer(string const & name,
239 : name_(name), inset_(inset)
244 string const InsetNoteMailer::inset2string(Buffer const &) const
246 return params2string(name_, inset_.params());
250 string const InsetNoteMailer::params2string(string const & name,
251 InsetNoteParams const & params)
256 return STRCONV(data.str());
260 void InsetNoteMailer::string2params(string const & in,
261 InsetNoteParams & params)
263 params = InsetNoteParams();
268 istringstream data(STRCONV(in));
275 void InsetNoteParams::write(ostream & os) const
281 void InsetNoteParams::read(LyXLex & lex)
285 string token = lex.getString();
290 type = lex.getString();