X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FUndo.cpp;h=eec7ff446601aa8399956693e893aabe77c0fb61;hb=604a3341d9bd6b6bee6f042292f28b89027ca2b5;hp=a0e84e43ec7ccdfd4a2bc209bab2d97e90ec82c5;hpb=f1cba8ff64b369792fd49f5ddf90e8126ab476ac;p=lyx.git diff --git a/src/Undo.cpp b/src/Undo.cpp index a0e84e43ec..eec7ff4466 100644 --- a/src/Undo.cpp +++ b/src/Undo.cpp @@ -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 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,