- ParIterator fpit = par_iterator_begin(in);
- ParIterator fend = par_iterator_end(in);
-
- for (; fpit != fend; ++fpit) {
- InsetList::const_iterator lit = fpit->insetlist.begin();
- InsetList::const_iterator eit = fpit->insetlist.end();
+ InsetIterator const i_end = inset_iterator_end(in);
+ for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
+ // Even though this will also be done later, it has to be done here
+ // since some inset might going to try to access
+ // the buffer() member.
+ it->setBuffer(const_cast<Buffer &>(buffer));
+ switch (it->lyxCode()) {
+
+ case MATH_HULL_CODE: {
+ // check for equation labels and resolve duplicates
+ InsetMathHull * ins = it->asInsetMath()->asHullInset();
+ std::vector<InsetLabel *> labels = ins->getLabels();
+ for (size_t i = 0; i != labels.size(); ++i) {
+ if (!labels[i])
+ continue;
+ InsetLabel * lab = labels[i];
+ docstring const oldname = lab->getParam("name");
+ lab->updateLabel(oldname);
+ // We need to update the buffer reference cache.
+ cur.forceBufferUpdate();
+ docstring const newname = lab->getParam("name");
+ if (oldname == newname)
+ continue;
+ // adapt the references
+ for (InsetIterator itt = inset_iterator_begin(in);
+ itt != i_end; ++itt) {
+ if (itt->lyxCode() == REF_CODE) {
+ InsetCommand * ref = itt->asInsetCommand();
+ if (ref->getParam("reference") == oldname)
+ ref->setParam("reference", newname);
+ } else if (itt->lyxCode() == MATH_REF_CODE) {
+ InsetMathHull * mi = itt->asInsetMath()->asHullInset();
+ // this is necessary to prevent an uninitialized
+ // buffer when the RefInset is in a MathBox.
+ // FIXME audit setBuffer calls
+ mi->setBuffer(const_cast<Buffer &>(buffer));
+ if (mi->asRefInset()->getTarget() == oldname)
+ mi->asRefInset()->changeTarget(newname);
+ }
+ }
+ }
+ break;
+ }