On 01/28/2010 08:29 AM, [email protected] wrote:
Author: spitz
Date: Thu Jan 28 08:29:57 2010
New Revision: 33239
URL: http://www.lyx.org/trac/changeset/33239

Log:
When pasting a math inset with a label, check for duplicates (as we do outside 
math)
(bug 6218)

Modified:
    lyx-devel/branches/BRANCH_1_6_X/src/CutAndPaste.cpp
    lyx-devel/branches/BRANCH_1_6_X/src/mathed/InsetMathHull.h
    lyx-devel/branches/BRANCH_1_6_X/status.16x

Modified: lyx-devel/branches/BRANCH_1_6_X/src/CutAndPaste.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/CutAndPaste.cpp Wed Jan 27 20:17:18 
2010        (r33238)
+++ lyx-devel/branches/BRANCH_1_6_X/src/CutAndPaste.cpp Thu Jan 28 08:29:57 
2010        (r33239)
@@ -42,10 +42,12 @@
  #include "insets/InsetGraphics.h"
  #include "insets/InsetGraphicsParams.h"
  #include "insets/InsetInclude.h"
+#include "insets/InsetLabel.h"
  #include "insets/InsetTabular.h"

  #include "mathed/MathData.h"
  #include "mathed/InsetMath.h"
+#include "mathed/InsetMathHull.h"
  #include "mathed/MathSupport.h"

  #include "support/debug.h"
@@ -231,6 +233,33 @@

                switch (it->lyxCode()) {

+               case MATH_CODE: {
+                       // check for equation labels and resolve duplicates
+                       InsetMathHull&  ins = static_cast<InsetMathHull&>(*it);
+                       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->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);

I don't think you need a dynamic cast. And if you need it, you should use a pointer instead and check it id null.

+                                                       if 
(ref.getParam("reference") == oldname)
+                                                               
ref.setParam("reference", newname);


Ouch, that's 7 level of indentation! I suggest that you use "continue" instead:

        if (oldname == newname)
                continue;

and
        if (itt->lyxCode() != REF_CODE)
                continue;



+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               }
+               
                case LABEL_CODE: {
                        // check for duplicates
                        InsetCommand&  lab = static_cast<InsetCommand&>(*it);

Modified: lyx-devel/branches/BRANCH_1_6_X/src/mathed/InsetMathHull.h
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/mathed/InsetMathHull.h  Wed Jan 27 
20:17:18 2010        (r33238)
+++ lyx-devel/branches/BRANCH_1_6_X/src/mathed/InsetMathHull.h  Thu Jan 28 
08:29:57 2010        (r33239)
@@ -58,6 +58,8 @@
        ///
        void label(row_type row, docstring const&  label);
        ///
+       std::vector<InsetLabel *>  getLabels() { return label_; }

Hum, maybe:

std::vector<InsetLabel *> const & getLabels() const { return label_; }

The InsetLabel pointers themselves should remain modifiable.

Abdel.

Reply via email to