"Changing the citation key does not update references to it" http://bugzilla.lyx.org/show_bug.cgi?id=2744
The attached patch against 1.4svn fixes the bug by extending changeRefsIfUnique. It works very nicely. OK for trunk and branch? (I have another fix for bug 1684 in the pipe). Jürgen
Index: src/insets/insetlabel.C =================================================================== --- src/insets/insetlabel.C (Revision 15150) +++ src/insets/insetlabel.C (Arbeitskopie) @@ -71,7 +71,7 @@ } if (p.getContents() != params().getContents()) cur.bv().buffer()->changeRefsIfUnique(params().getContents(), - p.getContents()); + p.getContents(), InsetBase::REF_CODE); setParams(p); break; } Index: src/insets/insetbibitem.C =================================================================== --- src/insets/insetbibitem.C (Revision 15150) +++ src/insets/insetbibitem.C (Arbeitskopie) @@ -61,10 +61,14 @@ case LFUN_INSET_MODIFY: { InsetCommandParams p; InsetCommandMailer::string2params("bibitem", cmd.argument, p); - if (!p.getCmdName().empty()) - setParams(p); - else + if (p.getCmdName().empty()) { cur.noUpdate(); + break; + } + if (p.getContents() != params().getContents()) + cur.bv().buffer()->changeRefsIfUnique(params().getContents(), + p.getContents(), InsetBase::CITE_CODE); + setParams(p); break; } Index: src/mathed/math_hullinset.C =================================================================== --- src/mathed/math_hullinset.C (Revision 15150) +++ src/mathed/math_hullinset.C (Arbeitskopie) @@ -1078,7 +1078,7 @@ numbered(r, true); string old = label(r); if (str != old) { - cur.bv().buffer()->changeRefsIfUnique(old, str); + cur.bv().buffer()->changeRefsIfUnique(old, str, InsetBase::REF_CODE); label(r, str); } break; Index: src/buffer.C =================================================================== --- src/buffer.C (Revision 15150) +++ src/buffer.C (Arbeitskopie) @@ -67,7 +67,7 @@ #include "support/lyxalgo.h" #include "support/filetools.h" #include "support/fs_extras.h" -# include "support/gzstream.h" +#include "support/gzstream.h" #include "support/lyxlib.h" #include "support/os.h" #include "support/path.h" @@ -83,6 +83,7 @@ # include <sys/utime.h> #endif +#include <algorithm> #include <iomanip> #include <stack> #include <sstream> @@ -99,6 +100,8 @@ using lyx::support::createBufferTmpDir; using lyx::support::destroyDir; using lyx::support::getFormatFromContents; +using lyx::support::getStringFromVector; +using lyx::support::getVectorFromString; using lyx::support::IsDirWriteable; using lyx::support::LibFileSearch; using lyx::support::latex_path; @@ -116,6 +119,7 @@ using lyx::support::split; using lyx::support::subst; using lyx::support::tempName; +using lyx::support::tokenPos; using lyx::support::trim; namespace os = lyx::support::os; @@ -124,6 +128,7 @@ using std::endl; using std::for_each; using std::make_pair; +using std::replace; using std::ifstream; using std::ios; @@ -1612,17 +1617,25 @@ } -void Buffer::changeRefsIfUnique(string const & from, string const & to) +void Buffer::changeRefsIfUnique(string const & from, string const & to, InsetBase::Code code) { // Check if the label 'from' appears more than once vector<string> labels; - getLabelList(labels); + if (code == InsetBase::CITE_CODE) { + vector<pair<string, string> > keys; + fillWithBibKeys(keys); + vector<pair<string, string> >::const_iterator bit = keys.begin(); + vector<pair<string, string> >::const_iterator bend = keys.end(); + + for (; bit != bend; ++bit) + labels.push_back(bit->first); + } else + getLabelList(labels); + if (lyx::count(labels.begin(), labels.end(), from) > 1) return; - InsetBase::Code code = InsetBase::REF_CODE; - ParIterator it = par_iterator_begin(); ParIterator end = par_iterator_end(); for ( ; it != end; ++it) { @@ -1631,10 +1644,16 @@ it2 != it->insetlist.end(); ++it2) { if (it2->inset->lyxCode() == code) { InsetCommand * inset = static_cast<InsetCommand *>(it2->inset); - if (inset->getContents() == from) { + string const contents = inset->getContents(); + if (contents == from) { inset->setContents(to); //inset->setButtonLabel(); changed_inset = true; + } else if (code == InsetBase::CITE_CODE + && tokenPos(contents, ',', from) != -1) { + vector<string> items = getVectorFromString(contents); + replace(items.begin(), items.end(), from, to); + inset->setContents(getStringFromVector(items)); } } } Index: src/buffer.h =================================================================== --- src/buffer.h (Revision 15150) +++ src/buffer.h (Arbeitskopie) @@ -343,7 +343,7 @@ /// StableDocIterator getAnchor() const { return anchor_; } /// - void changeRefsIfUnique(std::string const & from, std::string const & to); + void changeRefsIfUnique(std::string const & from, std::string const & to, InsetBase::Code code); private: /** Inserts a file into a document