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 && cmd.x < button_length
136 && cmd.y >= button_top_y && cmd.y <= button_bottom_y) {
137 InsetNoteMailer("note", *this).showDialog(bv);
142 return InsetCollapsable::localDispatch(cmd);
147 int InsetNote::latex(Buffer const * buf, ostream & os,
148 LatexRunParams const & runparams) const
150 string const pt = params_.type;
154 os << "%\n\\begin{comment}\n"; // remember to validate
155 else if (pt == "Greyedout")
156 os << "%\n\\textcolor[gray]{0.8}{";
159 i = inset.latex(buf, os, runparams);
161 if (pt == "Comment") {
162 os << "%\n\\end{comment}\n";
164 } else if (pt == "Greyedout") {
165 os << "\\normalcolor%\n}";
172 int InsetNote::linuxdoc(Buffer const *, std::ostream &) const
178 int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
181 string const pt = params_.type;
182 // incomplete, untested - MV
184 i = inset.docbook(buf, os, mixcont);
189 int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
192 string const pt = params_.type;
195 i = inset.ascii(buf, os, ll);
202 void InsetNote::validate(LaTeXFeatures & features) const
204 if (params_.type == "Comment")
205 features.require("verbatim");
206 if (params_.type == "Greyedout")
207 features.require("color");
208 inset.validate(features);
213 InsetNoteMailer::InsetNoteMailer(string const & name,
215 : name_(name), inset_(inset)
220 string const InsetNoteMailer::inset2string(Buffer const &) const
222 return params2string(name_, inset_.params());
226 string const InsetNoteMailer::params2string(string const & name,
227 InsetNoteParams const & params)
232 return STRCONV(data.str());
236 void InsetNoteMailer::string2params(string const & in,
237 InsetNoteParams & params)
239 params = InsetNoteParams();
244 istringstream data(STRCONV(in));
251 void InsetNoteParams::write(ostream & os) const
257 void InsetNoteParams::read(LyXLex & lex)
261 string token = lex.getString();
266 type = lex.getString();