Extend the branch-(de)activate functions to work without a parameter. In

this case, when the cursor is on a branch inset (using the AtPoint mechanism)
the branch to which the branch inset belongs will be (de)activated.

This functionality can now be used through the branch inset context menu



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28987 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2009-03-31 09:38:07 +00:00
parent f5a3bd7c37
commit 6c422712e1
6 changed files with 58 additions and 10 deletions

View File

@ -398,4 +398,19 @@ Menuset
Item "Settings...|S" "inset-settings info" Item "Settings...|S" "inset-settings info"
End End
#
# InsetBranch context menu
#
Menu "context-branch"
OptItem "Open Inset|O" "inset-toggle open"
OptItem "Close Inset|C" "inset-toggle close"
Separator
OptItem "Activate Branch|A" "branch-activate"
OptItem "Deactivate Branch|e" "branch-deactivate"
Separator
Item "Dissolve Inset|D" "inset-dissolve"
OptItem "Settings...|S" "inset-settings"
End
End End

View File

@ -1497,6 +1497,11 @@ bool Buffer::dispatch(FuncRequest const & func, bool * result)
case LFUN_BRANCH_DEACTIVATE: { case LFUN_BRANCH_DEACTIVATE: {
BranchList & branchList = params().branchlist(); BranchList & branchList = params().branchlist();
docstring const branchName = func.argument(); docstring const branchName = func.argument();
// the case without a branch name is handled elsewhere
if (branchName.empty()) {
dispatched = false;
break;
}
Branch * branch = branchList.find(branchName); Branch * branch = branchList.find(branchName);
if (!branch) if (!branch)
LYXERR0("Branch " << branchName << " does not exist."); LYXERR0("Branch " << branchName << " does not exist.");

View File

@ -1059,11 +1059,10 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
case LFUN_BRANCH_ACTIVATE: case LFUN_BRANCH_ACTIVATE:
case LFUN_BRANCH_DEACTIVATE: { case LFUN_BRANCH_DEACTIVATE: {
bool enable = false; BranchList const & branchList = buffer_.params().branchlist();
docstring const branchName = cmd.argument(); docstring const branchName = cmd.argument();
if (!branchName.empty()) flag.setEnabled(!branchName.empty()
enable = buffer_.params().branchlist().find(branchName); && branchList.find(branchName));
flag.setEnabled(enable);
break; break;
} }
@ -1502,6 +1501,8 @@ bool BufferView::dispatch(FuncRequest const & cmd)
case LFUN_BRANCH_ACTIVATE: case LFUN_BRANCH_ACTIVATE:
case LFUN_BRANCH_DEACTIVATE: case LFUN_BRANCH_DEACTIVATE:
if (cmd.argument().empty())
return false;
buffer_.dispatch(cmd); buffer_.dispatch(cmd);
processUpdateFlags(Update::Force); processUpdateFlags(Update::Force);
break; break;

View File

@ -3184,7 +3184,7 @@ void LyXAction::init()
* \li Origin: rgh, 27 May 2008 * \li Origin: rgh, 27 May 2008
* \endvar * \endvar
*/ */
{ LFUN_BRANCH_ACTIVATE, "branch-activate", Argument, Buffer }, { LFUN_BRANCH_ACTIVATE, "branch-activate", AtPoint, Buffer },
/*! /*!
* \var lyx::FuncCode lyx::LFUN_BRANCH_DEACTIVATE * \var lyx::FuncCode lyx::LFUN_BRANCH_DEACTIVATE
* \li Action: De-activate the branch * \li Action: De-activate the branch
@ -3193,7 +3193,7 @@ void LyXAction::init()
* \li Origin: rgh, 27 May 2008 * \li Origin: rgh, 27 May 2008
* \endvar * \endvar
*/ */
{ LFUN_BRANCH_DEACTIVATE, "branch-deactivate", Argument, Buffer }, { LFUN_BRANCH_DEACTIVATE, "branch-deactivate", AtPoint, Buffer },
/*! /*!
* \var lyx::FuncCode lyx::LFUN_COPY_LABEL_AS_REF * \var lyx::FuncCode lyx::LFUN_COPY_LABEL_AS_REF

View File

@ -143,6 +143,18 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.bv().updateDialog("branch", params2string(params())); cur.bv().updateDialog("branch", params2string(params()));
break; break;
case LFUN_BRANCH_ACTIVATE:
case LFUN_BRANCH_DEACTIVATE: {
// FIXME: I do not like this cast, but have no other idea...
Buffer * realbuffer = const_cast<Buffer *>(buffer().masterBuffer());
BranchList & branchlist = realbuffer->params().branchlist();
Branch * ourBranch = branchlist.find(params_.branch);
if (!ourBranch)
break;
ourBranch->setSelected(cmd.action == LFUN_BRANCH_ACTIVATE);
break;
}
case LFUN_INSET_TOGGLE: case LFUN_INSET_TOGGLE:
if (cmd.argument() == "assign") if (cmd.argument() == "assign")
setStatus(cur, isBranchSelected() ? Open : Collapsed); setStatus(cur, isBranchSelected() ? Open : Collapsed);
@ -166,12 +178,19 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.setEnabled(true); flag.setEnabled(true);
break; break;
case LFUN_BRANCH_ACTIVATE:
flag.setEnabled(!isBranchSelected());
break;
case LFUN_BRANCH_DEACTIVATE:
flag.setEnabled(isBranchSelected());
break;
case LFUN_INSET_TOGGLE: case LFUN_INSET_TOGGLE:
if (cmd.argument() == "assign") { if (cmd.argument() == "assign")
flag.setEnabled(true); flag.setEnabled(true);
break; else
} return InsetCollapsable::getStatus(cur, cmd, flag);
//fall through to generic InsetCollapsable implmementation
default: default:
return InsetCollapsable::getStatus(cur, cmd, flag); return InsetCollapsable::getStatus(cur, cmd, flag);
@ -232,6 +251,12 @@ void InsetBranch::validate(LaTeXFeatures & features) const
} }
docstring InsetBranch::contextMenu(BufferView const &, int, int) const
{
return from_ascii("context-branch");
}
bool InsetBranch::isMacroScope() const bool InsetBranch::isMacroScope() const
{ {
// Its own scope if not selected by buffer // Its own scope if not selected by buffer

View File

@ -78,6 +78,8 @@ private:
/// ///
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
/// ///
docstring contextMenu(BufferView const &, int, int) const;
///
void addToToc(DocIterator const &); void addToToc(DocIterator const &);
/// ///
InsetBranchParams const & params() const { return params_; } InsetBranchParams const & params() const { return params_; }