]> git.lyx.org Git - lyx.git/commitdiff
UI for separate control of master/child branch state (#7642, part of #7643)
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 30 Sep 2012 12:59:24 +0000 (14:59 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 30 Sep 2012 12:59:24 +0000 (14:59 +0200)
RELEASE-NOTES
lib/ui/stdcontext.inc
src/BufferView.cpp
src/FuncCode.h
src/LyXAction.cpp
src/insets/InsetBranch.cpp
src/insets/InsetBranch.h

index 64adb50059e326f83d77bffec42ac8740825ef71..7b483d07c10999aba34c231fe3817f4e6e781740 100644 (file)
@@ -53,6 +53,12 @@ To set the default language and paper size for new documents, use the
 
 The following new LyX functions have been introduced:
 
+- LFUN_BRANCH_MASTER_ACTIVATE <branch>:
+  LFUN_BRANCH_MASTER_DEACTIVATE <branch>:
+  Activates or deactivates a branch in a master document from within
+  a child (as opposed to the existing LFUN_BRANCH_[DE]ACTIVATE, which
+  toggle the branch in the document itself).
+
 - LFUN_BUFFER_EXPORT_AS <format> <filename>
   Equivalent to the new -export-to command-line switch (see above).
 
index 41f498288c180e9fea40bd334dac5f07a2c1ece8..d250afa74539b147eadd08bf042c6929f01ccafb 100644 (file)
@@ -441,6 +441,8 @@ Menuset
        Menu "context-branch"
                OptItem "Activate Branch|A" "branch-activate"
                OptItem "Deactivate Branch|e" "branch-deactivate"
+               OptItem "Activate Branch in Master|M" "branch-master-activate"
+               OptItem "Deactivate Branch in Master|v" "branch-master-deactivate"
        End
 
 #
index 98b84c8fa978422b79c42fe026610987e8b28059..07ad2c93abe3855214058461ea164749f7b57595 100644 (file)
@@ -1188,8 +1188,13 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        // handle their dispatch here, for reasons explained there, so we'll
        // handle this here, too, for consistency.
        case LFUN_BRANCH_ACTIVATE:
-       case LFUN_BRANCH_DEACTIVATE: {
-               BranchList const & branchList = buffer().params().branchlist();
+       case LFUN_BRANCH_DEACTIVATE:
+       case LFUN_BRANCH_MASTER_ACTIVATE:
+       case LFUN_BRANCH_MASTER_DEACTIVATE: {
+               bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
+                                                        || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
+               BranchList const & branchList = master ? buffer().masterBuffer()->params().branchlist()
+                                                                                          : buffer().params().branchlist();
                docstring const branchName = cmd.argument();
                flag.setEnabled(!branchName.empty() && branchList.find(branchName));
                break;
@@ -1969,15 +1974,21 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        // So, if this does get fixed, this code can be moved back to Buffer.cpp,
        // and the corresponding code in getStatus() should be moved back, too.
        case LFUN_BRANCH_ACTIVATE:
-       case LFUN_BRANCH_DEACTIVATE: {
-               BranchList & branch_list = buffer().params().branchlist();
+       case LFUN_BRANCH_DEACTIVATE:
+       case LFUN_BRANCH_MASTER_ACTIVATE:
+       case LFUN_BRANCH_MASTER_DEACTIVATE: {
+               bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
+                                                        || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
+               Buffer * buf = master ? const_cast<Buffer *>(buffer().masterBuffer())
+                                                         : &buffer();
+
                docstring const branch_name = cmd.argument();
                // the case without a branch name is handled elsewhere
                if (branch_name.empty()) {
                        dispatched = false;
                        break;
                }
-               Branch * branch = branch_list.find(branch_name);
+               Branch * branch = buf->params().branchlist().find(branch_name);
                if (!branch) {
                        LYXERR0("Branch " << branch_name << " does not exist.");
                        dr.setError(true);
@@ -1986,7 +1997,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dr.setMessage(msg);
                        break;
                }
-               bool activate = cmd.action() == LFUN_BRANCH_ACTIVATE;
+               bool activate = (cmd.action() == LFUN_BRANCH_ACTIVATE
+                                                || cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE);
                if (branch->isSelected() != activate) {
                        branch->setSelected(activate);
                        cur.recordUndoFullDocument();
index 6f41e7dec948dc1ba37595335c85702cbfa285f0..c5749c3753dce46ca05f179319c6de3eaaa5a9b0 100644 (file)
@@ -450,6 +450,8 @@ enum FuncCode
        LFUN_SCRIPT_INSERT,             // gb, 20101123
        LFUN_BUFFER_EXPORT_AS,          // tommaso 20111006
        // 350
+       LFUN_BRANCH_MASTER_ACTIVATE,    // spitz 20120930
+       LFUN_BRANCH_MASTER_DEACTIVATE,  // spitz 20120930
        LFUN_LASTACTION                 // end of the table
 };
 
index 9aa2ddefb31aaae76c5a09563664ae719aeee6c9..998b79d2fc4df6ba67fd97b3773feb6a9380ea10 100644 (file)
@@ -3525,6 +3525,27 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_BRANCH_DEACTIVATE, "branch-deactivate", AtPoint, Buffer },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_BRANCH_MASTER_ACTIVATE
+ * \li Action: Activate the branch in the master buffer.
+ * \li Syntax: branch-master-activate <BRANCH>
+ * \li Params: <BRANCH>: The branch to activate
+ * \li Sample: lyx -x "branch-activate answers" -e pdf2 finalexam.lyx \n
+               could be used to export a pdf with the answers branch included
+               without one's having to open LyX and activate the branch manually.
+ * \li Origin: spitz, 30 Sep 2012
+ * \endvar
+ */
+        { LFUN_BRANCH_MASTER_ACTIVATE, "branch-master-activate", AtPoint, Buffer },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_BRANCH_MASTER_DEACTIVATE
+ * \li Action: De-activate the branch in the master buffer.
+ * \li Syntax: branch-master-deactivate <BRANCH>
+ * \li Params: <BRANCH>: The branch to deactivate
+ * \li Origin: spitz, 30 Sep 2012
+ * \endvar
+ */
+        { LFUN_BRANCH_MASTER_DEACTIVATE, "branch-master-deactivate", AtPoint, Buffer },
 
 /*!
  * \var lyx::FuncCode lyx::LFUN_BRANCHES_RENAME
index 6ab2fb79e73e5712a08c3face65b7bafc933eb6c..6407fb638963ef404c170e66d7afc9074d68093f 100644 (file)
@@ -64,8 +64,14 @@ void InsetBranch::read(Lexer & lex)
 
 docstring InsetBranch::toolTip(BufferView const & bv, int, int) const
 {
-       docstring const status = isBranchSelected() ? 
+       docstring const masterstatus = isBranchSelected() ?
                _("active") : _("non-active");
+       docstring const childstatus = isBranchSelected(true) ?
+               _("active") : _("non-active");
+       docstring const status = (masterstatus == childstatus) ?
+               masterstatus :
+               support::bformat(_("master: %1$s, child: %2$s"),
+                                                masterstatus, childstatus);
        docstring const heading = 
                support::bformat(_("Branch (%1$s): %2$s"), status, params_.branch);
        if (isOpen(bv))
@@ -79,10 +85,13 @@ docstring const InsetBranch::buttonLabel(BufferView const & bv) const
        docstring s = _("Branch: ") + params_.branch;
        Buffer const & realbuffer = *buffer().masterBuffer();
        BranchList const & branchlist = realbuffer.params().branchlist();
-       if (!branchlist.find(params_.branch)
-           && buffer().params().branchlist().find(params_.branch))
+       bool const inmaster = branchlist.find(params_.branch);
+       bool const inchild = buffer().params().branchlist().find(params_.branch);
+       if (!inmaster && inchild)
                s = _("Branch (child only): ") + params_.branch;
-       else if (!branchlist.find(params_.branch))
+       else if (inmaster && !inchild)
+               s = _("Branch (master only): ") + params_.branch;
+       else if (!inmaster)
                s = _("Branch (undefined): ") + params_.branch;
        if (!params_.branch.empty()) {
                // FIXME UNICODE
@@ -90,7 +99,12 @@ docstring const InsetBranch::buttonLabel(BufferView const & bv) const
                if (c == Color_none)
                        s = _("Undef: ") + s;
        }
-       s = char_type(isBranchSelected() ? 0x2714 : 0x2716) + s;
+       bool const master_selected = isBranchSelected();
+       bool const child_selected = isBranchSelected(true);
+       docstring symb = docstring(1, char_type(master_selected ? 0x2714 : 0x2716));
+       if (inchild && master_selected != child_selected)
+               symb += char_type(child_selected ? 0x2714 : 0x2716);
+       s = symb + s;
        if (decoration() == InsetLayout::CLASSIC)
                return isOpen(bv) ? s : getNewLabel(s);
        else
@@ -125,26 +139,26 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
        case LFUN_BRANCH_ACTIVATE:
-       case LFUN_BRANCH_DEACTIVATE: {
-               Buffer * buf = const_cast<Buffer *>(buffer().masterBuffer());
-               // is the branch in our master buffer?
-               bool branch_in_master = (buf != &buffer());
+       case LFUN_BRANCH_DEACTIVATE:
+       case LFUN_BRANCH_MASTER_ACTIVATE:
+       case LFUN_BRANCH_MASTER_DEACTIVATE: {
+               bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
+                                                        || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
+               Buffer * buf = master ? const_cast<Buffer *>(buffer().masterBuffer())
+                                                         : &buffer();
 
                Branch * our_branch = buf->params().branchlist().find(params_.branch);
-               if (branch_in_master && !our_branch) {
-                       // child only?
-                       our_branch = buffer().params().branchlist().find(params_.branch);
-                       if (!our_branch)
-                               break;
-                       branch_in_master = false;
-               }
-               bool const activate = (cmd.action() == LFUN_BRANCH_ACTIVATE);
+               if (!our_branch)
+                       break;
+
+               bool const activate = (cmd.action() == LFUN_BRANCH_ACTIVATE
+                                                          || cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE);
                if (our_branch->isSelected() != activate) {
                        // FIXME If the branch is in the master document, we cannot
-                       // call recordUndo..., becuase the master may be hidden, and
+                       // call recordUndo..., because the master may be hidden, and
                        // the code presently assumes that hidden documents can never
                        // be dirty. See GuiView::closeBufferAll(), for example.
-                       if (!branch_in_master)
+                       if (!master)
                                buffer().undo().recordUndoFullDocument(cur);
                        our_branch->setSelected(activate);
                        cur.forceBufferUpdate();
@@ -174,11 +188,19 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
                break;
 
        case LFUN_BRANCH_ACTIVATE:
-               flag.setEnabled(!isBranchSelected());
+               flag.setEnabled(!isBranchSelected(true));
                break;
 
        case LFUN_BRANCH_DEACTIVATE:
-               flag.setEnabled(isBranchSelected());
+               flag.setEnabled(isBranchSelected(true));
+               break;
+
+       case LFUN_BRANCH_MASTER_ACTIVATE:
+               flag.setEnabled(buffer().parent() && !isBranchSelected());
+               break;
+
+       case LFUN_BRANCH_MASTER_DEACTIVATE:
+               flag.setEnabled(buffer().parent() && isBranchSelected());
                break;
 
        case LFUN_INSET_TOGGLE:
@@ -195,9 +217,9 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-bool InsetBranch::isBranchSelected() const
+bool InsetBranch::isBranchSelected(bool const child) const
 {
-       Buffer const & realbuffer = *buffer().masterBuffer();
+       Buffer const & realbuffer = child ? buffer() : *buffer().masterBuffer();
        BranchList const & branchlist = realbuffer.params().branchlist();
        Branch const * ourBranch = branchlist.find(params_.branch);
 
index 6cc64ec8b28ec2b230d56b710047279f7306affe..6588bc61b3e81a86a9e5cf4bda002783875b4a35 100644 (file)
@@ -88,9 +88,9 @@ private:
        void setParams(InsetBranchParams const & params) { params_ = params; }
 
        /** \returns true if params_.branch is listed as 'selected' in
-           \c buffer. This handles the case of child documents.
+               \c buffer. \p child only checks within child documents.
         */
-       bool isBranchSelected() const;
+       bool isBranchSelected(bool const child = false) const;
        /*!
         * Is the content of this inset part of the output document?
         *