]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Cmake build: Creating a define for a header file found
[lyx.git] / src / BufferView.cpp
index 07ad2c93abe3855214058461ea164749f7b57595..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)
@@ -1192,9 +1194,9 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        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);
+                                   || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
                BranchList const & branchList = master ? buffer().masterBuffer()->params().branchlist()
-                                                                                          : buffer().params().branchlist();
+                                                      : buffer().params().branchlist();
                docstring const branchName = cmd.argument();
                flag.setEnabled(!branchName.empty() && branchList.find(branchName));
                break;
@@ -1273,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.");
@@ -1807,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();
@@ -1823,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;
@@ -1906,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())
@@ -1978,9 +1999,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        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);
+                                    || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
                Buffer * buf = master ? const_cast<Buffer *>(buffer().masterBuffer())
-                                                         : &buffer();
+                                     : &buffer();
 
                docstring const branch_name = cmd.argument();
                // the case without a branch name is handled elsewhere
@@ -1998,7 +2019,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        break;
                }
                bool activate = (cmd.action() == LFUN_BRANCH_ACTIVATE
-                                                || cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE);
+                                || cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE);
                if (branch->isSelected() != activate) {
                        branch->setSelected(activate);
                        cur.recordUndoFullDocument();