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 "BufferView.h"
18 #include "funcrequest.h"
21 #include "paragraph.h"
23 #include "support/std_sstream.h"
26 using std::istringstream;
28 using std::ostringstream;
31 void InsetBranch::init()
33 setInsetName("Branch");
37 InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
38 : InsetCollapsable(bp)
40 params_.branch = label;
41 // Hack: stash the list of all allowable branch labels from this
42 // buffer into inset's parm list as a "stowaway":
43 params_.branchlist = bp.branchlist();
48 InsetBranch::InsetBranch(InsetBranch const & in)
49 : InsetCollapsable(in), params_(in.params_)
55 InsetBranch::~InsetBranch()
57 InsetBranchMailer mailer("branch", *this);
62 auto_ptr<InsetBase> InsetBranch::clone() const
64 return auto_ptr<InsetBase>(new InsetBranch(*this));
68 string const InsetBranch::editMessage() const
70 return _("Opened Branch Inset");
74 void InsetBranch::write(Buffer const & buf, ostream & os) const
77 InsetCollapsable::write(buf, os);
81 void InsetBranch::read(Buffer const & buf, LyXLex & lex)
85 params_.branch = lex.getString();
87 InsetCollapsable::read(buf, lex);
92 void InsetBranch::setButtonLabel()
94 LyXFont font(LyXFont::ALL_SANE);
98 setLabel("Branch: " + params_.branch);
99 font.setColor(LColor::foreground);
100 string const color = params_.branchlist.getColor(params_.branch);
101 if (!color.empty()) {
102 setBackgroundColor(lcolor.getFromLyXName(params_.branch));
104 setBackgroundColor(LColor::background);
109 bool InsetBranch::showInsetDialog(BufferView * bv) const
111 InsetBranchMailer("branch", const_cast<InsetBranch &>(*this)).showDialog(bv);
116 dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd)
118 BufferView * bv = cmd.view();
119 switch (cmd.action) {
120 case LFUN_INSET_MODIFY:
122 InsetBranchParams params;
123 InsetBranchMailer::string2params(cmd.argument, params);
124 params_.branch = params.branch;
126 bv->updateInset(this);
129 case LFUN_INSET_EDIT:
130 if (cmd.button() != mouse_button::button3)
131 return InsetCollapsable::localDispatch(cmd);
134 case LFUN_INSET_DIALOG_UPDATE:
135 InsetBranchMailer("branch", *this).updateDialog(bv);
137 case LFUN_MOUSE_RELEASE:
138 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
139 InsetBranchMailer("branch", *this).showDialog(bv);
144 return InsetCollapsable::localDispatch(cmd);
149 int InsetBranch::latex(Buffer const & buf, ostream & os,
150 LatexRunParams const & runparams) const
152 string const branch_sel = buf.params().branchlist().allSelected();
153 if (branch_sel.find(params_.branch, 0) != string::npos)
154 return inset.latex(buf, os, runparams);
159 int InsetBranch::linuxdoc(Buffer const &, std::ostream &) const
165 int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
168 string const branch_sel = buf.params().branchlist().allSelected();
169 if (branch_sel.find(params_.branch, 0) != string::npos)
170 return inset.docbook(buf, os, mixcont);
175 int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
177 string const branch_sel = buf.params().branchlist().allSelected();
178 if (branch_sel.find(params_.branch, 0) != string::npos) {
179 return inset.ascii(buf, os, ll);
185 void InsetBranch::validate(LaTeXFeatures & features) const
187 inset.validate(features);
192 InsetBranchMailer::InsetBranchMailer(string const & name,
194 : name_(name), inset_(inset)
199 string const InsetBranchMailer::inset2string(Buffer const & buf) const
201 InsetBranchParams params = inset_.params();
202 params.branchlist = buf.params().branchlist();
203 inset_.setParams(params);
204 return params2string(name_, params);
208 string const InsetBranchMailer::params2string(string const & name,
209 InsetBranchParams const & params)
214 // Add all_branches parameter to data:
215 data << params.branchlist.allBranches() << "\n";
216 return STRCONV(data.str());
220 void InsetBranchMailer::string2params(string const & in,
221 InsetBranchParams & params)
223 params = InsetBranchParams();
228 istringstream data(STRCONV(in));
232 // Process all_branches here:
235 params.branchlist.add(lex.getString());
240 void InsetBranchParams::write(ostream & os) const
242 os << "Branch" << " " << branch << "\n";
246 void InsetBranchParams::read(LyXLex & lex)
250 string token = lex.getString();
254 string token = lex.getString();
258 branch = lex.getString();