]> git.lyx.org Git - lyx.git/blobdiff - src/Undo.cpp
Cleanup mouse/selection/context-menu interactions.
[lyx.git] / src / Undo.cpp
index 74e8cbc2c3d9453c70388320d9ec282031109df1..9c800adfe994425e7c3651774c8664aee9e044e0 100644 (file)
@@ -20,7 +20,6 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "buffer_funcs.h"
-#include "support/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 namespace std;
+using namespace lyx::support;
 
-namespace lyx {
 
+namespace lyx {
 
 /**
 These are the elements put on the undo stack. Each object contains complete
@@ -60,8 +63,9 @@ Obviously, the stored ranged should be as small as possible. However, it
 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?
@@ -87,7 +91,7 @@ struct UndoElement
 
 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);
@@ -118,9 +122,16 @@ struct Undo::Private
 };
 
 
-Undo::Undo(Buffer & buffer): d(new Undo::Private(buffer))
-{
-}
+/////////////////////////////////////////////////////////////////////
+//
+// Undo
+//
+/////////////////////////////////////////////////////////////////////
+
+
+Undo::Undo(Buffer & buffer)
+       : d(new Undo::Private(buffer))
+{}
 
 
 Undo::~Undo()
@@ -141,11 +152,7 @@ bool Undo::hasRedoStack() const
 }
 
 
-
-
-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
@@ -153,15 +160,19 @@ std::ostream & operator<<(std::ostream & os, UndoElement const & undo)
 }
 
 
-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,
@@ -171,7 +182,7 @@ void Undo::Private::doRecordUndo(UndoKind kind,
        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;
@@ -222,7 +233,7 @@ void Undo::Private::doRecordUndo(UndoKind kind,
 
        // 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;
@@ -242,7 +253,7 @@ void Undo::Private::recordUndo(UndoKind kind, DocIterator & cur,
        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;
 }
 
 
@@ -280,7 +291,7 @@ bool Undo::Private::textUndoOrRedo(DocIterator & cur, bool isUndoOperation)
                // 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()) {
@@ -362,7 +373,7 @@ void Undo::recordUndoInset(DocIterator & cur, UndoKind kind)
 {
        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);
 }