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);
119 dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd)
121 BufferView * bv = cmd.view();
122 switch (cmd.action) {
123 case LFUN_INSET_MODIFY:
125 InsetBranchParams params;
126 InsetBranchMailer::string2params(cmd.argument, params);
127 params_.branch = params.branch;
129 bv->updateInset(this);
132 case LFUN_INSET_EDIT:
133 if (cmd.button() != mouse_button::button3)
134 return InsetCollapsable::localDispatch(cmd);
137 case LFUN_INSET_DIALOG_UPDATE:
138 InsetBranchMailer("branch", *this).updateDialog(bv);
140 case LFUN_MOUSE_RELEASE:
141 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
142 InsetBranchMailer("branch", *this).showDialog(bv);
147 return InsetCollapsable::localDispatch(cmd);
152 int InsetBranch::latex(Buffer const & buf, ostream & os,
153 LatexRunParams const & runparams) const
155 string const branch_sel = buf.params().branchlist().allSelected();
156 if (branch_sel.find(params_.branch, 0) != string::npos)
157 return inset.latex(buf, os, runparams);
162 int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os) const
164 string const branch_sel = buf.params().branchlist().allSelected();
165 if (branch_sel.find(params_.branch, 0) != string::npos)
166 return inset.linuxdoc(buf, os);
171 int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
173 string const branch_sel = buf.params().branchlist().allSelected();
174 if (branch_sel.find(params_.branch, 0) != string::npos)
175 return inset.docbook(buf, os, mixcont);
180 int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
182 string const branch_sel = buf.params().branchlist().allSelected();
183 if (branch_sel.find(params_.branch, 0) != string::npos) {
184 return inset.ascii(buf, os, ll);
190 void InsetBranch::validate(LaTeXFeatures & features) const
192 inset.validate(features);
197 InsetBranchMailer::InsetBranchMailer(string const & name,
199 : name_(name), inset_(inset)
204 string const InsetBranchMailer::inset2string(Buffer const & buf) const
206 InsetBranchParams params = inset_.params();
207 params.branchlist = buf.params().branchlist();
208 inset_.setParams(params);
209 return params2string(name_, params);
213 string const InsetBranchMailer::params2string(string const & name,
214 InsetBranchParams const & params)
219 // Add all_branches parameter to data:
220 data << params.branchlist.allBranches() << "\n";
225 void InsetBranchMailer::string2params(string const & in,
226 InsetBranchParams & params)
228 params = InsetBranchParams();
233 istringstream data(in);
237 // Process all_branches here:
240 params.branchlist.add(lex.getString());
245 void InsetBranchParams::write(ostream & os) const
247 os << "Branch" << " " << branch << "\n";
251 void InsetBranchParams::read(LyXLex & lex)
255 string token = lex.getString();
259 string token = lex.getString();
263 branch = lex.getString();