Fix #3288. Implement undo / redo until specified named transaction. Fix fundamental undo bug where Blender doesn't track the undo UUID property if you toggle edit mode.

This also has the nice side effect of implementing "Jump to point in history" so you can now use the Edit > Undo History menu.
This commit is contained in:
Dion Moult
2023-07-16 22:58:56 +10:00
parent 844cc62960
commit 944f2f701a
2 changed files with 26 additions and 12 deletions
+2 -2
View File
@@ -209,7 +209,7 @@ def loadIfcStore(scene):
def undo_post(scene):
if IfcStore.last_transaction != bpy.context.scene.BIMProperties.last_transaction:
IfcStore.last_transaction = bpy.context.scene.BIMProperties.last_transaction
IfcStore.undo()
IfcStore.undo(until_key=bpy.context.scene.BIMProperties.last_transaction)
purge_module_data()
tool.Ifc.rebuild_element_maps()
@@ -218,7 +218,7 @@ def undo_post(scene):
def redo_post(scene):
if IfcStore.last_transaction != bpy.context.scene.BIMProperties.last_transaction:
IfcStore.last_transaction = bpy.context.scene.BIMProperties.last_transaction
IfcStore.redo()
IfcStore.redo(until_key=bpy.context.scene.BIMProperties.last_transaction)
purge_module_data()
tool.Ifc.rebuild_element_maps()
+24 -10
View File
@@ -366,21 +366,35 @@ class IfcStore:
IfcStore.future = []
@staticmethod
def undo():
def undo(until_key=None):
BrickStore.undo()
if not IfcStore.history:
return
event = IfcStore.history.pop()
for transaction in event["operations"][::-1]:
transaction["rollback"](transaction["data"])
IfcStore.future.append(event)
while IfcStore.history:
if IfcStore.history[-1]["key"] == until_key:
return
event = IfcStore.history.pop()
for transaction in event["operations"][::-1]:
transaction["rollback"](transaction["data"])
IfcStore.future.append(event)
@staticmethod
def redo():
def redo(until_key=None):
BrickStore.redo()
if not IfcStore.future:
return
event = IfcStore.future.pop()
for transaction in event["operations"]:
transaction["commit"](transaction["data"])
IfcStore.history.append(event)
has_encountered_key = False
while IfcStore.future:
if has_encountered_key and IfcStore.future[-1]["key"] != until_key:
return
elif IfcStore.future[-1]["key"] == until_key:
has_encountered_key = True
event = IfcStore.future.pop()
for transaction in event["operations"]:
transaction["commit"](transaction["data"])
IfcStore.history.append(event)