#include "Buffer.h"
#include "BufferParams.h"
#include "buffer_funcs.h"
-#include "debug.h"
#include "DocIterator.h"
#include "Paragraph.h"
#include "ParagraphList.h"
#include "insets/Inset.h"
+#include "support/debug.h"
#include "support/limited_stack.h"
+#include <boost/assert.hpp>
+
#include <algorithm>
#include <ostream>
-using std::advance;
+using namespace std;
+using namespace lyx::support;
-namespace lyx {
+namespace lyx {
/**
These are the elements put on the undo stack. Each object contains complete
there is a lower limit: The StableDocIterator pointing stored in the undo
class must be valid after the changes, too, as it will used as a pointer
where to insert the stored bits when performining undo.
-
*/
+
+
struct UndoElement
{
/// Which kind of operation are we recording for?
struct Undo::Private
{
- Private(Buffer & buffer): buffer_(buffer) {}
+ Private(Buffer & buffer) : buffer_(buffer) {}
// Returns false if no undo possible.
bool textUndoOrRedo(DocIterator & cur, bool isUndoOperation);
};
-Undo::Undo(Buffer & buffer): d(new Undo::Private(buffer))
-{
-}
+/////////////////////////////////////////////////////////////////////
+//
+// Undo
+//
+/////////////////////////////////////////////////////////////////////
+
+
+Undo::Undo(Buffer & buffer)
+ : d(new Undo::Private(buffer))
+{}
Undo::~Undo()
}
-
-
-namespace {
-
-std::ostream & operator<<(std::ostream & os, UndoElement const & undo)
+static ostream & operator<<(ostream & os, UndoElement const & undo)
{
return os << " from: " << undo.from << " end: " << undo.end
<< " cell:\n" << undo.cell
}
-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;
}
-} // namespace anon
+/////////////////////////////////////////////////////////////////////
+//
+// Undo::Private
+//
+///////////////////////////////////////////////////////////////////////
void Undo::Private::doRecordUndo(UndoKind kind,
DocIterator const & cell,
bool isUndoOperation)
{
if (first_pit > last_pit)
- std::swap(first_pit, last_pit);
+ swap(first_pit, last_pit);
// create the position information of the Undo entry
UndoElement undo;
undo.array = 0;
// push the undo entry to undo stack
stack.push(undo);
- //lyxerr << "undo record: " << stack.top() << std::endl;
+ //lyxerr << "undo record: " << stack.top() << endl;
// next time we'll try again to combine entries if possible
undo_finished = false;
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;
+ // lyxerr << " " << i << ": " << buf.undostack()[i] << endl;
}
// This is a full document
otherstack.top().bparams = buffer_.params();
buffer_.params() = undo.bparams;
- std::swap(buffer_.paragraphs(), *undo.pars);
+ swap(buffer_.paragraphs(), *undo.pars);
delete undo.pars;
undo.pars = 0;
} else if (dit.inMathed()) {
{
DocIterator c = cur;
c.pop_back();
- d->doRecordUndo(kind, c, c.pit(), c.pit(), cur, false, true);
+ d->doRecordUndo(kind, c, c.pit(), c.pit(), cur, false, true);
}