-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathundo_commands.cpp
More file actions
75 lines (65 loc) · 1.11 KB
/
undo_commands.cpp
File metadata and controls
75 lines (65 loc) · 1.11 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
#include "undo_commands.h"
#include "debug.h"
undo_nibble_command::undo_nibble_command(QByteArray *b, int l, unsigned char d[2], bool r)
{
buffer = b;
location = l;
data[0] = d[0];
data[1] = d[1];
remove = r;
}
void undo_nibble_command::undo()
{
if(remove){
buffer->remove(location, 1);
}else{
(*buffer)[location] = data[0];
}
}
void undo_nibble_command::redo()
{
if(!run_redo){
run_redo = true;
return;
}
(*buffer)[location] = data[1];
}
undo_action_command::undo_action_command(QByteArray *b, int l, QByteArray *d)
{
buffer = b;
location = l;
data = d;
}
undo_action_command::~undo_action_command()
{
delete data;
}
bool undo_action_command::check_run_redo()
{
if(run_redo){
return true;
}
return !(run_redo = true);
}
void undo_paste_command::undo()
{
buffer->remove(location, data->length());
}
void undo_paste_command::redo()
{
if(!check_run_redo()){
return;
}
buffer->insert(location, *data);
}
void undo_delete_command::undo()
{
buffer->insert(location, *data);
}
void undo_delete_command::redo()
{
if(!check_run_redo()){
return;
}
buffer->remove(location, data->length());
}