UI: Add maximum number of items in undo/redo stack

master
Ford Smith 2021-04-02 17:26:37 -04:00 committed by Jim
parent c7aaceaee6
commit 0e944897c6
1 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,8 @@
#include <util/util.hpp>
#define MAX_STACK_SIZE 5000
undo_stack::undo_stack(ui_ptr ui) : ui(ui) {}
void undo_stack::release()
@ -19,6 +21,13 @@ void undo_stack::add_action(const QString &name, undo_redo_cb undo,
undo_redo_cb redo, std::string undo_data,
std::string redo_data, func d)
{
while (undo_items.size() >= MAX_STACK_SIZE) {
undo_redo_t item = undo_items.back();
if (item.d)
item.d(true);
undo_items.pop_back();
}
undo_redo_t n = {name, undo_data, redo_data, undo, redo, d};
undo_items.push_front(n);