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"
21 #include "support/std_sstream.h"
24 using std::istringstream;
26 using std::ostringstream;
29 void InsetBranch::init()
31 setInsetName("Branch");
35 InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
36 : InsetCollapsable(bp)
38 params_.branch = label;
39 // Hack: stash the list of all allowable branch labels from this
40 // buffer into inset's parm list as a "stowaway":
41 params_.branchlist = bp.branchlist;
46 InsetBranch::InsetBranch(InsetBranch const & in)
47 : InsetCollapsable(in), params_(in.params_)
53 InsetBranch::~InsetBranch()
55 InsetBranchMailer mailer("branch", *this);
60 auto_ptr<InsetBase> InsetBranch::clone() const
62 return auto_ptr<InsetBase>(new InsetBranch(*this));
66 string const InsetBranch::editMessage() const
68 return _("Opened Branch Inset");
72 void InsetBranch::write(Buffer const & buf, ostream & os) const
75 InsetCollapsable::write(buf, os);
79 void InsetBranch::read(Buffer const & buf, LyXLex & lex)
83 params_.branch = lex.getString();
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 string const color = params_.branchlist.getColor(params_.branch);
100 setBackgroundColor(lcolor.getFromLyXName(params_.branch));
102 setBackgroundColor(LColor::background);
107 bool InsetBranch::showInsetDialog(BufferView * bv) const
109 InsetBranchMailer("branch", const_cast<InsetBranch &>(*this)).showDialog(bv);
114 dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd)
116 BufferView * bv = cmd.view();
117 switch (cmd.action) {
118 case LFUN_INSET_MODIFY:
120 InsetBranchParams params;
121 InsetBranchMailer::string2params(cmd.argument, params);
122 params_.branch = params.branch;
124 bv->updateInset(this);
127 case LFUN_INSET_EDIT:
128 if (cmd.button() != mouse_button::button3)
129 return InsetCollapsable::localDispatch(cmd);
132 case LFUN_INSET_DIALOG_UPDATE:
133 InsetBranchMailer("branch", *this).updateDialog(bv);
135 case LFUN_MOUSE_RELEASE:
136 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
137 InsetBranchMailer("branch", *this).showDialog(bv);
142 return InsetCollapsable::localDispatch(cmd);
147 int InsetBranch::latex(Buffer const & buf, ostream & os,
148 LatexRunParams const & runparams) const
150 string const branch_sel = buf.params.branchlist.allSelected();
151 if (branch_sel.find(params_.branch, 0) != string::npos)
152 return inset.latex(buf, os, runparams);
157 int InsetBranch::linuxdoc(Buffer const &, std::ostream &) const
163 int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
166 string const branch_sel = buf.params.branchlist.allSelected();
167 if (branch_sel.find(params_.branch, 0) != string::npos)
168 return inset.docbook(buf, os, mixcont);
173 int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
175 string const branch_sel = buf.params.branchlist.allSelected();
176 if (branch_sel.find(params_.branch, 0) != string::npos) {
177 return inset.ascii(buf, os, ll);
183 void InsetBranch::validate(LaTeXFeatures & features) const
185 inset.validate(features);
190 InsetBranchMailer::InsetBranchMailer(string const & name,
192 : name_(name), inset_(inset)
197 string const InsetBranchMailer::inset2string(Buffer const & buf) const
199 InsetBranchParams params = inset_.params();
200 params.branchlist = buf.params.branchlist;
201 inset_.setParams(params);
202 return params2string(name_, params);
206 string const InsetBranchMailer::params2string(string const & name,
207 InsetBranchParams const & params)
212 // Add all_branches parameter to data:
213 data << params.branchlist.allBranches() << "\n";
214 return STRCONV(data.str());
218 void InsetBranchMailer::string2params(string const & in,
219 InsetBranchParams & params)
221 params = InsetBranchParams();
226 istringstream data(STRCONV(in));
230 // Process all_branches here:
233 params.branchlist.add(lex.getString());
238 void InsetBranchParams::write(ostream & os) const
240 os << "Branch" << " " << branch << "\n";
244 void InsetBranchParams::read(LyXLex & lex)
248 string token = lex.getString();
252 string token = lex.getString();
256 branch = lex.getString();