-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathundo_history.h
More file actions
69 lines (54 loc) · 2.04 KB
/
Copy pathundo_history.h
File metadata and controls
69 lines (54 loc) · 2.04 KB
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
63
64
65
66
67
68
69
// Undo Library
// Copyright (C) 2015-2026 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 UndoContext;
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; }
// Adds a new command to the undo history. If "moveCur" is false,
// the current state is not moved, which means that we're adding a
// state to the "redo history", a command that was executed and
// undone.
void add(UndoCommand* cmd);
void add(UndoCommand* cmd, const UndoState* parent, bool moveCur);
bool canUndo(UndoContext* ctx = nullptr) const;
bool canRedo(UndoContext* ctx = nullptr) const;
void undo(UndoContext* ctx = nullptr);
void redo(UndoContext* ctx = nullptr);
// 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, UndoContext* ctx = nullptr);
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