1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file Undo.h
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Asger Alstrup
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-10-14 13:01:49 +00:00
|
|
|
|
* \author John Levon
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2003-10-14 13:01:49 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-11-15 12:01:38 +00:00
|
|
|
|
|
|
|
|
|
#ifndef UNDO_H
|
|
|
|
|
#define UNDO_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DocIterator.h"
|
|
|
|
|
#include "BufferParams.h"
|
2004-03-08 21:14:45 +00:00
|
|
|
|
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "support/types.h"
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2005-07-14 22:09:22 +00:00
|
|
|
|
class BufferParams;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
class BufferView;
|
2006-12-30 15:05:15 +00:00
|
|
|
|
class DocIterator;
|
2007-04-26 14:56:30 +00:00
|
|
|
|
class Cursor;
|
2007-04-26 16:06:39 +00:00
|
|
|
|
class MathData;
|
2007-04-26 08:30:11 +00:00
|
|
|
|
class ParagraphList;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2004-02-03 08:56:28 +00:00
|
|
|
|
|
2003-07-25 19:18:43 +00:00
|
|
|
|
/**
|
2004-11-05 06:12:21 +00:00
|
|
|
|
These are the elements put on the undo stack. Each object contains complete
|
|
|
|
|
paragraphs from some cell and sufficient information to restore the cursor
|
|
|
|
|
state.
|
|
|
|
|
|
|
|
|
|
The cell is given by a DocIterator pointing to this cell, the 'interesting'
|
|
|
|
|
range of paragraphs by counting them from begin and end of cell,
|
|
|
|
|
respectively.
|
|
|
|
|
|
|
|
|
|
The cursor is also given as DocIterator and should point to some place in
|
|
|
|
|
the stored paragraph range. In case of math, we simply store the whole
|
|
|
|
|
cell, as there usually is just a simple paragraph in a cell.
|
|
|
|
|
|
|
|
|
|
The idea is to store the contents of 'interesting' paragraphs in some
|
|
|
|
|
structure ('Undo') _before_ it is changed in some edit operation.
|
|
|
|
|
Obviously, the stored ranged should be as small as possible. However, it
|
|
|
|
|
there is a lower limit: The StableDocIterator pointing stored in the undo
|
2005-01-19 15:03:31 +00:00
|
|
|
|
class must be valid after the changes, too, as it will used as a pointer
|
2004-11-26 14:52:54 +00:00
|
|
|
|
where to insert the stored bits when performining undo.
|
2004-11-05 06:12:21 +00:00
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
|
class Undo {
|
|
|
|
|
public:
|
2004-02-03 08:56:28 +00:00
|
|
|
|
/// This is used to combine consecutive undo recordings of the same kind.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
enum undo_kind {
|
2003-07-25 19:18:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* Insert something - these will combine to one big chunk
|
|
|
|
|
* when many inserts come after each other.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
INSERT,
|
2003-07-25 19:18:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* Delete something - these will combine to one big chunk
|
|
|
|
|
* when many deletes come after each other.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
DELETE,
|
2003-07-25 19:18:43 +00:00
|
|
|
|
/// Atomic - each of these will have its own entry in the stack
|
|
|
|
|
ATOMIC
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
2004-02-03 08:56:28 +00:00
|
|
|
|
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// Which kind of operation are we recording for?
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undo_kind kind;
|
2004-03-08 21:14:45 +00:00
|
|
|
|
/// the position of the cursor
|
2004-03-31 19:11:56 +00:00
|
|
|
|
StableDocIterator cursor;
|
2004-11-26 14:52:54 +00:00
|
|
|
|
/// the position of the cell described
|
2004-11-05 06:12:21 +00:00
|
|
|
|
StableDocIterator cell;
|
|
|
|
|
/// counted from begin of cell
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type from;
|
2004-03-08 21:14:45 +00:00
|
|
|
|
/// complement to end of this cell
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type end;
|
2004-11-05 06:12:21 +00:00
|
|
|
|
/// the contents of the saved Paragraphs (for texted)
|
2007-03-27 14:33:19 +00:00
|
|
|
|
ParagraphList * pars;
|
2007-04-26 16:06:39 +00:00
|
|
|
|
/// the contents of the saved MathData (for mathed)
|
|
|
|
|
MathData * array;
|
2005-07-14 22:09:22 +00:00
|
|
|
|
/// Only used in case of full backups
|
|
|
|
|
BufferParams bparams;
|
|
|
|
|
/// Only used in case of full backups
|
2006-04-05 23:56:29 +00:00
|
|
|
|
bool isFullBuffer;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// this will undo the last action - returns false if no undo possible
|
2004-11-05 06:12:21 +00:00
|
|
|
|
bool textUndo(BufferView & bv);
|
2003-10-14 13:01:49 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// this will redo the last undo - returns false if no redo possible
|
2004-11-05 06:12:21 +00:00
|
|
|
|
bool textRedo(BufferView & bv);
|
2003-10-14 13:01:49 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// makes sure the next operation will be stored
|
2003-10-14 13:01:49 +00:00
|
|
|
|
void finishUndo();
|
|
|
|
|
|
2004-02-03 08:56:28 +00:00
|
|
|
|
|
2003-10-14 13:01:49 +00:00
|
|
|
|
/**
|
2004-02-03 08:56:28 +00:00
|
|
|
|
* Record undo information - call with the current cursor and the 'other
|
|
|
|
|
* end' of the range of changed paragraphs. So we give an inclusive range.
|
2003-10-14 13:01:49 +00:00
|
|
|
|
* This is called before you make the changes to the paragraph, and it
|
|
|
|
|
* will record the original information of the paragraphs in the undo stack.
|
2005-10-12 18:44:53 +00:00
|
|
|
|
*
|
|
|
|
|
* FIXME: We need something to record undo in partial grids for mathed.
|
|
|
|
|
* Right now we use recordUndoInset if more than one cell is changed,
|
|
|
|
|
* but that puts the cursor in front of the inset after undo. We would need
|
|
|
|
|
* something like
|
2007-04-26 14:56:30 +00:00
|
|
|
|
* recordUndoGrid(Cursor & cur, Undo::undo_kind kind, idx_type from, idx_type to);
|
2005-10-12 18:44:53 +00:00
|
|
|
|
* and store the cell information in class Undo.
|
2003-10-14 13:01:49 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// The general case: prepare undo for an arbitrary range.
|
2007-04-26 14:56:30 +00:00
|
|
|
|
/// FIXME: replace Cursor with DocIterator. This is not possible right
|
2006-12-30 15:05:15 +00:00
|
|
|
|
/// now because we need access to Buffer->params()!.
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void recordUndo(Cursor & cur, Undo::undo_kind kind,
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type from, pit_type to);
|
2004-02-03 08:56:28 +00:00
|
|
|
|
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// Convenience: prepare undo for the range between 'from' and cursor.
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void recordUndo(Cursor & cur, Undo::undo_kind kind, pit_type from);
|
2004-02-03 08:56:28 +00:00
|
|
|
|
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// Convenience: prepare undo for the single paragraph or cell
|
|
|
|
|
/// containing the cursor
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void recordUndo(Cursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// Convenience: prepare undo for the inset containing the cursor
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void recordUndoInset(Cursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// Convenience: prepare undo for the selected paragraphs
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void recordUndoSelection(Cursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
2003-10-14 13:01:49 +00:00
|
|
|
|
|
2005-07-14 22:09:22 +00:00
|
|
|
|
/// Convenience: prepare undo for the whole buffer
|
|
|
|
|
void recordUndoFullDocument(BufferView * bv);
|
2003-10-14 13:01:49 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#endif // UNDO_FUNCS_H
|