From 6c422712e165e39d497ffecf287caeb77f3e663f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 31 Mar 2009 09:38:07 +0000 Subject: [PATCH] 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 --- lib/ui/stdcontext.inc | 15 +++++++++++++++ src/Buffer.cpp | 5 +++++ src/BufferView.cpp | 9 +++++---- src/LyXAction.cpp | 4 ++-- src/insets/InsetBranch.cpp | 33 +++++++++++++++++++++++++++++---- src/insets/InsetBranch.h | 2 ++ 6 files changed, 58 insertions(+), 10 deletions(-) diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 82c85e3de8..552d54b115 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -398,4 +398,19 @@ Menuset Item "Settings...|S" "inset-settings info" 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 diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 3cd53dd1ba..e1d43097ed 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1497,6 +1497,11 @@ bool Buffer::dispatch(FuncRequest const & func, bool * result) case LFUN_BRANCH_DEACTIVATE: { BranchList & branchList = params().branchlist(); 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); if (!branch) LYXERR0("Branch " << branchName << " does not exist."); diff --git a/src/BufferView.cpp b/src/BufferView.cpp index c79a51deca..53cd4d09a8 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1059,11 +1059,10 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) case LFUN_BRANCH_ACTIVATE: case LFUN_BRANCH_DEACTIVATE: { - bool enable = false; + BranchList const & branchList = buffer_.params().branchlist(); docstring const branchName = cmd.argument(); - if (!branchName.empty()) - enable = buffer_.params().branchlist().find(branchName); - flag.setEnabled(enable); + flag.setEnabled(!branchName.empty() + && branchList.find(branchName)); break; } @@ -1502,6 +1501,8 @@ bool BufferView::dispatch(FuncRequest const & cmd) case LFUN_BRANCH_ACTIVATE: case LFUN_BRANCH_DEACTIVATE: + if (cmd.argument().empty()) + return false; buffer_.dispatch(cmd); processUpdateFlags(Update::Force); break; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 577cbde42c..ecd6b6f3e0 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3184,7 +3184,7 @@ void LyXAction::init() * \li Origin: rgh, 27 May 2008 * \endvar */ - { LFUN_BRANCH_ACTIVATE, "branch-activate", Argument, Buffer }, + { LFUN_BRANCH_ACTIVATE, "branch-activate", AtPoint, Buffer }, /*! * \var lyx::FuncCode lyx::LFUN_BRANCH_DEACTIVATE * \li Action: De-activate the branch @@ -3193,7 +3193,7 @@ void LyXAction::init() * \li Origin: rgh, 27 May 2008 * \endvar */ - { LFUN_BRANCH_DEACTIVATE, "branch-deactivate", Argument, Buffer }, + { LFUN_BRANCH_DEACTIVATE, "branch-deactivate", AtPoint, Buffer }, /*! * \var lyx::FuncCode lyx::LFUN_COPY_LABEL_AS_REF diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 0072dac43f..2878a4772b 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -143,6 +143,18 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) cur.bv().updateDialog("branch", params2string(params())); 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().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: if (cmd.argument() == "assign") setStatus(cur, isBranchSelected() ? Open : Collapsed); @@ -166,12 +178,19 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd, flag.setEnabled(true); break; + case LFUN_BRANCH_ACTIVATE: + flag.setEnabled(!isBranchSelected()); + break; + + case LFUN_BRANCH_DEACTIVATE: + flag.setEnabled(isBranchSelected()); + break; + case LFUN_INSET_TOGGLE: - if (cmd.argument() == "assign") { + if (cmd.argument() == "assign") flag.setEnabled(true); - break; - } - //fall through to generic InsetCollapsable implmementation + else + return InsetCollapsable::getStatus(cur, cmd, flag); default: 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 { // Its own scope if not selected by buffer diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index 607d8cfba2..640cc67103 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -78,6 +78,8 @@ private: /// void validate(LaTeXFeatures &) const; /// + docstring contextMenu(BufferView const &, int, int) const; + /// void addToToc(DocIterator const &); /// InsetBranchParams const & params() const { return params_; } -- 2.39.2