]> git.lyx.org Git - lyx.git/blobdiff - src/Undo.cpp
adjust
[lyx.git] / src / Undo.cpp
index 3d0f2ed093554af5ac27652216e05d2237039ef3..8b6af363018472d4ab5ac4ff2b419dfb073bd588 100644 (file)
 #include "Cursor.h"
 #include "debug.h"
 #include "BufferView.h"
-#include "LyXText.h"
+#include "Text.h"
 #include "Paragraph.h"
 #include "ParagraphList.h"
 
 #include "mathed/MathSupport.h"
-#include "mathed/MathArray.h"
+#include "mathed/MathData.h"
 
 #include "insets/Inset.h"
 
@@ -101,12 +101,12 @@ void doRecordUndo(Undo::undo_kind kind,
        // fill in the real data to be saved
        if (cell.inMathed()) {
                // simply use the whole cell
-               undo.array = new MathArray(cell.cell());
+               undo.array = new MathData(cell.cell());
        } else {
                // some more effort needed here as 'the whole cell' of the
-               // main LyXText _is_ the whole document.
+               // main Text _is_ the whole document.
                // record the relevant paragraphs
-               LyXText const * text = cell.text();
+               Text const * text = cell.text();
                BOOST_ASSERT(text);
                ParagraphList const & plist = text->paragraphs();
                ParagraphList::const_iterator first = plist.begin();
@@ -133,7 +133,7 @@ void recordUndo(Undo::undo_kind kind,
        BOOST_ASSERT(last_pit <= cur.lastpit());
 
        doRecordUndo(kind, cur, first_pit, last_pit, cur,
-               cur.bv().buffer()->params(), false, stack);
+               cur.bv().buffer().params(), false, stack);
 }
 
 
@@ -154,8 +154,8 @@ bool textUndoOrRedo(BufferView & bv,
        stack.pop();
 
        // We will store in otherstack the part of the document under 'undo'
-       Buffer * buf = bv.buffer();
-       DocIterator cell_dit = undo.cell.asDocIterator(&buf->inset());
+       Buffer & buf = bv.buffer();
+       DocIterator cell_dit = undo.cell.asDocIterator(&buf.inset());
 
        doRecordUndo(Undo::ATOMIC, cell_dit,
                   undo.from, cell_dit.lastpit() - undo.end, bv.cursor(),
@@ -164,13 +164,14 @@ bool textUndoOrRedo(BufferView & bv,
 
        // This does the actual undo/redo.
        //lyxerr << "undo, performing: " << undo << std::endl;
-       DocIterator dit = undo.cell.asDocIterator(&buf->inset());
+       bool labelsUpdateNeeded = false;
+       DocIterator dit = undo.cell.asDocIterator(&buf.inset());
        if (undo.isFullBuffer) {
                BOOST_ASSERT(undo.pars);
                // This is a full document
-               otherstack.top().bparams = buf->params();
-               buf->params() = undo.bparams;
-               std::swap(buf->paragraphs(), *undo.pars);
+               otherstack.top().bparams = buf.params();
+               buf.params() = undo.bparams;
+               std::swap(buf.paragraphs(), *undo.pars);
                delete undo.pars;
                undo.pars = 0;
        } else if (dit.inMathed()) {
@@ -184,7 +185,7 @@ bool textUndoOrRedo(BufferView & bv,
                undo.array = 0;
        } else {
                // Some finer machinery is needed here.
-               LyXText * text = dit.text();
+               Text * text = dit.text();
                BOOST_ASSERT(text);
                BOOST_ASSERT(undo.pars);
                ParagraphList & plist = text->paragraphs();
@@ -209,19 +210,21 @@ bool textUndoOrRedo(BufferView & bv,
                plist.insert(first, undo.pars->begin(), undo.pars->end());
                delete undo.pars;
                undo.pars = 0;
-               updateLabels(*buf);
+               labelsUpdateNeeded = true;
        }
        BOOST_ASSERT(undo.pars == 0);
        BOOST_ASSERT(undo.array == 0);
 
        // Set cursor
        Cursor & cur = bv.cursor();
-       cur.setCursor(undo.cursor.asDocIterator(&buf->inset()));
+       cur.setCursor(undo.cursor.asDocIterator(&buf.inset()));
        cur.selection() = false;
        cur.resetAnchor();
        cur.fixIfBroken();
+       
+       if (labelsUpdateNeeded)
+               updateLabels(buf);
        finishUndo();
-
        return true;
 }
 
@@ -237,27 +240,27 @@ void finishUndo()
 
 bool textUndo(BufferView & bv)
 {
-       return textUndoOrRedo(bv, bv.buffer()->undostack(),
-                             bv.buffer()->redostack());
+       return textUndoOrRedo(bv, bv.buffer().undostack(),
+                             bv.buffer().redostack());
 }
 
 
 bool textRedo(BufferView & bv)
 {
-       return textUndoOrRedo(bv, bv.buffer()->redostack(),
-                             bv.buffer()->undostack());
+       return textUndoOrRedo(bv, bv.buffer().redostack(),
+                             bv.buffer().undostack());
 }
 
 
 void recordUndo(Undo::undo_kind kind,
        Cursor & cur, pit_type first, pit_type last)
 {
-       Buffer * buf = cur.bv().buffer();
-       recordUndo(kind, cur, first, last, buf->undostack());
-       buf->redostack().clear();
+       Buffer & buf = cur.bv().buffer();
+       recordUndo(kind, cur, first, last, buf.undostack());
+       buf.redostack().clear();
        //lyxerr << "undostack:\n";
-       //for (size_t i = 0, n = buf->undostack().size(); i != n && i < 6; ++i)
-       //      lyxerr << "  " << i << ": " << buf->undostack()[i] << std::endl;
+       //for (size_t i = 0, n = buf.undostack().size(); i != n && i < 6; ++i)
+       //      lyxerr << "  " << i << ": " << buf.undostack()[i] << std::endl;
 }
 
 
@@ -271,9 +274,9 @@ void recordUndoInset(Cursor & cur, Undo::undo_kind kind)
 {
        Cursor c = cur;
        c.pop();
-       Buffer * buf = cur.bv().buffer();
+       Buffer & buf = cur.bv().buffer();
        doRecordUndo(kind, c, c.pit(), c.pit(), cur,
-                    buf->params(), false, buf->undostack());
+                    buf.params(), false, buf.undostack());
 }
 
 
@@ -298,15 +301,15 @@ void recordUndo(Cursor & cur, Undo::undo_kind kind,
 
 void recordUndoFullDocument(BufferView * bv)
 {
-       Buffer * buf = bv->buffer();
+       Buffer & buf = bv->buffer();
        doRecordUndo(
                Undo::ATOMIC,
-               doc_iterator_begin(buf->inset()),
-               0, buf->paragraphs().size() - 1,
+               doc_iterator_begin(buf.inset()),
+               0, buf.paragraphs().size() - 1,
                bv->cursor(),
-               buf->params(),
+               buf.params(),
                true,
-               buf->undostack()
+               buf.undostack()
        );
        undo_finished = false;
 }