/**
* \file insetcite.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author Angus Leeming, a.leeming@ic.ac.uk
- * \author Herbert Voss, voss@lyx.org 2002-03-17
+ * \author Angus Leeming
+ * \author Herbert Voss
+ *
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
namespace {
// An optimisation. We assume that until the first InsetCitation::edit is
-// called, we're loding the buffer and that, therefore, we don't need to
+// called, we're loading the buffer and that, therefore, we don't need to
// reload the bibkey list
std::map<Buffer const *, bool> loading_buffer;
string const & before, string const & after,
bool numerical)
{
- // Only reload the bibkeys if we have to...
- map<Buffer const *, bool>::iterator lit = loading_buffer.find(buffer);
- if (lit != loading_buffer.end())
- loading_buffer[buffer] = true;
-
typedef std::map<Buffer const *, biblio::InfoMap> CachedMap;
static CachedMap cached_keys;
- CachedMap::iterator kit = cached_keys.find(buffer);
+ // Only load the bibkeys once if we're loading up the buffer,
+ // else load them afresh each time.
+ map<Buffer const *, bool>::iterator lit = loading_buffer.find(buffer);
+ if (lit == loading_buffer.end())
+ loading_buffer[buffer] = true;
+
+ bool loadkeys = !loading_buffer[buffer];
+ if (!loadkeys) {
+ CachedMap::iterator kit = cached_keys.find(buffer);
+ loadkeys = kit == cached_keys.end();
+ }
- if (!loading_buffer[buffer] || kit == cached_keys.end()) {
+ if (loadkeys) {
// build the keylist
typedef vector<std::pair<string, string> > InfoType;
InfoType bibkeys = buffer->getBibkeyList();
infomap[bit->first] = bit->second;
}
if (infomap.empty())
- return string();
+ return string();
cached_keys[buffer] = infomap;
}
}
+void InsetCitation::setLoadingBuffer(Buffer const * buffer, bool state) const
+{
+ // Doesn't matter if there is no bv->buffer() entry in the map.
+ loading_buffer[buffer] = state;
+}
+
+
void InsetCitation::edit(BufferView * bv, int, int, mouse_button::state)
{
// A call to edit() indicates that we're no longer loading the
// buffer but doing some real work.
- // Doesn't matter if there is no bv->buffer() entry in the map.
- loading_buffer[bv->buffer()] = false;
+ setLoadingBuffer(bv->buffer(), false);
- bv->owner()->getDialogs()->showCitation(this);
+ bv->owner()->getDialogs().showCitation(this);
}
os << "cite";
#warning What is this code supposed to do? (Lgb)
+// my guess is that this is just waiting for when we support before,
+// so it's a oneliner. But this is very silly ! - jbl
#if 1
// The current strange code
string::const_iterator end = getContents().end();
// Paranoia check: make sure that there is no whitespace in here
string content;
+ char last = ',';
for (; it != end; ++it) {
- if (*it != ' ') content += *it;
+ if (*it != ' ')
+ last = *it;
+ if (*it != ' ' || last != ',')
+ content += *it;
}
os << "{" << content << "}";