Fix: Remove All Materials operator is not greyed out when list is empty
Disable the operator when there are no materials in the list to delete Co-authored-by: Pratik Borhade <pratikborhade302@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/141003
This commit is contained in:
committed by
Pratik Borhade
parent
acebf4b6d5
commit
0571b66566
@@ -751,14 +751,24 @@ void OBJECT_OT_material_slot_remove_unused(wmOperatorType *ot)
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static bool material_slot_remove_all_poll(bContext *C)
|
||||
{
|
||||
if (!material_slot_remove_poll(C)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const Object *ob_active = CTX_data_active_object(C);
|
||||
if (ob_active->actcol <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static wmOperatorStatus material_slot_remove_all_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
/* Removing material slots in edit mode screws things up, see bug #21822. */
|
||||
Object *ob_active = CTX_data_active_object(C);
|
||||
if (ob_active && BKE_object_is_in_editmode(ob_active)) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Unable to remove material slot in edit mode");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
Main *bmain = CTX_data_main(C);
|
||||
int removed = 0;
|
||||
|
||||
@@ -810,7 +820,7 @@ void OBJECT_OT_material_slot_remove_all(wmOperatorType *ot)
|
||||
|
||||
/* API callbacks. */
|
||||
ot->exec = material_slot_remove_all_exec;
|
||||
ot->poll = object_materials_supported_poll;
|
||||
ot->poll = material_slot_remove_all_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
Reference in New Issue
Block a user