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"
18 #include "BufferView.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);
114 InsetBranch::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
116 switch (cmd.action) {
117 case LFUN_INSET_MODIFY: {
118 InsetBranchParams params;
119 InsetBranchMailer::string2params(cmd.argument, params);
120 params_.branch = params.branch;
122 return DispatchResult(true, true);
125 case LFUN_MOUSE_PRESS:
126 if (cmd.button() != mouse_button::button3)
127 return InsetCollapsable::priv_dispatch(bv, cmd);
128 return DispatchResult(false);
130 case LFUN_INSET_DIALOG_UPDATE:
131 InsetBranchMailer(*this).updateDialog(&bv);
132 return DispatchResult(true);
134 case LFUN_MOUSE_RELEASE:
135 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
136 InsetBranchMailer(*this).showDialog(&bv);
137 return DispatchResult(true);
139 return InsetCollapsable::priv_dispatch(bv, cmd);
142 return InsetCollapsable::priv_dispatch(bv, cmd);
147 bool InsetBranch::isBranchSelected(BranchList const & branchlist) const
149 BranchList::const_iterator const end = branchlist.end();
150 BranchList::const_iterator it =
151 std::find_if(branchlist.begin(), end,
152 BranchNamesEqual(params_.branch));
155 return it->getSelected();
159 int InsetBranch::latex(Buffer const & buf, ostream & os,
160 OutputParams const & runparams) const
162 return isBranchSelected(buf.params().branchlist()) ?
163 inset.latex(buf, os, runparams) : 0;
167 int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os,
168 OutputParams const & runparams) const
170 return isBranchSelected(buf.params().branchlist()) ?
171 inset.linuxdoc(buf, os, runparams) : 0;
175 int InsetBranch::docbook(Buffer const & buf, std::ostream & os,
176 OutputParams const & runparams) const
178 return isBranchSelected(buf.params().branchlist()) ?
179 inset.docbook(buf, os, runparams) : 0;
183 int InsetBranch::plaintext(Buffer const & buf, std::ostream & os,
184 OutputParams const & runparams) const
186 return isBranchSelected(buf.params().branchlist()) ?
187 inset.plaintext(buf, os, runparams): 0;
191 void InsetBranch::validate(LaTeXFeatures & features) const
193 inset.validate(features);
198 string const InsetBranchMailer:: name_("branch");
200 InsetBranchMailer::InsetBranchMailer(InsetBranch & inset)
205 string const InsetBranchMailer::inset2string(Buffer const &) const
207 return params2string(inset_.params());
211 string const InsetBranchMailer::params2string(InsetBranchParams const & params)
214 data << name_ << ' ';
220 void InsetBranchMailer::string2params(string const & in,
221 InsetBranchParams & params)
223 params = InsetBranchParams();
227 istringstream data(in);
234 return print_mailer_error("InsetBranchMailer", in, 1, name_);
236 // This is part of the inset proper that is usually swallowed
237 // by LyXText::readInset
240 if (!lex || id != "Branch")
241 return print_mailer_error("InsetBranchMailer", in, 2, "Branch");
247 void InsetBranchParams::write(ostream & os) const
249 os << "Branch " << branch << '\n';
253 void InsetBranchParams::read(LyXLex & lex)