>>>>> "Juergen" == Juergen Spitzmueller <[EMAIL PROTECTED]> writes:

Juergen> "Changing the citation key does not update references to it"
Juergen> http://bugzilla.lyx.org/show_bug.cgi?id=2744

Juergen> The attached patch against 1.4svn fixes the bug by extending
Juergen> changeRefsIfUnique. It works very nicely. OK for trunk and
Juergen> branch? (I have another fix for bug 1684 in the pipe).

Some comments:

  -void Buffer::changeRefsIfUnique(string const & from, string const & to)
  +void Buffer::changeRefsIfUnique(string const & from, string const & to, 
InsetBase::Code code)

I do not like passing an inset code if it is not really generic (the
codes are hardcoded later). If we follow this route, we should at
least assert on code's value.

  +     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);

I am sure there is a nice way of doing the counting without building
additional lists, but we would need Lars' help for that :)

  +     } else
  +             getLabelList(labels);
  +
          if (lyx::count(labels.begin(), labels.end(), from) > 1)
                  return;

If we were able to make the code below truly generic, the code above
could be done by two separate helper functions.


          ParIterator it = par_iterator_begin();
          ParIterator end = par_iterator_end();

Why not use an InsetIterator there? I know it was in the existing
code, but it may be a good time to improve it.

  +                             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));

I'd rather have a InsetCommand::replaceContents(from, to) that is
specialized in InsetCite. This way the code in the present method
would be truly generic.

Finally, there is a changed_inset variable that does not seem to be
used (not your doing).

JMarc

Reply via email to