X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetcite.C;h=8bd95bfdbea5f73c6cad53c8bd0767386521126c;hb=6ce86e2bfe0a403e0e811b66fdddb2d56cfe0f83;hp=998338787bb4c355920b9879e04afe612995e5ac;hpb=0507b8600d40ac155d6576dafe1218db643a8970;p=lyx.git diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 998338787b..8bd95bfdbe 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -11,27 +11,14 @@ #include -#ifdef __GNUG__ -#pragma implementation -#endif - #include "insetcite.h" #include "buffer.h" #include "BufferView.h" #include "LaTeXFeatures.h" -#include "frontends/LyXView.h" -#include "debug.h" -#include "gettext.h" #include "frontends/controllers/biblio.h" -#include "frontends/Dialogs.h" -#include "support/filetools.h" -#include "support/lstrings.h" -#include "support/path.h" -#include "support/os.h" #include "support/lstrings.h" -#include "support/LAssert.h" #include @@ -51,20 +38,26 @@ string const getNatbibLabel(Buffer const * buffer, string const & before, string const & after, bool numerical) { - // Only reload the bibkeys if we have to... - map::iterator lit = loading_buffer.find(buffer); - if (lit != loading_buffer.end()) - loading_buffer[buffer] = true; - typedef std::map 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::iterator lit = loading_buffer.find(buffer); + if (lit == loading_buffer.end()) + loading_buffer[buffer] = true; - if (!loading_buffer[buffer] || kit == cached_keys.end()) { + bool loadkeys = !loading_buffer[buffer]; + if (!loadkeys) { + CachedMap::iterator kit = cached_keys.find(buffer); + loadkeys = kit == cached_keys.end(); + } + + if (loadkeys) { // build the keylist typedef vector > InfoType; - InfoType bibkeys = buffer->getBibkeyList(); + InfoType bibkeys; + buffer->fillWithBibKeys(bibkeys); InfoType::const_iterator bit = bibkeys.begin(); InfoType::const_iterator bend = bibkeys.end(); @@ -74,7 +67,7 @@ string const getNatbibLabel(Buffer const * buffer, infomap[bit->first] = bit->second; } if (infomap.empty()) - return string(); + return string(); cached_keys[buffer] = infomap; } @@ -125,9 +118,9 @@ string const getNatbibLabel(Buffer const * buffer, // puctuation mark separating citation entries. char const * const sep = ";"; - string const op_str(string(1, ' ') + string(1, op)); - string const cp_str(string(1, cp) + string(1, ' ')); - string const sep_str(string(sep) + " "); + string const op_str(' ' + string(1, op)); + string const cp_str(string(1, cp) + ' '); + string const sep_str(string(sep) + ' '); string label; vector keys = getVectorFromString(keyList); @@ -209,7 +202,7 @@ string const getBasicLabel(string const & keyList, string const & after) if (contains(keys, ",")) { // Final comma allows while loop to cover all keys - keys = ltrim(split(keys, label, ',')) + ","; + keys = ltrim(split(keys, label, ',')) + ','; while (contains(keys, ",")) { string key; keys = ltrim(split(keys, key, ',')); @@ -221,7 +214,7 @@ string const getBasicLabel(string const & keyList, string const & after) if (!after.empty()) label += ", " + after; - return "[" + label + "]"; + return '[' + label + ']'; } } // anon namespace @@ -232,6 +225,13 @@ InsetCitation::InsetCitation(InsetCommandParams const & p, bool) {} +InsetCitation::~InsetCitation() +{ + InsetCommandMailer mailer("citation", *this); + mailer.hideDialog(); +} + + string const InsetCitation::generateLabel(Buffer const * buffer) const { string const before = string(); @@ -310,14 +310,21 @@ string const InsetCitation::getScreenLabel(Buffer const * buffer) const } +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); + InsetCommandMailer mailer("citation", *this); + mailer.showDialog(bv); } @@ -364,14 +371,14 @@ int InsetCitation::latex(Buffer const * buffer, ostream & os, string const before = string(); string const after = getOptions(); if (!before.empty() && buffer->params.use_natbib) - os << "[" << before << "][" << after << "]"; + os << '[' << before << "][" << after << ']'; else if (!after.empty()) - os << "[" << after << "]"; + os << '[' << after << ']'; #else // and the cleaned up equvalent, should it just be changed? (Lgb) string const after = getOptions(); if (!after.empty()) - os << "[" << after << "]"; + os << '[' << after << ']'; #endif string::const_iterator it = getContents().begin(); string::const_iterator end = getContents().end(); @@ -385,7 +392,7 @@ int InsetCitation::latex(Buffer const * buffer, ostream & os, content += *it; } - os << "{" << content << "}"; + os << '{' << content << '}'; return 0; }