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"
27 using std::istringstream;
29 using std::ostringstream;
32 void InsetBranch::init()
34 setInsetName("Branch");
39 InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
40 : InsetCollapsable(bp)
42 params_.branch = label;
43 // Hack: stash the list of all allowable branch labels from this
44 // buffer into inset's parm list as a "stowaway":
45 params_.branchlist = bp.branchlist();
50 InsetBranch::InsetBranch(InsetBranch const & in)
51 : InsetCollapsable(in), params_(in.params_)
57 InsetBranch::~InsetBranch()
59 InsetBranchMailer mailer("branch", *this);
64 auto_ptr<InsetBase> InsetBranch::clone() const
66 return auto_ptr<InsetBase>(new InsetBranch(*this));
70 string const InsetBranch::editMessage() const
72 return _("Opened Branch Inset");
76 void InsetBranch::write(Buffer const & buf, ostream & os) const
79 InsetCollapsable::write(buf, os);
83 void InsetBranch::read(Buffer const & buf, LyXLex & lex)
87 params_.branch = lex.getString();
89 InsetCollapsable::read(buf, lex);
94 void InsetBranch::setButtonLabel()
96 LyXFont font(LyXFont::ALL_SANE);
100 setLabel("Branch: " + params_.branch);
101 font.setColor(LColor::foreground);
102 if (!params_.branch.empty())
103 setBackgroundColor(lcolor.getFromLyXName(params_.branch));
105 setBackgroundColor(LColor::background);
110 bool InsetBranch::showInsetDialog(BufferView * bv) const
112 InsetBranchMailer("branch", const_cast<InsetBranch &>(*this)).showDialog(bv);
117 dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd)
119 BufferView * bv = cmd.view();
120 switch (cmd.action) {
121 case LFUN_INSET_MODIFY:
123 InsetBranchParams params;
124 InsetBranchMailer::string2params(cmd.argument, params);
125 params_.branch = params.branch;
127 bv->updateInset(this);
130 case LFUN_INSET_EDIT:
131 if (cmd.button() != mouse_button::button3)
132 return InsetCollapsable::localDispatch(cmd);
135 case LFUN_INSET_DIALOG_UPDATE:
136 InsetBranchMailer("branch", *this).updateDialog(bv);
138 case LFUN_MOUSE_RELEASE:
139 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
140 InsetBranchMailer("branch", *this).showDialog(bv);
145 return InsetCollapsable::localDispatch(cmd);
150 int InsetBranch::latex(Buffer const & buf, ostream & os,
151 LatexRunParams const & runparams) const
153 string const branch_sel = buf.params().branchlist().allSelected();
154 if (branch_sel.find(params_.branch, 0) != string::npos)
155 return inset.latex(buf, os, runparams);
160 int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os) const
162 string const branch_sel = buf.params().branchlist().allSelected();
163 if (branch_sel.find(params_.branch, 0) != string::npos)
164 return inset.linuxdoc(buf, os);
169 int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
171 string const branch_sel = buf.params().branchlist().allSelected();
172 if (branch_sel.find(params_.branch, 0) != string::npos)
173 return inset.docbook(buf, os, mixcont);
178 int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
180 string const branch_sel = buf.params().branchlist().allSelected();
181 if (branch_sel.find(params_.branch, 0) != string::npos) {
182 return inset.ascii(buf, os, ll);
188 void InsetBranch::validate(LaTeXFeatures & features) const
190 inset.validate(features);
195 InsetBranchMailer::InsetBranchMailer(string const & name,
197 : name_(name), inset_(inset)
202 string const InsetBranchMailer::inset2string(Buffer const & buf) const
204 InsetBranchParams params = inset_.params();
205 params.branchlist = buf.params().branchlist();
206 inset_.setParams(params);
207 return params2string(name_, params);
211 string const InsetBranchMailer::params2string(string const & name,
212 InsetBranchParams const & params)
217 // Add all_branches parameter to data:
218 data << params.branchlist.allBranches() << "\n";
223 void InsetBranchMailer::string2params(string const & in,
224 InsetBranchParams & params)
226 params = InsetBranchParams();
231 istringstream data(in);
235 // Process all_branches here:
238 params.branchlist.add(lex.getString());
243 void InsetBranchParams::write(ostream & os) const
245 os << "Branch" << " " << branch << "\n";
249 void InsetBranchParams::read(LyXLex & lex)
253 string token = lex.getString();
257 string token = lex.getString();
261 branch = lex.getString();