]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
tex2lyx: support for multiple indices and subindices
[lyx.git] / src / BufferView.cpp
index e1ff3897199eb1fc92ecc7435a829bdc09816b3b..43420209cceab24a9d4101b4855c72ad797a437e 100644 (file)
@@ -54,6 +54,7 @@
 #include "WordLangTuple.h"
 
 #include "insets/InsetBibtex.h"
+#include "insets/InsetCitation.h"
 #include "insets/InsetCommand.h" // ChangeRefs
 #include "insets/InsetExternal.h"
 #include "insets/InsetGraphics.h"
@@ -105,6 +106,7 @@ T * getInsetByCode(Cursor const & cur, InsetCode code)
        return 0;
 }
 
+
 /// Note that comparing contents can only be used for InsetCommand
 bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
        docstring const & contents)
@@ -1188,8 +1190,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;
@@ -1218,14 +1225,7 @@ void BufferView::editInset(string const & name, Inset * inset)
 
 void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 {
-       //lyxerr << [ cmd = " << cmd << "]" << endl;
-
-       // Make sure that the cached BufferView is correct.
-       LYXERR(Debug::ACTION, " action[" << cmd.action() << ']'
-               << " arg[" << to_utf8(cmd.argument()) << ']'
-               << " x[" << cmd.x() << ']'
-               << " y[" << cmd.y() << ']'
-               << " button[" << cmd.button() << ']');
+       LYXERR(Debug::ACTION, "BufferView::dispatch: cmd: " << cmd);
 
        string const argument = to_utf8(cmd.argument());
        Cursor & cur = d->cursor_;
@@ -1275,7 +1275,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
        case LFUN_LAYOUT_MODULE_ADD: {
                BufferParams const & params = buffer_.params();
-               if (!params.moduleCanBeAdded(argument)) {
+               if (!params.layoutModuleCanBeAdded(argument)) {
                        LYXERR0("Module `" << argument << 
                                "' cannot be added due to failed requirements or "
                                "conflicts with installed modules.");
@@ -1809,7 +1809,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        cur.forwardInset();
                cur.beginUndoGroup();
                while(cur && iterations < max_iter) {
-                       Inset * ins = cur.nextInset();
+                       Inset * const ins = cur.nextInset();
                        if (!ins)
                                break;
                        docstring insname = ins->layoutName();
@@ -1825,7 +1825,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                        break;
                                insname = insname.substr(0, i);
                        }
-                       cur.forwardInset();
+                       // if we did not delete the inset, skip it
+                       if (!cur.nextInset() || cur.nextInset() == ins)
+                               cur.forwardInset();
                }
                cur.endUndoGroup();
                cur = savecur;
@@ -1908,6 +1910,23 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        arg = token(argument, '|', 0);
                        opt1 = token(argument, '|', 1);
                }
+
+               // if our cursor is direclty in front of or behind a citation inset,
+               // we will instead add the new key to it.
+               Inset * inset = cur.nextInset();
+               if (!inset || inset->lyxCode() != CITE_CODE)
+                       inset = cur.prevInset();
+               if (inset && inset->lyxCode() == CITE_CODE) {
+                       InsetCitation * icite = static_cast<InsetCitation *>(inset);
+                       if (icite->addKey(arg)) {
+                               dr.forceBufferUpdate();
+                               dr.screenUpdate(Update::FitCursor | Update::SinglePar);
+                               if (!opt1.empty())
+                                       LYXERR0("Discarding optional argument to citation-insert.");
+                       }
+                       dispatched = true;
+                       break;
+               }
                InsetCommandParams icp(CITE_CODE);
                icp["key"] = from_utf8(arg);
                if (!opt1.empty())
@@ -1976,15 +1995,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);
@@ -1993,7 +2018,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();
@@ -2449,6 +2475,8 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
                cap::saveSelection(cursor());
 
        d->cursor_.macroModeClose();
+       // If a macro has been finalized, the cursor might have been broken
+       cur.fixIfBroken();
 
        // Has the cursor just left the inset?
        bool const leftinset = (&d->cursor_.inset() != &cur.inset());