]> git.lyx.org Git - lyx.git/blobdiff - src/Undo.cpp
* add PreBabelPreamble to Language definition (fixes #4786).
[lyx.git] / src / Undo.cpp
index c7684bb1fcf2bb65dee1d97e1a58fcfde82a7132..eec7ff446601aa8399956693e893aabe77c0fb61 100644 (file)
@@ -4,10 +4,10 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Asger Alstrup
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author John Levon
- * \author André Pönitz
- * \author Jürgen Vigna
+ * \author André Pönitz
+ * \author Jürgen Vigna
  * \author Abdelrazak Younes
  *
  * Full author contact details are available in file CREDITS.
@@ -71,9 +71,9 @@ struct UndoElement
                    StableDocIterator const & cel,
                    pit_type fro, pit_type en, ParagraphList * pl, 
                    MathData * ar, BufferParams const & bp, 
-                   bool ifb, size_t gid) :
+                   bool ifb, bool lc, size_t gid) :
                kind(kin), cursor(cur), cell(cel), from(fro), end(en),
-               pars(pl), array(ar), bparams(0), isFullBuffer(ifb), group_id(gid)
+               pars(pl), array(ar), bparams(0), isFullBuffer(ifb), lyx_clean(lc), group_id(gid)
        {
                if (isFullBuffer)
                        bparams = new BufferParams(bp);
@@ -91,6 +91,7 @@ struct UndoElement
                bparams = ue.isFullBuffer
                        ? new BufferParams(*ue.bparams) : ue.bparams;
                isFullBuffer = ue.isFullBuffer;
+               lyx_clean = ue.lyx_clean;
                group_id = ue.group_id;
        }
        ///
@@ -117,6 +118,8 @@ struct UndoElement
        BufferParams const * bparams;
        /// Only used in case of full backups
        bool isFullBuffer;
+       /// Was the buffer clean at this point?
+       bool lyx_clean;
        /// the element's group id
        size_t group_id;
 private:
@@ -163,6 +166,12 @@ public:
                }
        }
 
+       /// Mark all the elements of the stack as dirty
+       void markDirty() {
+               for (size_t i = 0; i != c_.size(); ++i)
+                       c_[i].lyx_clean = false;
+       }               
+
 private:
        /// Internal contents.
        std::deque<UndoElement> c_;
@@ -242,11 +251,11 @@ bool Undo::hasRedoStack() const
 }
 
 
-static bool samePar(StableDocIterator const & i1, StableDocIterator const & i2)
+void Undo::markDirty()
 {
-       StableDocIterator tmpi2 = i2;
-       tmpi2.pos() = i1.pos();
-       return i1 == tmpi2;
+       d->undo_finished_ = true;
+       d->undostack_.markDirty();
+       d->redostack_.markDirty();      
 }
 
 
@@ -256,6 +265,14 @@ static bool samePar(StableDocIterator const & i1, StableDocIterator const & i2)
 //
 ///////////////////////////////////////////////////////////////////////
 
+static bool samePar(StableDocIterator const & i1, StableDocIterator const & i2)
+{
+       StableDocIterator tmpi2 = i2;
+       tmpi2.pos() = i1.pos();
+       return i1 == tmpi2;
+}
+
+
 void Undo::Private::doRecordUndo(UndoKind kind,
        DocIterator const & cell,
        pit_type first_pit, pit_type last_pit,
@@ -291,12 +308,13 @@ void Undo::Private::doRecordUndo(UndoKind kind,
                LYXERR(Debug::UNDO, "Create undo element of group " << group_id);
        // create the position information of the Undo entry
        UndoElement undo(kind, cur, cell, from, end, 0, 0, 
-                        buffer_.params(), isFullBuffer, group_id);
+                        buffer_.params(), isFullBuffer, buffer_.isClean(), group_id);
 
        // fill in the real data to be saved
        if (cell.inMathed()) {
                // simply use the whole cell
-               undo.array = new MathData(cell.cell());
+               MathData & ar = cell.cell();
+               undo.array = new MathData(ar.buffer(), ar.begin(), ar.end());
        } else {
                // some more effort needed here as 'the whole cell' of the
                // main Text _is_ the whole document.
@@ -346,7 +364,7 @@ void Undo::Private::doTextUndoOrRedo(DocIterator & cur, UndoElementStack & stack
        // try to return early.
 
        // We will store in otherstack the part of the document under 'undo'
-       DocIterator cell_dit = undo.cell.asDocIterator(&buffer_.inset());
+       DocIterator cell_dit = undo.cell.asDocIterator(&buffer_);
 
        doRecordUndo(ATOMIC_UNDO, cell_dit,
                undo.from, cell_dit.lastpit() - undo.end, cur,
@@ -354,7 +372,7 @@ void Undo::Private::doTextUndoOrRedo(DocIterator & cur, UndoElementStack & stack
 
        // This does the actual undo/redo.
        //LYXERR0("undo, performing: " << undo);
-       DocIterator dit = undo.cell.asDocIterator(&buffer_.inset());
+       DocIterator dit = undo.cell.asDocIterator(&buffer_);
        if (undo.isFullBuffer) {
                LASSERT(undo.pars, /**/);
                // This is a full document
@@ -404,7 +422,11 @@ void Undo::Private::doTextUndoOrRedo(DocIterator & cur, UndoElementStack & stack
        LASSERT(undo.pars == 0, /**/);
        LASSERT(undo.array == 0, /**/);
 
-       cur = undo.cursor.asDocIterator(&buffer_.inset());
+       cur = undo.cursor.asDocIterator(&buffer_);
+       if (undo.lyx_clean)
+               buffer_.markClean();
+       else
+               buffer_.markDirty();
        // Now that we're done with undo, we pop it off the stack.
        stack.pop();
 }
@@ -426,8 +448,8 @@ bool Undo::Private::textUndoOrRedo(DocIterator & cur, bool isUndoOperation)
        while (!stack.empty() && stack.top().group_id == gid)
                doTextUndoOrRedo(cur, stack, otherstack);
 
-       // Addapt the new material to current buffer.
-       updateLabels(buffer_);
+       // Adapt the new material to current buffer.
+       buffer_.setBuffersForInsets(); // FIXME This shouldn't be here.
        return true;
 }
 
@@ -509,7 +531,7 @@ void Undo::recordUndoFullDocument(DocIterator const & cur)
        beginUndoGroup();
        d->doRecordUndo(
                ATOMIC_UNDO,
-               doc_iterator_begin(d->buffer_.inset()),
+               doc_iterator_begin(&d->buffer_),
                0, d->buffer_.paragraphs().size() - 1,
                cur,
                true,