From: Benjamin Piwowarski Date: Tue, 5 Jun 2012 08:37:34 +0000 (+0200) Subject: Initial patch for citation-insert X-Git-Tag: 2.1.0beta1~911 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9f62413b103b74dbbd223388101b537a4988cae2;p=lyx.git Initial patch for citation-insert --- diff --git a/src/BufferView.cpp b/src/BufferView.cpp index fd26a81709..cb2b7fba03 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -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(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()) diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 2778e199a0..b1e48a672c 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -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 keys = getVectorFromString(curkeys); + vector::const_iterator it = keys.begin(); + vector::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(); diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index e29c3997fb..af817dddb8 100644 --- a/src/insets/InsetCitation.h +++ b/src/insets/InsetCitation.h @@ -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 //@{ ///