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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-10-14 13:01:49 +00:00
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
|
|
|
* \author Jürgen Vigna
|
2007-10-18 11:51:17 +00:00
|
|
|
* \author Abdelrazak Younes
|
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-10-14 13:01:49 +00:00
|
|
|
#include "support/types.h"
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
class Buffer;
|
2012-07-15 16:16:09 +00:00
|
|
|
class CursorData;
|
2010-11-29 09:47:46 +00:00
|
|
|
class Inset;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
/// This is used to combine consecutive undo recordings of the same kind.
|
|
|
|
enum UndoKind {
|
|
|
|
/**
|
|
|
|
* Insert something - these will combine to one big chunk
|
|
|
|
* when many inserts come after each other.
|
|
|
|
*/
|
|
|
|
INSERT_UNDO,
|
|
|
|
/**
|
|
|
|
* Delete something - these will combine to one big chunk
|
|
|
|
* when many deletes come after each other.
|
|
|
|
*/
|
|
|
|
DELETE_UNDO,
|
|
|
|
/// Atomic - each of these will have its own entry in the stack
|
|
|
|
ATOMIC_UNDO
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
class Undo
|
|
|
|
{
|
2015-09-20 17:43:06 +00:00
|
|
|
/// noncopyable
|
|
|
|
Undo(Undo const &);
|
|
|
|
void operator=(Undo const &);
|
2007-10-18 11:51:17 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
Undo(Buffer &);
|
|
|
|
|
|
|
|
~Undo();
|
|
|
|
|
2011-01-09 17:55:16 +00:00
|
|
|
/// Clear out all undo/redo contents.
|
|
|
|
void clear();
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
/// this will undo the last action - returns false if no undo possible
|
2018-08-26 14:47:25 +00:00
|
|
|
bool undoAction(CursorData &);
|
2003-10-14 13:01:49 +00:00
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
/// this will redo the last undo - returns false if no redo possible
|
2018-08-26 14:47:25 +00:00
|
|
|
bool redoAction(CursorData &);
|
2004-02-03 08:56:28 +00:00
|
|
|
|
2008-09-17 15:15:12 +00:00
|
|
|
/// End a sequence of INSERT_UNDO or DELETE_UNDO type of undo
|
2008-09-17 21:26:54 +00:00
|
|
|
/// operations (grouping of consecutive characters insertion/deletion).
|
2007-10-18 11:51:17 +00:00
|
|
|
void finishUndo();
|
2004-02-03 08:56:28 +00:00
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
///
|
|
|
|
bool hasUndoStack() const;
|
|
|
|
///
|
|
|
|
bool hasRedoStack() const;
|
|
|
|
|
2010-08-06 23:54:04 +00:00
|
|
|
/// Mark all the elements of the undo and redo stacks as dirty
|
|
|
|
void markDirty();
|
|
|
|
|
2008-09-25 14:02:14 +00:00
|
|
|
/// open a new group of undo operations.
|
2008-09-25 13:59:26 +00:00
|
|
|
/**
|
|
|
|
* Groups can be nested. Such a nested group e.g. { {} {} } is undone in
|
|
|
|
* a single step. This means you can add a group whenever you are not sure.
|
|
|
|
*/
|
2008-08-15 19:24:56 +00:00
|
|
|
void beginUndoGroup();
|
2015-07-16 12:13:13 +00:00
|
|
|
/// open a new group as above and specify a cursor to set as cur_before
|
|
|
|
/// of the group's undo elements.
|
|
|
|
/**
|
|
|
|
* This cursor takes precedence over what is passed to recordUndo.
|
|
|
|
* In the case of nested groups, only the first cur_before is
|
2015-09-25 16:14:53 +00:00
|
|
|
* taken into account. The cursor is reset at the end of the
|
2015-07-16 12:13:13 +00:00
|
|
|
* top-level group.
|
|
|
|
*/
|
|
|
|
void beginUndoGroup(CursorData const & cur_before);
|
2008-09-17 15:15:12 +00:00
|
|
|
/// end the current undo group.
|
2008-08-15 19:24:56 +00:00
|
|
|
void endUndoGroup();
|
2012-02-07 14:56:16 +00:00
|
|
|
/// end the current undo group and set UndoElement::cur_after if necessary.
|
2015-07-16 12:13:13 +00:00
|
|
|
void endUndoGroup(CursorData const & cur_after);
|
2019-04-15 09:12:25 +00:00
|
|
|
/// end abruptly the current group and create a new one wih the same nesting level
|
|
|
|
void splitUndoGroup(CursorData const & cur);
|
2018-05-31 21:15:40 +00:00
|
|
|
/// return true if an undo group is open and contains at least one element
|
|
|
|
bool activeUndoGroup() const;
|
2012-02-07 14:56:16 +00:00
|
|
|
|
2008-09-17 15:15:12 +00:00
|
|
|
/// The general case: record undo information for an arbitrary range.
|
|
|
|
/**
|
|
|
|
* Record undo information - call with the current cursor and
|
|
|
|
* the 'other end' of the range of changed paragraphs. 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.
|
2015-03-12 14:57:29 +00:00
|
|
|
* Kind of undo is always ATOMIC_UNDO.
|
2008-09-17 15:15:12 +00:00
|
|
|
*/
|
2015-03-12 14:57:29 +00:00
|
|
|
void recordUndo(CursorData const & cur, pit_type from, pit_type to);
|
2007-10-18 11:51:17 +00:00
|
|
|
|
2008-09-17 15:15:12 +00:00
|
|
|
/// Convenience: record undo information for the single
|
|
|
|
/// paragraph or cell containing the cursor.
|
2012-07-15 16:16:09 +00:00
|
|
|
void recordUndo(CursorData const & cur, UndoKind kind = ATOMIC_UNDO);
|
2008-09-17 15:15:12 +00:00
|
|
|
|
2015-05-20 10:09:12 +00:00
|
|
|
/// prepare undo for the inset containing the cursor
|
|
|
|
void recordUndoInset(CursorData const & cur, Inset const * inset);
|
|
|
|
|
2015-01-17 19:38:22 +00:00
|
|
|
/// Convenience: record undo for buffer parameters
|
|
|
|
void recordUndoBufferParams(CursorData const & cur);
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
/// Convenience: prepare undo for the whole buffer
|
2015-01-17 19:38:22 +00:00
|
|
|
void recordUndoFullBuffer(CursorData const & cur);
|
2007-10-18 11:51:17 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Private;
|
|
|
|
Private * const d;
|
|
|
|
};
|
2003-10-14 13:01:49 +00:00
|
|
|
|
|
|
|
|
2015-05-21 14:49:19 +00:00
|
|
|
/** Helper class to simplify the use of undo groups across several buffers.
|
|
|
|
*
|
|
|
|
* The undo group is created when the object is instanciated; it is
|
|
|
|
* then ended as the object goes out of scope or the buffer is reset
|
|
|
|
* (see below)
|
|
|
|
*/
|
|
|
|
class UndoGroupHelper {
|
|
|
|
public:
|
2020-09-23 15:28:36 +00:00
|
|
|
UndoGroupHelper(Buffer * buf);
|
2015-05-21 14:49:19 +00:00
|
|
|
|
2017-11-29 13:10:33 +00:00
|
|
|
~UndoGroupHelper();
|
2015-05-21 14:49:19 +00:00
|
|
|
|
|
|
|
/** Close the current undo group if necessary and create a new one
|
|
|
|
* for buffer \c buf.
|
|
|
|
*/
|
|
|
|
void resetBuffer(Buffer * buf);
|
|
|
|
|
|
|
|
private:
|
2017-11-29 13:10:33 +00:00
|
|
|
class Impl;
|
|
|
|
Impl * const d;
|
2015-05-21 14:49:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
#endif // UNDO_H
|