]> git.lyx.org Git - features.git/commitdiff
Initial patch for citation-insert
authorBenjamin Piwowarski <benjamin@bpiwowar.net>
Tue, 5 Jun 2012 08:37:34 +0000 (10:37 +0200)
committerJulien Rioux <jrioux@lyx.org>
Tue, 15 Jan 2013 13:51:29 +0000 (14:51 +0100)
src/BufferView.cpp
src/insets/InsetCitation.cpp
src/insets/InsetCitation.h

index fd26a81709b5cfe3b4cfeb81f7ba7ba0e2ee9798..cb2b7fba0362c78ddd39f94e4879f44b6d9c4a84 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"
@@ -1907,6 +1908,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->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())
index 2778e199a06bc21c56501f69f1e7ed08a28a5f58..b1e48a672c5e2603fecf9f4a7e27a7b2d9cb3275 100644 (file)
@@ -122,6 +122,32 @@ void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetCitation::addKey(string const & key)
+{
+       docstring const ukey = from_utf8(key);
+       docstring const & curkeys = getParam("key");
+       if (curkeys.empty()) {
+               setParam("key", ukey);
+               cache.recalculate = true;
+               return true;
+       }
+
+       vector<docstring> keys = getVectorFromString(curkeys);
+       vector<docstring>::const_iterator it = keys.begin();
+       vector<docstring>::const_iterator en = keys.end();
+       for (; it != en; ++it) {
+               if (*it == ukey) {
+                       LYXERR0("Key " << key << " already present.");
+                       return false;
+               }
+       }
+       keys.push_back(ukey);
+       setParam("key", getStringFromVector(keys));
+       cache.recalculate = true;
+       return true;
+}
+
+
 docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
 {
        Buffer const & buf = bv.buffer();
index e29c3997fb8fcfa8953512c13cb2fa40c46f5324..af817dddb87d6db1e958d3708ce4e8026d550bab 100644 (file)
@@ -16,6 +16,7 @@
 #include "InsetCommand.h"
 
 #include "Citation.h"
+#include "support/strfwd.h"
 
 namespace lyx {
 
@@ -34,6 +35,9 @@ public:
        ///
        ~InsetCitation();
 
+       ///
+       bool addKey(std::string const & key);
+
        /// \name Public functions inherited from Inset class
        //@{
        ///