GPv3: Lock/Unlock All Layers

Port the legacy lock/unlock all layers operator from GPv2.

Pull Request: https://projects.blender.org/blender/blender/pulls/118259
This commit is contained in:
Pratik Borhade 2024-02-15 12:14:17 +01:00 committed by Falk David
parent 4780cd3368
commit 43996a54cf
2 changed files with 46 additions and 0 deletions

@ -55,6 +55,10 @@ class GREASE_PENCIL_MT_grease_pencil_add_layer_extra(Menu):
layout.operator("grease_pencil.layer_reveal", icon='RESTRICT_VIEW_OFF', text="Show All")
layout.operator("grease_pencil.layer_hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True
layout.separator()
layout.operator("grease_pencil.layer_lock_all", icon='LOCKED', text="Lock All")
layout.operator("grease_pencil.layer_lock_all", icon='UNLOCKED', text="Unlock All").lock = False
class DATA_PT_grease_pencil_layers(DataButtonsPanel, Panel):
bl_label = "Layers"

@ -428,6 +428,47 @@ static void GREASE_PENCIL_OT_layer_isolate(wmOperatorType *ot)
RNA_def_boolean(
ot->srna, "affect_visibility", false, "Affect Visibility", "Also affect the visibility");
}
static int grease_pencil_layer_lock_all_exec(bContext *C, wmOperator *op)
{
using namespace blender::bke::greasepencil;
Object *object = CTX_data_active_object(C);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
const bool lock_value = RNA_boolean_get(op->ptr, "lock");
if (grease_pencil.layers().is_empty()) {
return OPERATOR_CANCELLED;
}
for (Layer *layer : grease_pencil.layers_for_write()) {
layer->set_locked(lock_value);
}
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil);
WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, nullptr);
return OPERATOR_FINISHED;
}
static void GREASE_PENCIL_OT_layer_lock_all(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Lock All Layers";
ot->idname = "GREASE_PENCIL_OT_layer_lock_all";
ot->description =
"Lock all Grease Pencil layers to prevent them from being accidentally modified";
/* callbacks */
ot->exec = grease_pencil_layer_lock_all_exec;
ot->poll = active_grease_pencil_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "lock", true, "Lock Value", "Lock/Unlock all layers");
}
} // namespace blender::ed::greasepencil
void ED_operatortypes_grease_pencil_layers()
@ -440,6 +481,7 @@ void ED_operatortypes_grease_pencil_layers()
WM_operatortype_append(GREASE_PENCIL_OT_layer_hide);
WM_operatortype_append(GREASE_PENCIL_OT_layer_reveal);
WM_operatortype_append(GREASE_PENCIL_OT_layer_isolate);
WM_operatortype_append(GREASE_PENCIL_OT_layer_lock_all);
WM_operatortype_append(GREASE_PENCIL_OT_layer_group_add);
}