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"
22 #include "paragraph.h"
24 #include "support/std_sstream.h"
29 using std::istringstream;
31 using std::ostringstream;
34 void InsetBranch::init()
36 setInsetName("Branch");
41 InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
42 : InsetCollapsable(bp)
44 params_.branch = label;
45 // Hack: stash the list of all allowable branch labels from this
46 // buffer into inset's parm list as a "stowaway":
47 params_.branchlist = bp.branchlist();
52 InsetBranch::InsetBranch(InsetBranch const & in)
53 : InsetCollapsable(in), params_(in.params_)
59 InsetBranch::~InsetBranch()
61 InsetBranchMailer mailer("branch", *this);
66 auto_ptr<InsetBase> InsetBranch::clone() const
68 return auto_ptr<InsetBase>(new InsetBranch(*this));
72 string const InsetBranch::editMessage() const
74 return _("Opened Branch Inset");
78 void InsetBranch::write(Buffer const & buf, ostream & os) const
81 InsetCollapsable::write(buf, os);
85 void InsetBranch::read(Buffer const & buf, LyXLex & lex)
89 params_.branch = lex.getString();
91 InsetCollapsable::read(buf, lex);
96 void InsetBranch::setButtonLabel()
98 LyXFont font(LyXFont::ALL_SANE);
102 setLabel("Branch: " + params_.branch);
103 font.setColor(LColor::foreground);
104 if (!params_.branch.empty())
105 setBackgroundColor(lcolor.getFromLyXName(params_.branch));
107 setBackgroundColor(LColor::background);
112 bool InsetBranch::showInsetDialog(BufferView * bv) const
114 InsetBranchMailer("branch", const_cast<InsetBranch &>(*this)).showDialog(bv);
120 InsetBranch::priv_dispatch(FuncRequest const & cmd,
121 idx_type & idx, pos_type & pos)
123 BufferView * bv = cmd.view();
124 switch (cmd.action) {
125 case LFUN_INSET_MODIFY:
127 InsetBranchParams params;
128 InsetBranchMailer::string2params(cmd.argument, params);
129 params_.branch = params.branch;
131 bv->updateInset(this);
134 case LFUN_INSET_EDIT:
135 if (cmd.button() != mouse_button::button3)
136 return InsetCollapsable::priv_dispatch(cmd, idx, pos);
139 case LFUN_INSET_DIALOG_UPDATE:
140 InsetBranchMailer("branch", *this).updateDialog(bv);
142 case LFUN_MOUSE_RELEASE:
143 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
144 InsetBranchMailer("branch", *this).showDialog(bv);
149 return InsetCollapsable::priv_dispatch(cmd, idx, pos);
154 int InsetBranch::latex(Buffer const & buf, ostream & os,
155 LatexRunParams const & runparams) const
157 string const branch_sel = buf.params().branchlist().allSelected();
158 if (branch_sel.find(params_.branch, 0) != string::npos)
159 return inset.latex(buf, os, runparams);
164 int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os) const
166 string const branch_sel = buf.params().branchlist().allSelected();
167 if (branch_sel.find(params_.branch, 0) != string::npos)
168 return inset.linuxdoc(buf, os);
173 int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
175 string const branch_sel = buf.params().branchlist().allSelected();
176 if (branch_sel.find(params_.branch, 0) != string::npos)
177 return inset.docbook(buf, os, mixcont);
182 int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
184 string const branch_sel = buf.params().branchlist().allSelected();
185 if (branch_sel.find(params_.branch, 0) != string::npos) {
186 return inset.ascii(buf, os, ll);
192 void InsetBranch::validate(LaTeXFeatures & features) const
194 inset.validate(features);
199 InsetBranchMailer::InsetBranchMailer(string const & name,
201 : name_(name), inset_(inset)
206 string const InsetBranchMailer::inset2string(Buffer const & buf) const
208 InsetBranchParams params = inset_.params();
209 params.branchlist = buf.params().branchlist();
210 inset_.setParams(params);
211 return params2string(name_, params);
215 string const InsetBranchMailer::params2string(string const & name,
216 InsetBranchParams const & params)
221 // Add all_branches parameter to data:
222 data << params.branchlist.allBranches() << "\n";
227 void InsetBranchMailer::string2params(string const & in,
228 InsetBranchParams & params)
230 params = InsetBranchParams();
235 istringstream data(in);
239 // Process all_branches here:
242 params.branchlist.add(lex.getString());
247 void InsetBranchParams::write(ostream & os) const
249 os << "Branch" << " " << branch << "\n";
253 void InsetBranchParams::read(LyXLex & lex)
257 string token = lex.getString();
261 string token = lex.getString();
265 branch = lex.getString();