forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.cpp
More file actions
114 lines (88 loc) · 1.49 KB
/
cmd.cpp
File metadata and controls
114 lines (88 loc) · 1.49 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/cmd.h"
#include <typeinfo>
namespace app {
Cmd::Cmd()
#if _DEBUG
: m_state(State::NotExecuted)
#endif
{
}
Cmd::~Cmd()
{
}
void Cmd::execute(Context* ctx)
{
TRACE("CMD: Executing cmd '%s'\n", typeid(*this).name());
ASSERT(m_state == State::NotExecuted);
m_ctx = ctx;
onExecute();
onFireNotifications();
#if _DEBUG
m_state = State::Executed;
#endif
}
void Cmd::undo()
{
TRACE("CMD: Undo cmd '%s'\n", typeid(*this).name());
ASSERT(m_state == State::Executed || m_state == State::Redone);
onUndo();
onFireNotifications();
#if _DEBUG
m_state = State::Undone;
#endif
}
void Cmd::redo()
{
TRACE("CMD: Redo cmd '%s'\n", typeid(*this).name());
ASSERT(m_state == State::Undone);
onRedo();
onFireNotifications();
#if _DEBUG
m_state = State::Redone;
#endif
}
void Cmd::dispose()
{
delete this;
}
std::string Cmd::label() const
{
return onLabel();
}
size_t Cmd::memSize() const
{
return onMemSize();
}
void Cmd::onExecute()
{
// Do nothing
}
void Cmd::onUndo()
{
// Do nothing
}
void Cmd::onRedo()
{
// By default onRedo() uses onExecute() implementation
onExecute();
}
void Cmd::onFireNotifications()
{
// Do nothing
}
std::string Cmd::onLabel() const
{
return "";
}
size_t Cmd::onMemSize() const {
return sizeof(*this);
}
} // namespace app