]> git.lyx.org Git - features.git/commitdiff
Backport various parts of the fix for #7655. This include r39211, r39250, and r39251.
authorRichard Heck <rgheck@comcast.net>
Mon, 5 Sep 2011 19:09:14 +0000 (19:09 +0000)
committerRichard Heck <rgheck@comcast.net>
Mon, 5 Sep 2011 19:09:14 +0000 (19:09 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39598 a592a061-630c-0410-9148-cb99ea01b6c8

src/CutAndPaste.cpp
src/insets/InsetInclude.cpp
src/insets/InsetLabel.cpp
src/insets/InsetLabel.h
src/mathed/InsetMathHull.cpp
status.20x

index 2bac66f8a6db2d2fe4d72f078fe13c20f6b10bbd..c1dc097592492fdb353b237261994a3d8bb13ff6 100644 (file)
@@ -227,7 +227,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist,
        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, e.g., InsetLabel::updateCommand() is going to try to access
+               // since some inset might going to try to access
                // the buffer() member.
                it->setBuffer(const_cast<Buffer &>(buffer));
                switch (it->lyxCode()) {
@@ -241,7 +241,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist,
                                        continue;
                                InsetLabel * lab = labels[i];
                                docstring const oldname = lab->getParam("name");
-                               lab->updateCommand(oldname, false);
+                               lab->updateLabel(oldname);
                                // We need to update the buffer reference cache.
                                cur.forceBufferUpdate();
                                docstring const newname = lab->getParam("name");
@@ -272,7 +272,7 @@ pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist,
                        // check for duplicates
                        InsetLabel & lab = static_cast<InsetLabel &>(*it);
                        docstring const oldname = lab.getParam("name");
-                       lab.updateCommand(oldname, false);
+                       lab.updateLabel(oldname);
                        // We need to update the buffer reference cache.
                        cur.forceBufferUpdate();
                        docstring const newname = lab.getParam("name");
index e5d01f68487d56e2a95c663df0249619cb445240..324b4a07628f9ae9f6fff7c503fdebe9ce06daa2 100644 (file)
@@ -271,7 +271,7 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
                                        }                                       
 
                                        if (new_label != old_label) {
-                                               label_->updateCommand(new_label);
+                                               label_->updateLabelAndRefs(new_label, &cur);
                                                // the label might have been adapted (duplicate)
                                                if (new_label != label_->getParam("name")) {
                                                        new_params.addParam("label", "{" + 
@@ -1096,7 +1096,7 @@ void InsetInclude::updateCommand()
                return;
 
        docstring old_label = label_->getParam("name");
-       label_->updateCommand(old_label, false);
+       label_->updateLabel(old_label);
        // the label might have been adapted (duplicate)
        docstring new_label = label_->getParam("name");
        if (old_label == new_label)
@@ -1111,6 +1111,7 @@ void InsetInclude::updateCommand()
        setParams(p);   
 }
 
+
 void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype)
 {
        Buffer const * const childbuffer = getChildBuffer();
index 6f2e9f59ce295f7f0c22050dcc22e4842e419647..7bff3d7c6e82ba722223127cf44e9a1083709cfc 100644 (file)
@@ -55,46 +55,71 @@ InsetLabel::InsetLabel(Buffer * buf, InsetCommandParams const & p)
 
 void InsetLabel::initView()
 {
-       updateCommand(getParam("name"));
+       // FIXME: This seems to be used only for inset creation so
+       // we probably just need to call updateLabel() here.
+       updateLabelAndRefs(getParam("name"));
 }
 
 
-void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
+void InsetLabel::uniqueLabel(docstring & label) const
 {
-       docstring const old_label = getParam("name");
-       docstring label = new_label;
+       docstring const new_label = label;
        int i = 1;
        while (buffer().insetLabel(label)) {
                label = new_label + '-' + convert<docstring>(i);
                ++i;
        }
-
        if (label != new_label) {
                // Warn the user that the label has been changed to something else.
                frontend::Alert::warning(_("Label names must be unique!"),
                        bformat(_("The label %1$s already exists,\n"
                        "it will be changed to %2$s."), new_label, label));
        }
+}
+
+
+void InsetLabel::updateLabel(docstring const & new_label)
+{
+       docstring label = new_label;
+       uniqueLabel(label);
+       setParam("name", label);
+}
+
+
+void InsetLabel::updateLabelAndRefs(docstring const & new_label,
+               Cursor * cursor)
+{
+       docstring const old_label = getParam("name");
+       docstring label = new_label;
+       uniqueLabel(label);
+       if (label == old_label)
+               return;
 
        buffer().undo().beginUndoGroup();
+       if (cursor)
+               cursor->recordUndo();
        setParam("name", label);
+       updateReferences(old_label, label);
+       buffer().undo().endUndoGroup();
+}
 
-       if (updaterefs) {
-               Buffer::References & refs = buffer().references(old_label);
-               Buffer::References::iterator it = refs.begin();
-               Buffer::References::iterator end = refs.end();
-               for (; it != end; ++it) {
-                       buffer().undo().recordUndo(it->second);
-                       if (it->first->lyxCode() == MATH_REF_CODE) {
-                               InsetMathHull * mi = it->first->asInsetMath()->asHullInset();
-                               mi->asRefInset()->changeTarget(label);
-                       } else {
-                               InsetCommand * ref = it->first->asInsetCommand();
-                               ref->setParam("reference", label);
-                       }
+
+void InsetLabel::updateReferences(docstring const & old_label,
+               docstring const & new_label)
+{
+       Buffer::References & refs = buffer().references(old_label);
+       Buffer::References::iterator it = refs.begin();
+       Buffer::References::iterator end = refs.end();
+       for (; it != end; ++it) {
+               buffer().undo().recordUndo(it->second);
+               if (it->first->lyxCode() == MATH_REF_CODE) {
+                       InsetMathHull * mi = it->first->asInsetMath()->asHullInset();
+                       mi->asRefInset()->changeTarget(new_label);
+               } else {
+                       InsetCommand * ref = it->first->asInsetCommand();
+                       ref->setParam("reference", new_label);
                }
        }
-       buffer().undo().endUndoGroup();
 }
 
 
@@ -197,8 +222,8 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
                        break;
                }
                if (p["name"] != params()["name"]) {
-                       // undo is handled in updateCommand
-                       updateCommand(p["name"]);
+                       // undo is handled in updateLabelAndRefs
+                       updateLabelAndRefs(p["name"], &cur);
                }
                cur.forceBufferUpdate();
                break;
index 35e8f4ba953a3a857a4b7491e9ea3f3a5466fa24..61bcc1f3109d052835f4c2f5d2b66256bf4a7e84 100644 (file)
@@ -31,8 +31,11 @@ public:
        docstring const & counterValue() const { return counter_value_; }
        ///
        docstring const & prettyCounter() const { return pretty_counter_; }
-       ///
-       void updateCommand(docstring const & new_label, bool updaterefs = true);
+       /// Updates only the label string, doesn't handle undo nor references.
+       void updateLabel(docstring const & new_label);
+       /// Updates the label and the references to it.
+       /// Will also handle undo/redo if \p cursor is passed.
+       void updateLabelAndRefs(docstring const & new_label, Cursor * cursor = 0);
 
        /// \name Public functions inherited from Inset class
        //@{
@@ -85,6 +88,11 @@ private:
        void doDispatch(Cursor & cur, FuncRequest & cmd);
        //@}
 
+       ///
+       void uniqueLabel(docstring & label) const;
+       ///
+       void updateReferences(docstring const & old_label,
+               docstring const & new_label);
        ///
        docstring screen_label_;
        ///
index 4570332a9ac7559e3537c33b45d66175c4e5afd6..50fb014dc4acbb85da72f72d483a2d7dc17098d8 100644 (file)
@@ -663,7 +663,7 @@ void InsetMathHull::label(row_type row, docstring const & label)
                        label_[row] = dummy_pointer;
                } else {
                        if (buffer_)
-                               label_[row]->updateCommand(label);
+                               label_[row]->updateLabelAndRefs(label);
                        else
                                label_[row]->setParam("name", label);
                }
index 4eaab6f8dd797f7f4a05a3b4f12c5b8771afd1f0..b6eb2151724ee1c7cd066db3322ac839453c051d 100644 (file)
@@ -61,6 +61,9 @@ What's new
 
 - Repair broken outliner display for broken references (bug 7708).
 
+- Mark buffer dirty when a label is changed, so the file can be saved and
+  the change can be reverted (bug 7655).
+
 
 * ADVANCED FIND AND REPLACE