-
Notifications
You must be signed in to change notification settings - Fork 16
/
undo_history.h
62 lines (48 loc) · 1.6 KB
/
undo_history.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Undo Library
// Copyright (C) 2015-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef UNDO_HISTORY_H_INCLUDED
#define UNDO_HISTORY_H_INCLUDED
#pragma once
namespace undo {
class UndoCommand;
class UndoState;
class UndoHistoryDelegate {
public:
virtual ~UndoHistoryDelegate() { }
virtual void onDeleteUndoState(UndoState* state) { }
};
class UndoHistory {
public:
UndoHistory(UndoHistoryDelegate* delegate = nullptr);
virtual ~UndoHistory();
const UndoState* firstState() const { return m_first; }
const UndoState* lastState() const { return m_last; }
const UndoState* currentState() const { return m_cur; }
void add(UndoCommand* cmd);
bool canUndo() const;
bool canRedo() const;
void undo();
void redo();
// Deletes the whole redo history. Can be called before an add()
// to create a linear undo history.
void clearRedo();
// Deletes the first UndoState. It can be useful to limit the size
// of the undo history.
bool deleteFirstState();
// This can be used to jump to a specific UndoState in the whole
// history.
void moveTo(const UndoState* new_state);
private:
const UndoState* findCommonParent(const UndoState* a,
const UndoState* b);
void deleteState(UndoState* state);
UndoHistoryDelegate* m_delegate;
UndoState* m_first;
UndoState* m_last;
UndoState* m_cur; // Current action that can be undone
};
} // namespace undo
#endif // HISTORY_H_INCLUDED