]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.cpp
HTML for math fonts.
[lyx.git] / src / CutAndPaste.cpp
index 668d2b51ae11bfb44c3a7d9cf67466a69735c228..f70096b442c7fb48df84915efdd5cb603ea3451f 100644 (file)
@@ -29,7 +29,7 @@
 #include "InsetIterator.h"
 #include "InsetList.h"
 #include "Language.h"
-#include "LyXFunc.h"
+#include "LyX.h"
 #include "LyXRC.h"
 #include "Text.h"
 #include "Paragraph.h"
@@ -49,6 +49,7 @@
 #include "mathed/MathData.h"
 #include "mathed/InsetMath.h"
 #include "mathed/InsetMathHull.h"
+#include "mathed/InsetMathRef.h"
 #include "mathed/MathSupport.h"
 
 #include "support/debug.h"
@@ -242,16 +243,25 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                                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);
-                                               }
+                               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 =
+                                                       static_cast<InsetCommand &>(*itt);
+                                               if (ref.getParam("reference") == oldname)
+                                                       ref.setParam("reference", newname);
+                                       } else if (itt->lyxCode() == MATH_REF_CODE) {
+                                               InsetMathHull & mi =
+                                                       static_cast<InsetMathHull &>(*itt);
+                                               // this is necessary to prevent an uninitialized
+                                               // buffer when the RefInset is in a MathBox.
+                                               // FIXME audit setBuffer/updateBuffer calls
+                                               mi.setBuffer(const_cast<Buffer &>(buffer));
+                                               if (mi.asRefInset()->getTarget() == oldname)
+                                                       mi.asRefInset()->changeTarget(newname);
                                        }
                                }
                        }
@@ -264,14 +274,23 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                        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);
-                                       }
+                       if (oldname == newname)
+                               break;
+                       // adapt the references
+                       for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
+                               if (itt->lyxCode() == REF_CODE) {
+                                       InsetCommand & ref = static_cast<InsetCommand &>(*itt);
+                                       if (ref.getParam("reference") == oldname)
+                                               ref.setParam("reference", newname);
+                               } else if (itt->lyxCode() == MATH_REF_CODE) {
+                                       InsetMathHull & mi =
+                                               static_cast<InsetMathHull &>(*itt);
+                                       // this is necessary to prevent an uninitialized
+                                       // buffer when the RefInset is in a MathBox.
+                                       // FIXME audit setBuffer/updateBuffer calls
+                                       mi.setBuffer(const_cast<Buffer &>(buffer));
+                                       if (mi.asRefInset()->getTarget() == oldname)
+                                               mi.asRefInset()->changeTarget(newname);
                                }
                        }
                        break;
@@ -289,14 +308,16 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                        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);
-                                       }
+                       if (oldkey == newkey)
+                               break;
+                       // adapt the references
+                       for (InsetIterator itt = inset_iterator_begin(in);
+                            itt != i_end; ++itt) {
+                               if (itt->lyxCode() == CITE_CODE) {
+                                       InsetCommand & ref =
+                                               static_cast<InsetCommand &>(*itt);
+                                       if (ref.getParam("key") == oldkey)
+                                               ref.setParam("key", newkey);
                                }
                        }
                        break;
@@ -361,7 +382,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
        pit = last_paste;
        pos = pars[last_paste].size();
 
-       // FIXME Should we do it here, or should we let updateLabels() do it?
+       // FIXME Should we do it here, or should we let updateBuffer() do it?
        // Set paragraph buffers. It's important to do this right away
        // before something calls Inset::buffer() and causes a crash.
        for (pit_type p = startpit; p <= pit; ++p)
@@ -754,7 +775,7 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut)
 
                // need a valid cursor. (Lgb)
                cur.clearSelection();
-               cur.buffer()->updateLabels();
+               cur.buffer()->updateBuffer();
 
                // tell tabular that a recent copy happened
                dirtyTabularStack(false);
@@ -932,7 +953,7 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
 
                boost::tie(ppp, endpit) =
                        pasteSelectionHelper(cur, parlist, docclass, errorList);
-               cur.buffer()->updateLabels();
+               cur.buffer()->updateBuffer();
                cur.clearSelection();
                text->setCursor(cur, ppp.first, ppp.second);
        }