79 |
78 |
80 // ============================================================================= |
79 // ============================================================================= |
81 // ----------------------------------------------------------------------------- |
80 // ----------------------------------------------------------------------------- |
82 void History::clear() |
81 void History::clear() |
83 { for (Changeset set : m_changesets) |
82 { for (Changeset set : m_changesets) |
84 for (auto change : set) |
83 for (AbstractHistoryEntry* change : set) |
85 delete change; |
84 delete change; |
86 |
85 |
87 m_changesets.clear(); |
86 m_changesets.clear(); |
88 } |
87 } |
89 |
88 |
90 // ============================================================================= |
89 // ============================================================================= |
91 // ----------------------------------------------------------------------------- |
90 // ----------------------------------------------------------------------------- |
92 void History::updateActions() const |
91 void History::updateActions() const |
93 { ACTION (Undo)->setEnabled (pos() != -1); |
92 { ACTION (Undo)->setEnabled (getPosition() != -1); |
94 ACTION (Redo)->setEnabled (pos() < (long) m_changesets.size() - 1); |
93 ACTION (Redo)->setEnabled (getPosition() < (long) m_changesets.size() - 1); |
95 } |
94 } |
96 |
95 |
97 // ============================================================================= |
96 // ============================================================================= |
98 // ----------------------------------------------------------------------------- |
97 // ----------------------------------------------------------------------------- |
99 void History::open() |
98 void History::addStep() |
100 { if (opened()) |
99 { if (m_currentChangeset.isEmpty()) |
101 return; |
100 return; |
102 |
101 |
103 setOpened (true); |
102 while (getPosition() < getSize() - 1) |
104 } |
|
105 |
|
106 // ============================================================================= |
|
107 // ----------------------------------------------------------------------------- |
|
108 void History::close() |
|
109 { if (!opened()) |
|
110 return; |
|
111 |
|
112 setOpened (false); |
|
113 |
|
114 if (m_currentArchive.isEmpty()) |
|
115 return; |
|
116 |
|
117 while (pos() < getSize() - 1) |
|
118 m_changesets.removeLast(); |
103 m_changesets.removeLast(); |
119 |
104 |
120 m_changesets << m_currentArchive; |
105 m_changesets << m_currentChangeset; |
121 m_currentArchive.clear(); |
106 m_currentChangeset.clear(); |
122 setPos (pos() + 1); |
107 setPosition (getPosition() + 1); |
123 updateActions(); |
108 updateActions(); |
124 } |
109 } |
125 |
110 |
126 // ============================================================================= |
111 // ============================================================================= |
127 // ----------------------------------------------------------------------------- |
112 // ----------------------------------------------------------------------------- |
128 void History::add (AbstractHistoryEntry* entry) |
113 void History::add (AbstractHistoryEntry* entry) |
129 { if (!opened()) |
114 { if (isIgnoring()) |
130 { delete entry; |
115 { delete entry; |
131 return; |
116 return; |
132 } |
117 } |
133 |
118 |
134 entry->setParent (this); |
119 entry->setParent (this); |
135 m_currentArchive << entry; |
120 m_currentChangeset << entry; |
136 } |
121 } |
137 |
122 |
138 // ============================================================================= |
123 // ============================================================================= |
139 // ----------------------------------------------------------------------------- |
124 // ----------------------------------------------------------------------------- |
140 void AddHistory::undo() const |
125 void AddHistory::undo() const |
141 { LDFile* f = parent()->file(); |
126 { LDFile* f = getParent()->getFile(); |
142 LDObject* obj = f->getObject (index()); |
127 LDObject* obj = f->getObject (getIndex()); |
143 f->forgetObject (obj); |
128 f->forgetObject (obj); |
144 delete obj; |
129 delete obj; |
145 |
130 |
146 g_fullRefresh = true; |
131 g_fullRefresh = true; |
147 } |
132 } |
148 |
133 |
149 // ============================================================================= |
134 // ============================================================================= |
150 // ----------------------------------------------------------------------------- |
135 // ----------------------------------------------------------------------------- |
151 void AddHistory::redo() const |
136 void AddHistory::redo() const |
152 { LDFile* f = parent()->file(); |
137 { LDFile* f = getParent()->getFile(); |
153 LDObject* obj = parseLine (code()); |
138 LDObject* obj = parseLine (getCode()); |
154 f->insertObj (index(), obj); |
139 f->insertObj (getIndex(), obj); |
155 g_win->R()->compileObject (obj); |
140 g_win->R()->compileObject (obj); |
156 } |
141 } |
157 |
|
158 AddHistory::~AddHistory() {} |
|
159 |
142 |
160 // ============================================================================= |
143 // ============================================================================= |
161 // heh |
144 // heh |
162 // ----------------------------------------------------------------------------- |
145 // ----------------------------------------------------------------------------- |
163 void DelHistory::undo() const |
146 void DelHistory::undo() const |
164 { LDFile* f = parent()->file(); |
147 { LDFile* f = getParent()->getFile(); |
165 LDObject* obj = parseLine (code()); |
148 LDObject* obj = parseLine (getCode()); |
166 f->insertObj (index(), obj); |
149 f->insertObj (getIndex(), obj); |
167 g_win->R()->compileObject (obj); |
150 g_win->R()->compileObject (obj); |
168 } |
151 } |
169 |
152 |
170 // ============================================================================= |
153 // ============================================================================= |
171 // ----------------------------------------------------------------------------- |
154 // ----------------------------------------------------------------------------- |
172 void DelHistory::redo() const |
155 void DelHistory::redo() const |
173 { LDFile* f = parent()->file(); |
156 { LDFile* f = getParent()->getFile(); |
174 LDObject* obj = f->getObject (index()); |
157 LDObject* obj = f->getObject (getIndex()); |
175 f->forgetObject (obj); |
158 f->forgetObject (obj); |
176 delete obj; |
159 delete obj; |
177 |
160 |
178 g_fullRefresh = true; |
161 g_fullRefresh = true; |
179 } |
162 } |
180 |
163 |
181 DelHistory::~DelHistory() {} |
|
182 |
|
183 // ============================================================================= |
164 // ============================================================================= |
184 // ----------------------------------------------------------------------------- |
165 // ----------------------------------------------------------------------------- |
185 void EditHistory::undo() const |
166 void EditHistory::undo() const |
186 { LDObject* obj = LDFile::current()->getObject (index()); |
167 { LDObject* obj = LDFile::current()->getObject (getIndex()); |
187 LDObject* newobj = parseLine (oldCode()); |
168 LDObject* newobj = parseLine (getOldCode()); |
188 obj->replace (newobj); |
169 obj->replace (newobj); |
189 g_win->R()->compileObject (newobj); |
170 g_win->R()->compileObject (newobj); |
190 } |
171 } |
191 |
172 |
192 // ============================================================================= |
173 // ============================================================================= |
193 // ----------------------------------------------------------------------------- |
174 // ----------------------------------------------------------------------------- |
194 void EditHistory::redo() const |
175 void EditHistory::redo() const |
195 { LDObject* obj = LDFile::current()->getObject (index()); |
176 { LDObject* obj = LDFile::current()->getObject (getIndex()); |
196 LDObject* newobj = parseLine (newCode()); |
177 LDObject* newobj = parseLine (getNewCode()); |
197 obj->replace (newobj); |
178 obj->replace (newobj); |
198 g_win->R()->compileObject (newobj); |
179 g_win->R()->compileObject (newobj); |
199 } |
180 } |
200 |
|
201 EditHistory::~EditHistory() {} |
|
202 |
181 |
203 // ============================================================================= |
182 // ============================================================================= |
204 // ----------------------------------------------------------------------------- |
183 // ----------------------------------------------------------------------------- |
205 void SwapHistory::undo() const |
184 void SwapHistory::undo() const |
206 { LDObject::fromID (a)->swap (LDObject::fromID (b)); |
185 { LDObject::fromID (a)->swap (LDObject::fromID (b)); |
207 } |
186 } |
208 |
187 |
209 void SwapHistory::redo() const |
188 void SwapHistory::redo() const |
210 { undo(); // :v |
189 { undo(); // :v |
211 } |
190 } |
212 |
|
213 SwapHistory::~SwapHistory() {} |
|