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 "BufferView.h"
17 #include "funcrequest.h"
27 void InsetBranch::init()
29 setInsetName("Branch");
33 InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
34 : InsetCollapsable(bp)
36 params_.branch = label;
37 // Hack: stash the list of all allowable branch labels from this
38 // buffer into inset's parm list as a "stowaway":
39 params_.branchlist = bp.branchlist;
44 InsetBranch::InsetBranch(InsetBranch const & in)
45 : InsetCollapsable(in), params_(in.params_)
51 InsetBranch::~InsetBranch()
53 InsetBranchMailer mailer("branch", *this);
58 auto_ptr<InsetBase> InsetBranch::clone() const
60 return auto_ptr<InsetBase>(new InsetBranch(*this));
64 string const InsetBranch::editMessage() const
66 return _("Opened Branch Inset");
70 void InsetBranch::write(Buffer const & buf, ostream & os) const
73 InsetCollapsable::write(buf, os);
77 void InsetBranch::read(Buffer const & buf, LyXLex & lex)
81 params_.branch = lex.getString();
83 InsetCollapsable::read(buf, lex);
88 void InsetBranch::setButtonLabel()
90 LyXFont font(LyXFont::ALL_SANE);
94 setLabel("Branch: " + params_.branch);
95 font.setColor(LColor::foreground);
96 string const color = params_.branchlist.getColor(params_.branch);
98 setBackgroundColor(lcolor.getFromLyXName(params_.branch));
100 setBackgroundColor(LColor::background);
105 bool InsetBranch::showInsetDialog(BufferView * bv) const
107 InsetBranchMailer("branch", const_cast<InsetBranch &>(*this)).showDialog(bv);
112 dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd)
114 BufferView * bv = cmd.view();
115 switch (cmd.action) {
116 case LFUN_INSET_MODIFY:
118 InsetBranchParams params;
119 InsetBranchMailer::string2params(cmd.argument, params);
120 params_.branch = params.branch;
122 bv->updateInset(this);
125 case LFUN_INSET_EDIT:
126 if (cmd.button() != mouse_button::button3)
127 return InsetCollapsable::localDispatch(cmd);
130 case LFUN_INSET_DIALOG_UPDATE:
131 InsetBranchMailer("branch", *this).updateDialog(bv);
133 case LFUN_MOUSE_RELEASE:
134 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
135 InsetBranchMailer("branch", *this).showDialog(bv);
140 return InsetCollapsable::localDispatch(cmd);
145 int InsetBranch::latex(Buffer const & buf, ostream & os,
146 LatexRunParams const & runparams) const
148 string const branch_sel = buf.params.branchlist.allSelected();
149 if (branch_sel.find(params_.branch, 0) != string::npos)
150 return inset.latex(buf, os, runparams);
155 int InsetBranch::linuxdoc(Buffer const &, std::ostream &) const
161 int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
164 string const branch_sel = buf.params.branchlist.allSelected();
165 if (branch_sel.find(params_.branch, 0) != string::npos)
166 return inset.docbook(buf, os, mixcont);
171 int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
173 string const branch_sel = buf.params.branchlist.allSelected();
174 if (branch_sel.find(params_.branch, 0) != string::npos) {
175 return inset.ascii(buf, os, ll);
181 void InsetBranch::validate(LaTeXFeatures & features) const
183 inset.validate(features);
188 InsetBranchMailer::InsetBranchMailer(string const & name,
190 : name_(name), inset_(inset)
195 string const InsetBranchMailer::inset2string(Buffer const & buf) const
197 InsetBranchParams params = inset_.params();
198 params.branchlist = buf.params.branchlist;
199 inset_.setParams(params);
200 return params2string(name_, params);
204 string const InsetBranchMailer::params2string(string const & name,
205 InsetBranchParams const & params)
210 // Add all_branches parameter to data:
211 data << params.branchlist.allBranches() << "\n";
212 return STRCONV(data.str());
216 void InsetBranchMailer::string2params(string const & in,
217 InsetBranchParams & params)
219 params = InsetBranchParams();
224 istringstream data(STRCONV(in));
228 // Process all_branches here:
231 params.branchlist.add(lex.getString());
236 void InsetBranchParams::write(ostream & os) const
238 os << "Branch" << " " << branch << "\n";
242 void InsetBranchParams::read(LyXLex & lex)
246 string token = lex.getString();
250 string token = lex.getString();
254 branch = lex.getString();