]> git.lyx.org Git - lyx.git/commitdiff
Extend the branch-(de)activate functions to work without a parameter. In
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 31 Mar 2009 09:38:07 +0000 (09:38 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 31 Mar 2009 09:38:07 +0000 (09:38 +0000)
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
src/Buffer.cpp
src/BufferView.cpp
src/LyXAction.cpp
src/insets/InsetBranch.cpp
src/insets/InsetBranch.h

index 82c85e3de82dbe9efe5659bc8c73caed23738e4e..552d54b11595f9a8bc71d35bae8cfad9abdb62ea 100644 (file)
@@ -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
index 3cd53dd1ba0805e9bd63c2604f46f5dc862f23a8..e1d43097ed729d6b1439435778c88254c620d9f8 100644 (file)
@@ -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.");
index c79a51deca6b1651e4a88936637f4ffa452f3710..53cd4d09a89ad9cf963c2d0dca41980f9b0d373d 100644 (file)
@@ -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;
index 577cbde42c106d6075e165d60d39a0b78405fac1..ecd6b6f3e0f9d33eb4482ab15396964ccd57dbe2 100644 (file)
@@ -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
index 0072dac43f694e3db3d89ca5e1ba51741330a0f4..2878a4772b6e2a51c7bbcca82c4088dc1ce45c66 100644 (file)
@@ -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 *>(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
index 607d8cfba224ac4a7a783d04e48cc5e28214217e..640cc671031790392072eca0e1a55bec4bd21430 100644 (file)
@@ -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_; }