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"
20 #include "paragraph.h"
22 #include "support/std_sstream.h"
25 using std::istringstream;
27 using std::ostringstream;
30 void InsetBranch::init()
32 setInsetName("Branch");
36 InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
37 : InsetCollapsable(bp)
39 params_.branch = label;
40 // Hack: stash the list of all allowable branch labels from this
41 // buffer into inset's parm list as a "stowaway":
42 params_.branchlist = bp.branchlist;
47 InsetBranch::InsetBranch(InsetBranch const & in)
48 : InsetCollapsable(in), params_(in.params_)
54 InsetBranch::~InsetBranch()
56 InsetBranchMailer mailer("branch", *this);
61 auto_ptr<InsetBase> InsetBranch::clone() const
63 return auto_ptr<InsetBase>(new InsetBranch(*this));
67 string const InsetBranch::editMessage() const
69 return _("Opened Branch Inset");
73 void InsetBranch::write(Buffer const & buf, ostream & os) const
76 InsetCollapsable::write(buf, os);
80 void InsetBranch::read(Buffer const & buf, LyXLex & lex)
84 params_.branch = lex.getString();
86 InsetCollapsable::read(buf, lex);
91 void InsetBranch::setButtonLabel()
93 LyXFont font(LyXFont::ALL_SANE);
97 setLabel("Branch: " + params_.branch);
98 font.setColor(LColor::foreground);
99 string const color = params_.branchlist.getColor(params_.branch);
100 if (!color.empty()) {
101 setBackgroundColor(lcolor.getFromLyXName(params_.branch));
103 setBackgroundColor(LColor::background);
108 bool InsetBranch::showInsetDialog(BufferView * bv) const
110 InsetBranchMailer("branch", const_cast<InsetBranch &>(*this)).showDialog(bv);
115 dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd)
117 BufferView * bv = cmd.view();
118 switch (cmd.action) {
119 case LFUN_INSET_MODIFY:
121 InsetBranchParams params;
122 InsetBranchMailer::string2params(cmd.argument, params);
123 params_.branch = params.branch;
125 bv->updateInset(this);
128 case LFUN_INSET_EDIT:
129 if (cmd.button() != mouse_button::button3)
130 return InsetCollapsable::localDispatch(cmd);
133 case LFUN_INSET_DIALOG_UPDATE:
134 InsetBranchMailer("branch", *this).updateDialog(bv);
136 case LFUN_MOUSE_RELEASE:
137 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
138 InsetBranchMailer("branch", *this).showDialog(bv);
143 return InsetCollapsable::localDispatch(cmd);
148 int InsetBranch::latex(Buffer const & buf, ostream & os,
149 LatexRunParams const & runparams) const
151 string const branch_sel = buf.params().branchlist.allSelected();
152 if (branch_sel.find(params_.branch, 0) != string::npos)
153 return inset.latex(buf, os, runparams);
158 int InsetBranch::linuxdoc(Buffer const &, std::ostream &) const
164 int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
167 string const branch_sel = buf.params().branchlist.allSelected();
168 if (branch_sel.find(params_.branch, 0) != string::npos)
169 return inset.docbook(buf, os, mixcont);
174 int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
176 string const branch_sel = buf.params().branchlist.allSelected();
177 if (branch_sel.find(params_.branch, 0) != string::npos) {
178 return inset.ascii(buf, os, ll);
184 void InsetBranch::validate(LaTeXFeatures & features) const
186 inset.validate(features);
191 InsetBranchMailer::InsetBranchMailer(string const & name,
193 : name_(name), inset_(inset)
198 string const InsetBranchMailer::inset2string(Buffer const & buf) const
200 InsetBranchParams params = inset_.params();
201 params.branchlist = buf.params().branchlist;
202 inset_.setParams(params);
203 return params2string(name_, params);
207 string const InsetBranchMailer::params2string(string const & name,
208 InsetBranchParams const & params)
213 // Add all_branches parameter to data:
214 data << params.branchlist.allBranches() << "\n";
215 return STRCONV(data.str());
219 void InsetBranchMailer::string2params(string const & in,
220 InsetBranchParams & params)
222 params = InsetBranchParams();
227 istringstream data(STRCONV(in));
231 // Process all_branches here:
234 params.branchlist.add(lex.getString());
239 void InsetBranchParams::write(ostream & os) const
241 os << "Branch" << " " << branch << "\n";
245 void InsetBranchParams::read(LyXLex & lex)
249 string token = lex.getString();
253 string token = lex.getString();
257 branch = lex.getString();