3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Martin Vermeer
8 * Full author contact details are available in file CREDITS.
13 #include "insetbranch.h"
16 #include "bufferparams.h"
17 #include "BranchList.h"
19 #include "dispatchresult.h"
20 #include "funcrequest.h"
24 #include "paragraph.h"
26 #include "support/std_sstream.h"
30 using std::istringstream;
32 using std::ostringstream;
35 void InsetBranch::init()
37 setInsetName("Branch");
42 InsetBranch::InsetBranch(BufferParams const & bp,
43 InsetBranchParams const & params)
44 : InsetCollapsable(bp), params_(params)
50 InsetBranch::InsetBranch(InsetBranch const & in)
51 : InsetCollapsable(in), params_(in.params_)
57 InsetBranch::~InsetBranch()
59 InsetBranchMailer(*this).hideDialog();
63 auto_ptr<InsetBase> InsetBranch::clone() const
65 return auto_ptr<InsetBase>(new InsetBranch(*this));
69 string const InsetBranch::editMessage() const
71 return _("Opened Branch Inset");
75 void InsetBranch::write(Buffer const & buf, ostream & os) const
78 InsetCollapsable::write(buf, os);
82 void InsetBranch::read(Buffer const & buf, LyXLex & lex)
85 InsetCollapsable::read(buf, lex);
90 void InsetBranch::setButtonLabel()
92 LyXFont font(LyXFont::ALL_SANE);
96 setLabel("Branch: " + params_.branch);
97 font.setColor(LColor::foreground);
98 if (!params_.branch.empty())
99 setBackgroundColor(lcolor.getFromLyXName(params_.branch));
101 setBackgroundColor(LColor::background);
106 bool InsetBranch::showInsetDialog(BufferView * bv) const
108 InsetBranchMailer(const_cast<InsetBranch &>(*this)).showDialog(bv);
113 void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
115 switch (cmd.action) {
116 case LFUN_INSET_MODIFY: {
117 InsetBranchParams params;
118 InsetBranchMailer::string2params(cmd.argument, params);
119 params_.branch = params.branch;
124 case LFUN_MOUSE_PRESS:
125 if (cmd.button() != mouse_button::button3)
126 InsetCollapsable::priv_dispatch(cur, cmd);
131 case LFUN_INSET_DIALOG_UPDATE:
132 InsetBranchMailer(*this).updateDialog(&cur.bv());
135 case LFUN_MOUSE_RELEASE:
136 if (cmd.button() == mouse_button::button3 && hitButton(cmd))
137 InsetBranchMailer(*this).showDialog(&cur.bv());
139 InsetCollapsable::priv_dispatch(cur, cmd);
143 InsetCollapsable::priv_dispatch(cur, cmd);
149 bool InsetBranch::isBranchSelected(BranchList const & branchlist) const
151 BranchList::const_iterator const end = branchlist.end();
152 BranchList::const_iterator it =
153 std::find_if(branchlist.begin(), end,
154 BranchNamesEqual(params_.branch));
157 return it->getSelected();
161 int InsetBranch::latex(Buffer const & buf, ostream & os,
162 OutputParams const & runparams) const
164 return isBranchSelected(buf.params().branchlist()) ?
165 inset.latex(buf, os, runparams) : 0;
169 int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os,
170 OutputParams const & runparams) const
172 return isBranchSelected(buf.params().branchlist()) ?
173 inset.linuxdoc(buf, os, runparams) : 0;
177 int InsetBranch::docbook(Buffer const & buf, std::ostream & os,
178 OutputParams const & runparams) const
180 return isBranchSelected(buf.params().branchlist()) ?
181 inset.docbook(buf, os, runparams) : 0;
185 int InsetBranch::plaintext(Buffer const & buf, std::ostream & os,
186 OutputParams const & runparams) const
188 return isBranchSelected(buf.params().branchlist()) ?
189 inset.plaintext(buf, os, runparams): 0;
193 void InsetBranch::validate(LaTeXFeatures & features) const
195 inset.validate(features);
200 string const InsetBranchMailer:: name_("branch");
202 InsetBranchMailer::InsetBranchMailer(InsetBranch & inset)
207 string const InsetBranchMailer::inset2string(Buffer const &) const
209 return params2string(inset_.params());
213 string const InsetBranchMailer::params2string(InsetBranchParams const & params)
216 data << name_ << ' ';
222 void InsetBranchMailer::string2params(string const & in,
223 InsetBranchParams & params)
225 params = InsetBranchParams();
229 istringstream data(in);
236 return print_mailer_error("InsetBranchMailer", in, 1, name_);
238 // This is part of the inset proper that is usually swallowed
239 // by LyXText::readInset
242 if (!lex || id != "Branch")
243 return print_mailer_error("InsetBranchMailer", in, 2, "Branch");
249 void InsetBranchParams::write(ostream & os) const
251 os << "Branch " << branch << '\n';
255 void InsetBranchParams::read(LyXLex & lex)