From 43996a54cf121bf23f690a1375a044eca0edf195 Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Thu, 15 Feb 2024 12:14:17 +0100 Subject: [PATCH] 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 --- .../bl_ui/properties_data_grease_pencil.py | 4 ++ .../intern/grease_pencil_layers.cc | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/scripts/startup/bl_ui/properties_data_grease_pencil.py b/scripts/startup/bl_ui/properties_data_grease_pencil.py index 16c46be62d8..b0dc34fd244 100644 --- a/scripts/startup/bl_ui/properties_data_grease_pencil.py +++ b/scripts/startup/bl_ui/properties_data_grease_pencil.py @@ -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" diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc index 954b23aec07..da9917c932c 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc @@ -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(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); }