1999-11-15 12:01:38 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "undo.h"
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
UndoStack::UndoStack()
|
|
|
|
: limit(100) {}
|
|
|
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
Undo * UndoStack::pop()
|
1999-11-15 12:01:38 +00:00
|
|
|
{
|
|
|
|
if (stakk.empty()) return 0;
|
|
|
|
Undo * result = stakk.front();
|
|
|
|
stakk.pop_front();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
Undo * UndoStack::top()
|
1999-11-15 12:01:38 +00:00
|
|
|
{
|
|
|
|
if (stakk.empty()) return 0;
|
|
|
|
return stakk.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UndoStack::~UndoStack()
|
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
clear();
|
1999-11-15 12:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
void UndoStack::clear()
|
1999-11-15 12:01:38 +00:00
|
|
|
{
|
|
|
|
while (!stakk.empty()) {
|
|
|
|
Undo * tmp = stakk.front();
|
|
|
|
stakk.pop_front();
|
|
|
|
delete tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UndoStack::SetStackLimit(Stakk::size_type l)
|
|
|
|
{
|
|
|
|
limit = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
void UndoStack::push(Undo * undo_arg)
|
1999-11-15 12:01:38 +00:00
|
|
|
{
|
|
|
|
if (!undo_arg) return;
|
|
|
|
|
|
|
|
stakk.push_front(undo_arg);
|
|
|
|
if (stakk.size() > limit) {
|
|
|
|
Undo * tmp = stakk.back();
|
|
|
|
stakk.pop_back();
|
|
|
|
delete tmp;
|
|
|
|
}
|
|
|
|
}
|