2001-06-25 00:06:33 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "undostack.h"
|
|
|
|
#include "undo.h"
|
|
|
|
#include "paragraph.h"
|
|
|
|
|
|
|
|
|
|
|
|
UndoStack::UndoStack()
|
|
|
|
: limit(100) {}
|
|
|
|
|
|
|
|
|
2001-12-13 17:19:53 +00:00
|
|
|
void UndoStack::pop()
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-12-13 17:19:53 +00:00
|
|
|
if (stakk.empty())
|
|
|
|
return;
|
2001-06-25 00:06:33 +00:00
|
|
|
stakk.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-13 17:19:53 +00:00
|
|
|
Undo * UndoStack::top() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-12-13 17:19:53 +00:00
|
|
|
if (stakk.empty())
|
|
|
|
return 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
return stakk.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UndoStack::~UndoStack()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UndoStack::clear()
|
|
|
|
{
|
|
|
|
while (!stakk.empty()) {
|
|
|
|
Undo * tmp = stakk.front();
|
|
|
|
stakk.pop_front();
|
|
|
|
delete tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UndoStack::SetStackLimit(Stakk::size_type l)
|
|
|
|
{
|
|
|
|
limit = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UndoStack::push(Undo * undo_arg)
|
|
|
|
{
|
2001-12-13 17:19:53 +00:00
|
|
|
if (!undo_arg)
|
|
|
|
return;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
stakk.push_front(undo_arg);
|
|
|
|
if (stakk.size() > limit) {
|
|
|
|
Undo * tmp = stakk.back();
|
|
|
|
stakk.pop_back();
|
|
|
|
delete tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-13 17:19:53 +00:00
|
|
|
bool UndoStack::empty() const
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return stakk.empty();
|
|
|
|
}
|