1999-11-15 12:01:38 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-11-15 12:01:38 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-05-08 13:28:44 +00:00
|
|
|
#include "undo.h"
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
|
|
|
|
Undo::Undo(undo_kind kind_arg,
|
|
|
|
int number_before_arg, int number_behind_arg,
|
|
|
|
int cursor_par_arg, int cursor_pos_arg,
|
|
|
|
LyXParagraph * par_arg)
|
|
|
|
{
|
|
|
|
kind = kind_arg;
|
|
|
|
number_of_before_par = number_before_arg;
|
|
|
|
number_of_behind_par = number_behind_arg;
|
|
|
|
number_of_cursor_par = cursor_par_arg;
|
|
|
|
cursor_pos = cursor_pos_arg;
|
|
|
|
par = par_arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
Undo::~Undo()
|
|
|
|
{
|
|
|
|
LyXParagraph * tmppar;
|
|
|
|
while (par) {
|
|
|
|
tmppar = par;
|
|
|
|
par = par->next();
|
|
|
|
delete tmppar;
|
|
|
|
}
|
|
|
|
}
|
2000-01-06 02:44:26 +00:00
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2000-01-06 02:44:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool UndoStack::empty() const {
|
|
|
|
return stakk.empty();
|
|
|
|
}
|