Fix #1717 : Disable task editing if task was deleted as a result of deleting its parent (#1936)

* Disable task editing if task was deleted as a result of deleting its parent

* Optimize logic for bigger number of tasks

* Don't try to disable editing if not editing in the first place
This commit is contained in:
Gorgious56
2022-01-04 03:03:39 +01:00
committed by GitHub
parent 0625e4153c
commit 02a62a943c
@@ -513,13 +513,25 @@ class RemoveTask(bpy.types.Operator):
def _execute(self, context):
props = context.scene.BIMWorkScheduleProperties
self.file = IfcStore.get_file()
edited_task_ifc = self.file.by_id(props.active_task_id) if props.active_task_id else None
ifcopenshell.api.run(
"sequence.remove_task",
self.file,
task=IfcStore.get_file().by_id(self.task),
task=self.file.by_id(self.task),
)
Data.load(self.file)
bpy.ops.bim.enable_editing_tasks(work_schedule=props.active_work_schedule_id)
if edited_task_ifc:
if not any(
task
for task in context.scene.BIMTaskTreeProperties.tasks
if task.ifc_definition_id == props.active_task_id
and self.file.by_id(props.active_task_id) == edited_task_ifc
): # Task was deleted
bpy.ops.bim.disable_editing_task()
return {"FINISHED"}