WM: check missing space-data & constraints in poll functions
Without this, menu search prints many errors in some contexts.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user