mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
Initial patch for citation-insert
This commit is contained in:
parent
cd17d87e47
commit
9f62413b10
@ -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())
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
//@{
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user