1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file undo.h
|
|
|
|
|
* 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
|
|
|
|
|
2003-09-06 12:36:58 +00:00
|
|
|
|
#include "ParagraphList_fwd.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "support/types.h"
|
|
|
|
|
|
|
|
|
|
class LyXText;
|
|
|
|
|
class BufferView;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2003-07-25 19:18:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* These are the elements put on the undo stack. Each object
|
|
|
|
|
* contains complete paragraphs and sufficient information
|
2003-10-14 13:01:49 +00:00
|
|
|
|
* to restore the state.
|
2003-07-25 19:18:43 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
class Undo {
|
|
|
|
|
public:
|
2003-07-25 19:18:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* The undo kinds are 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
|
|
|
|
};
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// constructor
|
|
|
|
|
Undo(undo_kind kind, int text, int index,
|
|
|
|
|
int first_par, int end_par, int cursor_par, int cursor_pos);
|
2003-07-25 19:18:43 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// which kind of operation are we recording for?
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undo_kind kind;
|
2003-07-25 19:18:43 +00:00
|
|
|
|
|
2003-10-14 13:01:49 +00:00
|
|
|
|
/// hosting LyXText counted from buffer begin
|
|
|
|
|
int text;
|
2003-07-25 19:18:43 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// cell in a tabular or similar
|
|
|
|
|
int index;
|
2003-07-25 19:18:43 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// offset to the first paragraph in the paragraph list
|
|
|
|
|
int first_par;
|
2003-07-25 19:18:43 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// offset to the last paragraph from the end of parargraph list
|
|
|
|
|
int end_par;
|
|
|
|
|
|
|
|
|
|
/// offset to the first paragraph in the paragraph list
|
|
|
|
|
int cursor_par;
|
2003-06-04 07:14:05 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// the position of the cursor in the hosting paragraph
|
2003-07-25 19:18:43 +00:00
|
|
|
|
int cursor_pos;
|
2003-06-04 07:14:05 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// the contents of the paragraphs saved
|
2003-07-25 19:18:43 +00:00
|
|
|
|
ParagraphList pars;
|
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
|
2003-10-14 13:01:49 +00:00
|
|
|
|
bool textUndo(BufferView *);
|
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// this will redo the last undo - returns false if no redo possible
|
2003-10-14 13:01:49 +00:00
|
|
|
|
bool textRedo(BufferView *);
|
|
|
|
|
|
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();
|
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// whilst undo is frozen, all actions do not get added to the undo stack
|
2003-10-14 13:01:49 +00:00
|
|
|
|
void freezeUndo();
|
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// track undos again
|
2003-10-14 13:01:49 +00:00
|
|
|
|
void unFreezeUndo();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Record undo information - call with the first paragraph that will be changed
|
|
|
|
|
* and the last paragraph that will be changed. So we give an inclusive
|
|
|
|
|
* range.
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
void recordUndo(Undo::undo_kind kind,
|
|
|
|
|
LyXText const * text, lyx::paroffset_type first, lyx::paroffset_type last);
|
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// convienience: prepare undo when change in a single paragraph
|
2003-10-14 13:01:49 +00:00
|
|
|
|
void recordUndo(Undo::undo_kind kind,
|
|
|
|
|
LyXText const * text, lyx::paroffset_type par);
|
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// convienience: prepare undo for the paragraph that contains the cursor
|
2003-10-14 13:01:49 +00:00
|
|
|
|
void recordUndo(BufferView *, Undo::undo_kind kind);
|
2004-01-15 17:34:44 +00:00
|
|
|
|
void recordUndo(BufferView &, Undo::undo_kind kind);
|
2003-10-14 13:01:49 +00:00
|
|
|
|
|
2003-10-15 08:49:44 +00:00
|
|
|
|
/// are we avoiding tracking undos currently?
|
2003-10-14 13:01:49 +00:00
|
|
|
|
extern bool undo_frozen;
|
|
|
|
|
|
|
|
|
|
#endif // UNDO_FUNCS_H
|