forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_undo.h
94 lines (68 loc) · 2.39 KB
/
doc_undo.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Aseprite
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_DOCUMENT_UNDO_H_INCLUDED
#define APP_DOCUMENT_UNDO_H_INCLUDED
#pragma once
#include "app/doc_range.h"
#include "app/sprite_position.h"
#include "base/disable_copying.h"
#include "obs/observable.h"
#include "undo/undo_history.h"
#include <iosfwd>
#include <string>
namespace app {
using namespace doc;
class Cmd;
class CmdTransaction;
class Context;
class DocUndoObserver;
class DocUndo : public obs::observable<DocUndoObserver>,
public undo::UndoHistoryDelegate {
public:
DocUndo();
size_t totalUndoSize() const { return m_totalUndoSize; }
void setContext(Context* ctx);
void add(CmdTransaction* cmd);
bool canUndo() const;
bool canRedo() const;
void undo();
void redo();
void clearRedo();
bool isSavedState() const;
void markSavedState();
void impossibleToBackToSavedState();
std::string nextUndoLabel() const;
std::string nextRedoLabel() const;
SpritePosition nextUndoSpritePosition() const;
SpritePosition nextRedoSpritePosition() const;
std::istream* nextUndoDocRange() const;
std::istream* nextRedoDocRange() const;
Cmd* lastExecutedCmd() const;
int* savedCounter() { return &m_savedCounter; }
const undo::UndoState* firstState() const { return m_undoHistory.firstState(); }
const undo::UndoState* currentState() const { return m_undoHistory.currentState(); }
void moveToState(const undo::UndoState* state);
private:
const undo::UndoState* nextUndo() const;
const undo::UndoState* nextRedo() const;
// undo::UndoHistoryDelegate impl
void onDeleteUndoState(undo::UndoState* state) override;
undo::UndoHistory m_undoHistory;
Context* m_ctx;
size_t m_totalUndoSize;
// This counter is equal to 0 if we are in the "saved state", i.e.
// the document on memory is equal to the document on disk. This
// value is less than 0 if we're in a past version of the document
// (due undoes), or greater than 0 if we are in a future version
// (due redoes).
int m_savedCounter;
// True if the saved state was invalidated/corrupted/lost in some
// way. E.g. If the save process fails.
bool m_savedStateIsLost;
DISABLE_COPYING(DocUndo);
};
} // namespace app
#endif