mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 02:23:34 +00:00
Try to ensure undo will still work in case of an error
Previously transaction was never finished and therefore is_top_level_operator would never be triggered (without restarting project) making any IFC undo useless. Previously it wsan't finishing transaction therefore: - it was possible to undo ifc changes in the last step that had an error - since transaction was never finished, IfcStore.current_transaction was never cleared and therefore is_top_level_operator will be never be triggered for the next operators, so new transactions are never created breaking undo for any further ifc changes. Now user can try to undo the last action to save the file.
This commit is contained in:
@@ -399,6 +399,18 @@ class IfcStore:
|
||||
else:
|
||||
operator.transaction_key = IfcStore.current_transaction
|
||||
|
||||
def end_top_level_operator() -> None:
|
||||
if is_top_level_operator:
|
||||
if tool.Ifc.get():
|
||||
tool.Ifc.get().end_transaction()
|
||||
IfcStore.add_transaction_operation(
|
||||
operator, rollback=lambda d: tool.Ifc.get().undo(), commit=lambda d: tool.Ifc.get().redo()
|
||||
)
|
||||
if BrickStore.graph is not None: # `if BrickStore.graph` by itself takes ages.
|
||||
BrickStore.end_transaction()
|
||||
IfcStore.end_transaction(operator)
|
||||
bonsai.bim.handler.refresh_ui_data()
|
||||
|
||||
try:
|
||||
if is_invoke:
|
||||
result = getattr(operator, "_invoke")(context, None)
|
||||
@@ -406,19 +418,16 @@ class IfcStore:
|
||||
result = getattr(operator, "_execute")(context)
|
||||
except:
|
||||
bonsai.last_error = traceback.format_exc()
|
||||
# Try to ensure undo will work since Blender undo does work in case of errors.
|
||||
# As error come unexpectedly, it's important that user might have a chance to save the file
|
||||
# before they got the error and not to lose the work they've done.
|
||||
#
|
||||
# Also, some users won't stop seeing the error,
|
||||
# so we need to try to ensure that undo for further operations will work.
|
||||
end_top_level_operator()
|
||||
raise
|
||||
|
||||
if is_top_level_operator:
|
||||
if tool.Ifc.get():
|
||||
tool.Ifc.get().end_transaction()
|
||||
IfcStore.add_transaction_operation(
|
||||
operator, rollback=lambda d: tool.Ifc.get().undo(), commit=lambda d: tool.Ifc.get().redo()
|
||||
)
|
||||
if BrickStore.graph is not None: # `if BrickStore.graph` by itself takes ages.
|
||||
BrickStore.end_transaction()
|
||||
IfcStore.end_transaction(operator)
|
||||
bonsai.bim.handler.refresh_ui_data()
|
||||
|
||||
end_top_level_operator()
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user