#include "buffer.h"
#include "bufferparams.h"
#include "BranchList.h"
-#include "BufferView.h"
+#include "cursor.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "gettext.h"
#include "lyxlex.h"
#include "paragraph.h"
-#include "support/std_sstream.h"
-
+#include <sstream>
using std::string;
using std::auto_ptr;
font.decSize();
font.decSize();
- setLabel("Branch: " + params_.branch);
+ string s = "Branch: " + params_.branch;
+ setLabel(isOpen() ? s : getNewLabel(s) );
font.setColor(LColor::foreground);
if (!params_.branch.empty())
setBackgroundColor(lcolor.getFromLyXName(params_.branch));
}
-DispatchResult
-InsetBranch::priv_dispatch(FuncRequest const & cmd,
- idx_type & idx, pos_type & pos)
+void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd)
{
- BufferView * bv = cmd.view();
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetBranchParams params;
InsetBranchMailer::string2params(cmd.argument, params);
params_.branch = params.branch;
setButtonLabel();
- return DispatchResult(true, true);
+ break;
}
case LFUN_MOUSE_PRESS:
if (cmd.button() != mouse_button::button3)
- return InsetCollapsable::priv_dispatch(cmd, idx, pos);
- return DispatchResult(false);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ else
+ cur.undispatched();
+ break;
case LFUN_INSET_DIALOG_UPDATE:
- InsetBranchMailer(*this).updateDialog(bv);
- return DispatchResult(true);
+ InsetBranchMailer(*this).updateDialog(&cur.bv());
+ break;
case LFUN_MOUSE_RELEASE:
- if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
- InsetBranchMailer(*this).showDialog(bv);
- return DispatchResult(true);
+ if (cmd.button() == mouse_button::button3 && hitButton(cmd))
+ InsetBranchMailer(*this).showDialog(&cur.bv());
+ else
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
+
+
+ case LFUN_INSET_TOGGLE:
+ // We assume that this lfun is indeed going to be dispatched.
+ cur.dispatched();
+
+ if (cmd.argument == "open")
+ setStatus(Open);
+ else if (cmd.argument == "close") {
+ setStatus(Collapsed);
+ leaveInset(cur, *this);
+ } else if (cmd.argument == "toggle") {
+ if (isOpen()) {
+ setStatus(Collapsed);
+ leaveInset(cur, *this);
+ } else
+ setStatus(Open);
+
+ // The branch inset uses "assign".
+ } else if (cmd.argument == "assign"
+ || cmd.argument.empty()) {
+ BranchList const & branchlist =
+ cur.buffer().params().branchlist();
+ if (isBranchSelected(branchlist)) {
+ if (status() != Open)
+ setStatus(Open);
+ else
+ cur.undispatched();
+ } else {
+ if (status() != Collapsed) {
+ setStatus(Collapsed);
+ leaveInset(cur, *this);
+ } else
+ cur.undispatched();
+ }
}
- return InsetCollapsable::priv_dispatch(cmd, idx, pos);
-
+ break;
+
default:
- return InsetCollapsable::priv_dispatch(cmd, idx, pos);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
}
}
-namespace {
-
-struct SameBranch {
- SameBranch(string const & branch_name) : bn(branch_name) {}
- bool operator()(Branch const & branch) const
- { return bn == branch.getBranch(); }
-private:
- string bn;
-};
-
-} // namespace anon
-
-
bool InsetBranch::isBranchSelected(BranchList const & branchlist) const
{
- BranchList::const_iterator it = branchlist.begin();
BranchList::const_iterator const end = branchlist.end();
- it = std::find_if(it, end, SameBranch(params_.branch));
+ BranchList::const_iterator it =
+ std::find_if(branchlist.begin(), end,
+ BranchNamesEqual(params_.branch));
if (it == end)
return false;
return it->getSelected();
OutputParams const & runparams) const
{
return isBranchSelected(buf.params().branchlist()) ?
- inset.latex(buf, os, runparams) : 0;
+ InsetText::latex(buf, os, runparams) : 0;
}
OutputParams const & runparams) const
{
return isBranchSelected(buf.params().branchlist()) ?
- inset.linuxdoc(buf, os, runparams) : 0;
+ InsetText::linuxdoc(buf, os, runparams) : 0;
}
OutputParams const & runparams) const
{
return isBranchSelected(buf.params().branchlist()) ?
- inset.docbook(buf, os, runparams) : 0;
+ InsetText::docbook(buf, os, runparams) : 0;
}
OutputParams const & runparams) const
{
return isBranchSelected(buf.params().branchlist()) ?
- inset.plaintext(buf, os, runparams): 0;
+ InsetText::plaintext(buf, os, runparams): 0;
}
void InsetBranch::validate(LaTeXFeatures & features) const
{
- inset.validate(features);
+ InsetText::validate(features);
}
-string const InsetBranchMailer:: name_("branch");
+string const InsetBranchMailer::name_("branch");
InsetBranchMailer::InsetBranchMailer(InsetBranch & inset)
: inset_(inset)