Initial patch for citation-insert

This commit is contained in:
Benjamin Piwowarski 2012-06-05 10:37:34 +02:00 committed by Julien Rioux
parent cd17d87e47
commit 9f62413b10
3 changed files with 48 additions and 0 deletions

View File

@ -54,6 +54,7 @@
#include "WordLangTuple.h" #include "WordLangTuple.h"
#include "insets/InsetBibtex.h" #include "insets/InsetBibtex.h"
#include "insets/InsetCitation.h"
#include "insets/InsetCommand.h" // ChangeRefs #include "insets/InsetCommand.h" // ChangeRefs
#include "insets/InsetExternal.h" #include "insets/InsetExternal.h"
#include "insets/InsetGraphics.h" #include "insets/InsetGraphics.h"
@ -1907,6 +1908,23 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
arg = token(argument, '|', 0); arg = token(argument, '|', 0);
opt1 = token(argument, '|', 1); 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); InsetCommandParams icp(CITE_CODE);
icp["key"] = from_utf8(arg); icp["key"] = from_utf8(arg);
if (!opt1.empty()) if (!opt1.empty())

View 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 docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
{ {
Buffer const & buf = bv.buffer(); Buffer const & buf = bv.buffer();

View File

@ -16,6 +16,7 @@
#include "InsetCommand.h" #include "InsetCommand.h"
#include "Citation.h" #include "Citation.h"
#include "support/strfwd.h"
namespace lyx { namespace lyx {
@ -34,6 +35,9 @@ public:
/// ///
~InsetCitation(); ~InsetCitation();
///
bool addKey(std::string const & key);
/// \name Public functions inherited from Inset class /// \name Public functions inherited from Inset class
//@{ //@{
/// ///