src/history.cpp

changeset 455
c5d14d112034
parent 421
7d26db0be944
child 493
16766ac1bbd9
equal deleted inserted replaced
454:d6b4ed3bf169 455:c5d14d112034
23 #include "gui.h" 23 #include "gui.h"
24 #include "gldraw.h" 24 #include "gldraw.h"
25 25
26 bool g_fullRefresh = false; 26 bool g_fullRefresh = false;
27 27
28 // =============================================================================
29 // -----------------------------------------------------------------------------
28 History::History() : 30 History::History() :
29 m_pos (-1), 31 m_pos (-1),
30 m_opened (false) {} 32 m_opened (false) {}
31 33
34 // =============================================================================
35 // -----------------------------------------------------------------------------
32 void History::undo() { 36 void History::undo() {
33 if (m_changesets.size() == 0 || pos() == -1) 37 if (m_changesets.size() == 0 || pos() == -1)
34 return; 38 return;
35 39
36 const list& set = changeset (pos()); 40 const list& set = changeset (pos());
48 g_win->fullRefresh(); 52 g_win->fullRefresh();
49 53
50 updateActions(); 54 updateActions();
51 } 55 }
52 56
57 // =============================================================================
58 // -----------------------------------------------------------------------------
53 void History::redo() { 59 void History::redo() {
54 if (pos() == (long) m_changesets.size()) 60 if (pos() == (long) m_changesets.size())
55 return; 61 return;
56 62
57 const list& set = changeset (pos() + 1); 63 const list& set = changeset (pos() + 1);
69 g_win->fullRefresh(); 75 g_win->fullRefresh();
70 76
71 updateActions(); 77 updateActions();
72 } 78 }
73 79
80 // =============================================================================
81 // -----------------------------------------------------------------------------
74 void History::clear() { 82 void History::clear() {
75 for (List<AbstractHistoryEntry*> set : m_changesets) 83 for (List<AbstractHistoryEntry*> set : m_changesets)
76 for (AbstractHistoryEntry * change : set) 84 for (AbstractHistoryEntry * change : set)
77 delete change; 85 delete change;
78 86
79 m_changesets.clear(); 87 m_changesets.clear();
80 } 88 }
81 89
90 // =============================================================================
91 // -----------------------------------------------------------------------------
82 void History::updateActions() const { 92 void History::updateActions() const {
83 ACTION (Undo)->setEnabled (pos() != -1); 93 ACTION (Undo)->setEnabled (pos() != -1);
84 ACTION (Redo)->setEnabled (pos() < (long) m_changesets.size() - 1); 94 ACTION (Redo)->setEnabled (pos() < (long) m_changesets.size() - 1);
85 } 95 }
86 96
97 // =============================================================================
98 // -----------------------------------------------------------------------------
87 void History::open() { 99 void History::open() {
88 if (opened()) 100 if (opened())
89 return; 101 return;
90 102
91 setOpened (true); 103 setOpened (true);
92 } 104 }
93 105
106 // =============================================================================
107 // -----------------------------------------------------------------------------
94 void History::close() { 108 void History::close() {
95 if (!opened()) 109 if (!opened())
96 return; 110 return;
97 111
98 setOpened (false); 112 setOpened (false);
107 m_currentArchive.clear(); 121 m_currentArchive.clear();
108 setPos (pos() + 1); 122 setPos (pos() + 1);
109 updateActions(); 123 updateActions();
110 } 124 }
111 125
126 // =============================================================================
127 // -----------------------------------------------------------------------------
112 void History::add (AbstractHistoryEntry* entry) { 128 void History::add (AbstractHistoryEntry* entry) {
113 if (!opened()) { 129 if (!opened()) {
114 delete entry; 130 delete entry;
115 return; 131 return;
116 } 132 }
118 entry->setParent (this); 134 entry->setParent (this);
119 m_currentArchive << entry; 135 m_currentArchive << entry;
120 } 136 }
121 137
122 // ============================================================================= 138 // =============================================================================
139 // -----------------------------------------------------------------------------
123 void AddHistory::undo() const { 140 void AddHistory::undo() const {
124 LDFile* f = parent()->file(); 141 LDFile* f = parent()->file();
125 LDObject* obj = f->object (index()); 142 LDObject* obj = f->object (index());
126 f->forgetObject (obj); 143 f->forgetObject (obj);
127 delete obj; 144 delete obj;
128 145
129 g_fullRefresh = true; 146 g_fullRefresh = true;
130 } 147 }
131 148
149 // =============================================================================
150 // -----------------------------------------------------------------------------
132 void AddHistory::redo() const { 151 void AddHistory::redo() const {
133 LDFile* f = parent()->file(); 152 LDFile* f = parent()->file();
134 LDObject* obj = parseLine (code()); 153 LDObject* obj = parseLine (code());
135 f->insertObj (index(), obj); 154 f->insertObj (index(), obj);
136 g_win->R()->compileObject (obj); 155 g_win->R()->compileObject (obj);
138 157
139 AddHistory::~AddHistory() {} 158 AddHistory::~AddHistory() {}
140 159
141 // ============================================================================= 160 // =============================================================================
142 // heh 161 // heh
162 // -----------------------------------------------------------------------------
143 void DelHistory::undo() const { 163 void DelHistory::undo() const {
144 LDFile* f = parent()->file(); 164 LDFile* f = parent()->file();
145 LDObject* obj = parseLine (code()); 165 LDObject* obj = parseLine (code());
146 f->insertObj (index(), obj); 166 f->insertObj (index(), obj);
147 g_win->R()->compileObject (obj); 167 g_win->R()->compileObject (obj);
148 } 168 }
149 169
170 // =============================================================================
171 // -----------------------------------------------------------------------------
150 void DelHistory::redo() const { 172 void DelHistory::redo() const {
151 LDFile* f = parent()->file(); 173 LDFile* f = parent()->file();
152 LDObject* obj = f->object (index()); 174 LDObject* obj = f->object (index());
153 f->forgetObject (obj); 175 f->forgetObject (obj);
154 delete obj; 176 delete obj;
157 } 179 }
158 180
159 DelHistory::~DelHistory() {} 181 DelHistory::~DelHistory() {}
160 182
161 // ============================================================================= 183 // =============================================================================
184 // -----------------------------------------------------------------------------
162 void EditHistory::undo() const { 185 void EditHistory::undo() const {
163 LDObject* obj = LDFile::current()->object (index()); 186 LDObject* obj = LDFile::current()->object (index());
164 LDObject* newobj = parseLine (oldCode()); 187 LDObject* newobj = parseLine (oldCode());
165 obj->replace (newobj); 188 obj->replace (newobj);
166 g_win->R()->compileObject (newobj); 189 g_win->R()->compileObject (newobj);
167 } 190 }
168 191
192 // =============================================================================
193 // -----------------------------------------------------------------------------
169 void EditHistory::redo() const { 194 void EditHistory::redo() const {
170 LDObject* obj = LDFile::current()->object (index()); 195 LDObject* obj = LDFile::current()->object (index());
171 LDObject* newobj = parseLine (newCode()); 196 LDObject* newobj = parseLine (newCode());
172 obj->replace (newobj); 197 obj->replace (newobj);
173 g_win->R()->compileObject (newobj); 198 g_win->R()->compileObject (newobj);
174 } 199 }
175 200
176 EditHistory::~EditHistory() {} 201 EditHistory::~EditHistory() {}
177 202
178 // ============================================================================= 203 // =============================================================================
204 // -----------------------------------------------------------------------------
179 void SwapHistory::undo() const { 205 void SwapHistory::undo() const {
180 LDObject::fromID (a)->swap (LDObject::fromID (b)); 206 LDObject::fromID (a)->swap (LDObject::fromID (b));
181 } 207 }
182 208
183 void SwapHistory::redo() const { 209 void SwapHistory::redo() const {

mercurial