24 #include "GLRenderer.h" |
24 #include "GLRenderer.h" |
25 |
25 |
26 // ============================================================================= |
26 // ============================================================================= |
27 // |
27 // |
28 History::History() : |
28 History::History() : |
29 m_Position (-1) {} |
29 m_position (-1) {} |
30 |
30 |
31 // ============================================================================= |
31 // ============================================================================= |
32 // |
32 // |
33 void History::undo() |
33 void History::undo() |
34 { |
34 { |
35 if (m_changesets.isEmpty() || getPosition() == -1) |
35 if (m_changesets.isEmpty() || position() == -1) |
36 return; |
36 return; |
37 |
37 |
38 // Don't take the changes done here as actual edits to the document |
38 // Don't take the changes done here as actual edits to the document |
39 setIgnoring (true); |
39 setIgnoring (true); |
40 |
40 |
41 const Changeset& set = getChangeset (getPosition()); |
41 const Changeset& set = getChangeset (position()); |
42 |
42 |
43 // Iterate the list in reverse and undo all actions |
43 // Iterate the list in reverse and undo all actions |
44 for (int i = set.size() - 1; i >= 0; --i) |
44 for (int i = set.size() - 1; i >= 0; --i) |
45 { |
45 { |
46 AbstractHistoryEntry* change = set[i]; |
46 AbstractHistoryEntry* change = set[i]; |
47 change->undo(); |
47 change->undo(); |
48 } |
48 } |
49 |
49 |
50 decreasePosition(); |
50 m_position--; |
51 g_win->refresh(); |
51 g_win->refresh(); |
52 g_win->updateActions(); |
52 g_win->updateActions(); |
53 dlog ("Position is now %1", getPosition()); |
53 dprint ("Position is now %1", position()); |
54 setIgnoring (false); |
54 setIgnoring (false); |
55 } |
55 } |
56 |
56 |
57 // ============================================================================= |
57 // ============================================================================= |
58 // |
58 // |
59 void History::redo() |
59 void History::redo() |
60 { |
60 { |
61 if (getPosition() == m_changesets.size()) |
61 if (position() == m_changesets.size()) |
62 return; |
62 return; |
63 |
63 |
64 setIgnoring (true); |
64 setIgnoring (true); |
65 const Changeset& set = getChangeset (getPosition() + 1); |
65 const Changeset& set = getChangeset (position() + 1); |
66 |
66 |
67 // Redo things - in the order as they were done in the first place |
67 // Redo things - in the order as they were done in the first place |
68 for (const AbstractHistoryEntry* change : set) |
68 for (const AbstractHistoryEntry* change : set) |
69 change->redo(); |
69 change->redo(); |
70 |
70 |
71 setPosition (getPosition() + 1); |
71 setPosition (position() + 1); |
72 g_win->refresh(); |
72 g_win->refresh(); |
73 g_win->updateActions(); |
73 g_win->updateActions(); |
74 dlog ("Position is now %1", getPosition()); |
74 dprint ("Position is now %1", position()); |
75 setIgnoring (false); |
75 setIgnoring (false); |
76 } |
76 } |
77 |
77 |
78 // ============================================================================= |
78 // ============================================================================= |
79 // |
79 // |
82 for (Changeset set : m_changesets) |
82 for (Changeset set : m_changesets) |
83 for (AbstractHistoryEntry* change : set) |
83 for (AbstractHistoryEntry* change : set) |
84 delete change; |
84 delete change; |
85 |
85 |
86 m_changesets.clear(); |
86 m_changesets.clear(); |
87 dlog ("History: cleared"); |
87 dprint ("History: cleared"); |
88 } |
88 } |
89 |
89 |
90 // ============================================================================= |
90 // ============================================================================= |
91 // |
91 // |
92 void History::addStep() |
92 void History::addStep() |
93 { |
93 { |
94 if (m_currentChangeset.isEmpty()) |
94 if (m_currentChangeset.isEmpty()) |
95 return; |
95 return; |
96 |
96 |
97 while (getPosition() < getSize() - 1) |
97 while (position() < getSize() - 1) |
98 { |
98 { |
99 Changeset last = m_changesets.last(); |
99 Changeset last = m_changesets.last(); |
100 |
100 |
101 for (AbstractHistoryEntry* entry : last) |
101 for (AbstractHistoryEntry* entry : last) |
102 delete entry; |
102 delete entry; |
103 |
103 |
104 m_changesets.removeLast(); |
104 m_changesets.removeLast(); |
105 } |
105 } |
106 |
106 |
107 dlog ("History: step added (%1 changes)", m_currentChangeset.size()); |
107 dprint ("History: step added (%1 changes)", m_currentChangeset.size()); |
108 m_changesets << m_currentChangeset; |
108 m_changesets << m_currentChangeset; |
109 m_currentChangeset.clear(); |
109 m_currentChangeset.clear(); |
110 setPosition (getPosition() + 1); |
110 setPosition (position() + 1); |
111 g_win->updateActions(); |
111 g_win->updateActions(); |
112 } |
112 } |
113 |
113 |
114 // ============================================================================= |
114 // ============================================================================= |
115 // |
115 // |
121 return; |
121 return; |
122 } |
122 } |
123 |
123 |
124 entry->setParent (this); |
124 entry->setParent (this); |
125 m_currentChangeset << entry; |
125 m_currentChangeset << entry; |
126 dlog ("History: added entry of type %1", entry->getTypeName()); |
126 dprint ("History: added entry of type %1", entry->getTypeName()); |
127 } |
127 } |
128 |
128 |
129 // ============================================================================= |
129 // ============================================================================= |
130 // |
130 // |
131 void AddHistory::undo() const |
131 void AddHistory::undo() const |
132 { |
132 { |
133 LDObject* obj = getParent()->getDocument()->getObject (getIndex()); |
133 LDObject* obj = parent()->document()->getObject (index()); |
134 obj->deleteSelf(); |
134 obj->destroy(); |
135 } |
135 } |
136 |
136 |
137 // ============================================================================= |
137 // ============================================================================= |
138 // |
138 // |
139 void AddHistory::redo() const |
139 void AddHistory::redo() const |
140 { |
140 { |
141 LDObject* obj = parseLine (getCode()); |
141 LDObject* obj = parseLine (code()); |
142 getParent()->getDocument()->insertObj (getIndex(), obj); |
142 parent()->document()->insertObj (index(), obj); |
143 g_win->R()->compileObject (obj); |
143 g_win->R()->compileObject (obj); |
144 } |
144 } |
145 |
145 |
146 // ============================================================================= |
146 // ============================================================================= |
147 // |
147 // |
148 DelHistory::DelHistory (int idx, LDObject* obj) : |
148 DelHistory::DelHistory (int idx, LDObject* obj) : |
149 m_Index (idx), |
149 m_index (idx), |
150 m_Code (obj->raw()) {} |
150 m_code (obj->asText()) {} |
151 |
151 |
152 // ============================================================================= |
152 // ============================================================================= |
153 // heh |
153 // heh |
154 // |
154 // |
155 void DelHistory::undo() const |
155 void DelHistory::undo() const |
156 { |
156 { |
157 LDObject* obj = parseLine (getCode()); |
157 LDObject* obj = parseLine (code()); |
158 getParent()->getDocument()->insertObj (getIndex(), obj); |
158 parent()->document()->insertObj (index(), obj); |
159 g_win->R()->compileObject (obj); |
159 g_win->R()->compileObject (obj); |
160 } |
160 } |
161 |
161 |
162 // ============================================================================= |
162 // ============================================================================= |
163 // |
163 // |
164 void DelHistory::redo() const |
164 void DelHistory::redo() const |
165 { |
165 { |
166 LDObject* obj = getParent()->getDocument()->getObject (getIndex()); |
166 LDObject* obj = parent()->document()->getObject (index()); |
167 obj->deleteSelf(); |
167 obj->destroy(); |
168 } |
168 } |
169 |
169 |
170 // ============================================================================= |
170 // ============================================================================= |
171 // |
171 // |
172 void EditHistory::undo() const |
172 void EditHistory::undo() const |
173 { |
173 { |
174 LDObject* obj = getCurrentDocument()->getObject (getIndex()); |
174 LDObject* obj = getCurrentDocument()->getObject (index()); |
175 LDObject* newobj = parseLine (getOldCode()); |
175 LDObject* newobj = parseLine (oldCode()); |
176 obj->replace (newobj); |
176 obj->replace (newobj); |
177 g_win->R()->compileObject (newobj); |
177 g_win->R()->compileObject (newobj); |
178 } |
178 } |
179 |
179 |
180 // ============================================================================= |
180 // ============================================================================= |
181 // |
181 // |
182 void EditHistory::redo() const |
182 void EditHistory::redo() const |
183 { |
183 { |
184 LDObject* obj = getCurrentDocument()->getObject (getIndex()); |
184 LDObject* obj = getCurrentDocument()->getObject (index()); |
185 LDObject* newobj = parseLine (getNewCode()); |
185 LDObject* newobj = parseLine (newCode()); |
186 obj->replace (newobj); |
186 obj->replace (newobj); |
187 g_win->R()->compileObject (newobj); |
187 g_win->R()->compileObject (newobj); |
188 } |
188 } |
189 |
189 |
190 // ============================================================================= |
190 // ============================================================================= |