]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcite.C
Make it compile when USE_BOOST_FORMAT is unset
[lyx.git] / src / insets / insetcite.C
index dffb0abefe91a1af93e49cdcd2487556a50d23a1..1be81b58d24850d173602d5823fb9d7de621212d 100644 (file)
@@ -1,10 +1,12 @@
 /**
  * \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>
@@ -49,17 +51,22 @@ string const getNatbibLabel(Buffer const * 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();
@@ -72,7 +79,7 @@ string const getNatbibLabel(Buffer const * buffer,
                        infomap[bit->first] = bit->second;
                }
                if (infomap.empty())
-               return string();
+                       return string();
 
                cached_keys[buffer] = infomap;
        }
@@ -308,14 +315,20 @@ 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);
+       bv->owner()->getDialogs().showCitation(this);
 }
 
 
@@ -353,6 +366,8 @@ int InsetCitation::latex(Buffer const * buffer, ostream & os,
                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
@@ -373,8 +388,12 @@ int InsetCitation::latex(Buffer const * buffer, ostream & os,
        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 << "}";