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
|
|
|
|
|
2004-03-08 21:14:45 +00:00
|
|
|
|
#include "dociterator.h"
|
2004-04-03 08:37:12 +00:00
|
|
|
|
#include "ParagraphList_fwd.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>
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
class LCursor;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
class BufferView;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2004-02-03 08:56:28 +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
|
|
|
|
*/
|
2004-03-01 17:12:09 +00:00
|
|
|
|
struct Undo {
|
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-03-08 21:14:45 +00:00
|
|
|
|
/// counted from begin of buffer
|
2004-03-25 09:16:36 +00:00
|
|
|
|
lyx::par_type from;
|
2004-03-08 21:14:45 +00:00
|
|
|
|
/// complement to end of this cell
|
2004-03-25 09:16:36 +00:00
|
|
|
|
lyx::par_type end;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// the contents of the saved paragraphs (for texted)
|
2003-07-25 19:18:43 +00:00
|
|
|
|
ParagraphList pars;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// the contents of the saved matharray (for mathed)
|
|
|
|
|
std::string array;
|
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-02-03 08:56:28 +00:00
|
|
|
|
bool textUndo(BufferView &);
|
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-02-03 08:56:28 +00:00
|
|
|
|
bool textRedo(BufferView &);
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// The general case: prepare undo for an arbitrary range.
|
2004-02-03 08:56:28 +00:00
|
|
|
|
void recordUndo(LCursor & cur, Undo::undo_kind kind,
|
2004-03-25 09:16:36 +00:00
|
|
|
|
lyx::par_type from, lyx::par_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.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::par_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
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// Convenience: prepare undo for the inset containing the cursor
|
|
|
|
|
void recordUndoInset(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
|
|
|
|
/// Convenience: prepare undo for the selected paragraphs
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void recordUndoSelection(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
2003-10-14 13:01:49 +00:00
|
|
|
|
|
2004-04-18 19:41:40 +00:00
|
|
|
|
/// Convenience: prepare undo for the single paragraph containing the cursor
|
2004-02-03 08:56:28 +00:00
|
|
|
|
void recordUndoFullDocument(LCursor & cur);
|
2003-10-14 13:01:49 +00:00
|
|
|
|
|
|
|
|
|
#endif // UNDO_FUNCS_H
|