WM: check missing space-data & constraints in poll functions

Without this, menu search prints many errors in some contexts.
This commit is contained in:
2021-05-18 20:00:51 +10:00
parent eaf3160f13
commit 4402c3006b
5 changed files with 48 additions and 41 deletions

View File

@@ -33,6 +33,11 @@ class CONSTRAINT_OT_add_target(Operator):
bl_label = "Add Target"
bl_options = {'UNDO', 'INTERNAL'}
@classmethod
def poll(cls, context):
constraint = getattr(context, "constraint", None)
return constraint
def execute(self, context):
context.constraint.targets.new()
return {'FINISHED'}
@@ -46,6 +51,11 @@ class CONSTRAINT_OT_remove_target(Operator):
index: IntProperty()
@classmethod
def poll(cls, context):
constraint = getattr(context, "constraint", None)
return constraint
def execute(self, context):
tgts = context.constraint.targets
tgts.remove(tgts[self.index])
@@ -58,6 +68,11 @@ class CONSTRAINT_OT_normalize_target_weights(Operator):
bl_label = "Normalize Weights"
bl_options = {'UNDO', 'INTERNAL'}
@classmethod
def poll(cls, context):
constraint = getattr(context, "constraint", None)
return constraint
def execute(self, context):
tgts = context.constraint.targets
total = sum(t.weight for t in tgts)