]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.cpp
do what the FIXME suggested
[lyx.git] / src / CutAndPaste.cpp
index 975cf789c9f8ca3beee989df09b2a8539ca91598..f661b3462bf43a92d086c31ad2fbe8da91a56d41 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "CutAndPaste.h"
 
-#include "BaseClassList.h"
 #include "Buffer.h"
 #include "buffer_funcs.h"
 #include "BufferParams.h"
@@ -38,6 +37,7 @@
 #include "Undo.h"
 
 #include "insets/InsetFlex.h"
+#include "insets/InsetCommand.h"
 #include "insets/InsetGraphics.h"
 #include "insets/InsetGraphicsParams.h"
 #include "insets/InsetTabular.h"
@@ -213,14 +213,55 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
        // A couple of insets store buffer references so need updating.
        insertion.swap(in.paragraphs());
 
-       ParIterator fpit = par_iterator_begin(in);
-       ParIterator fend = par_iterator_end(in);
+       InsetIterator const i_end = inset_iterator_end(in);
+
+       for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
+
+               it->setBuffer(const_cast<Buffer &>(buffer));
+
+               switch (it->lyxCode()) {
+               case LABEL_CODE: {
+                       // check for duplicates
+                       InsetCommand & lab = static_cast<InsetCommand &>(*it);
+                       docstring const oldname = lab.getParam("name");
+                       lab.updateCommand(oldname, false);
+                       docstring const newname = lab.getParam("name");
+                       if (oldname != newname) {
+                               // adapt the references
+                               for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
+                                       if (itt->lyxCode() == REF_CODE) {
+                                               InsetCommand & ref = dynamic_cast<InsetCommand &>(*itt);
+                                               if (ref.getParam("reference") == oldname)
+                                                       ref.setParam("reference", newname);
+                                       }
+                               }
+                       }
+                       break;
+               }
+
+               case BIBITEM_CODE: {
+                       // check for duplicates
+                       InsetCommand & bib = static_cast<InsetCommand &>(*it);
+                       docstring const oldkey = bib.getParam("key");
+                       bib.updateCommand(oldkey, false);
+                       docstring const newkey = bib.getParam("key");
+                       if (oldkey != newkey) {
+                               // adapt the references
+                               for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
+                                       if (itt->lyxCode() == CITE_CODE) {
+                                               InsetCommand & ref = dynamic_cast<InsetCommand &>(*itt);
+                                               if (ref.getParam("key") == oldkey)
+                                                       ref.setParam("key", newkey);
+                                       }
+                               }
+                       }
+                       break;
+               }
 
-       for (; fpit != fend; ++fpit) {
-               InsetList::const_iterator it = fpit->insetList().begin();
-               InsetList::const_iterator et = fpit->insetList().end();
-               for (; it != et; ++it)
-                               it->inset->setBuffer(const_cast<Buffer &>(buffer));
+               default:
+                       break; // nothing
+               }
        }
        insertion.swap(in.paragraphs());