Bladeren bron

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

Ford Smith 4 jaren geleden
bovenliggende
commit
0e944897c6
1 gewijzigde bestanden met toevoegingen van 9 en 0 verwijderingen
  1. 9 0
      UI/undo-stack-obs.cpp

+ 9 - 0
UI/undo-stack-obs.cpp

@@ -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);