diff --git a/scripts/startup/bl_operators/grease_pencil.py b/scripts/startup/bl_operators/grease_pencil.py index 0c10d9c268e..c6a9b339c9a 100644 --- a/scripts/startup/bl_operators/grease_pencil.py +++ b/scripts/startup/bl_operators/grease_pencil.py @@ -32,7 +32,8 @@ class GREASE_PENCIL_OT_relative_layer_mask_add(Operator): (obj := context.active_object) is not None and obj.is_editable and obj.type == 'GREASEPENCIL' and - obj.data.layers.active is not None + obj.data.layers.active is not None and + obj.data.is_editable ) def execute(self, context): diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc index 25ca673435a..b11d2ace6c8 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc @@ -578,7 +578,7 @@ static void GREASE_PENCIL_OT_insert_blank_frame(wmOperatorType *ot) /* callbacks */ ot->exec = insert_blank_frame_exec; - ot->poll = active_grease_pencil_poll; + ot->poll = editable_grease_pencil_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -600,7 +600,7 @@ static void GREASE_PENCIL_OT_frame_clean_duplicate(wmOperatorType *ot) /* callbacks */ ot->exec = frame_clean_duplicate_exec; - ot->poll = active_grease_pencil_poll; + ot->poll = editable_grease_pencil_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -848,7 +848,7 @@ static void GREASE_PENCIL_OT_frame_duplicate(wmOperatorType *ot) /* callback */ ot->exec = grease_pencil_frame_duplicate_exec; - ot->poll = active_grease_pencil_poll; + ot->poll = editable_grease_pencil_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -906,7 +906,7 @@ static void GREASE_PENCIL_OT_active_frame_delete(wmOperatorType *ot) /* callback */ ot->exec = grease_pencil_active_frame_delete_exec; - ot->poll = active_grease_pencil_poll; + ot->poll = editable_grease_pencil_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; 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 0e584a6a796..d6138e2b595 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc @@ -329,7 +329,7 @@ static void GREASE_PENCIL_OT_layer_active(wmOperatorType *ot) /* callbacks */ ot->exec = grease_pencil_layer_active_exec; - ot->poll = active_grease_pencil_poll; + ot->poll = editable_grease_pencil_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -875,7 +875,7 @@ static void GREASE_PENCIL_OT_layer_merge(wmOperatorType *ot) ot->description = "Combine layers based on the mode into one layer"; ot->exec = grease_pencil_merge_layer_exec; - ot->poll = active_grease_pencil_poll; + ot->poll = editable_grease_pencil_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc index b4fc52039ad..848e41fcac7 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc @@ -30,7 +30,10 @@ namespace blender::ed::greasepencil { bool grease_pencil_context_poll(bContext *C) { GreasePencil *grease_pencil = blender::ed::greasepencil::from_context(*C); - return grease_pencil != nullptr; + if (!grease_pencil || ID_IS_LINKED(grease_pencil)) { + return false; + } + return true; } bool active_grease_pencil_poll(bContext *C) @@ -61,6 +64,12 @@ bool editable_grease_pencil_poll(bContext *C) if (!ED_operator_object_active_editable_ex(C, object)) { return false; } + + const GreasePencil *grease_pencil = static_cast(object->data); + if (ID_IS_LINKED(grease_pencil)) { + return false; + } + return true; } @@ -71,12 +80,18 @@ bool editable_grease_pencil_with_region_view3d_poll(bContext *C) bool active_grease_pencil_layer_poll(bContext *C) { + if (!grease_pencil_context_poll(C)) { + return false; + } const GreasePencil *grease_pencil = blender::ed::greasepencil::from_context(*C); return grease_pencil && grease_pencil->has_active_layer(); } bool active_grease_pencil_layer_group_poll(bContext *C) { + if (!grease_pencil_context_poll(C)) { + return false; + } const GreasePencil *grease_pencil = blender::ed::greasepencil::from_context(*C); return grease_pencil && grease_pencil->has_active_group(); } diff --git a/source/blender/editors/interface/templates/interface_template_grease_pencil_layer_tree.cc b/source/blender/editors/interface/templates/interface_template_grease_pencil_layer_tree.cc index b89e85b8a2c..9d3f14df5b0 100644 --- a/source/blender/editors/interface/templates/interface_template_grease_pencil_layer_tree.cc +++ b/source/blender/editors/interface/templates/interface_template_grease_pencil_layer_tree.cc @@ -302,7 +302,11 @@ class LayerViewItem : public AbstractTreeViewItem { { uiBut *but = uiItemL_ex( &row, layer_.name().c_str(), ICON_OUTLINER_DATA_GP_LAYER, false, false); - if (!layer_.is_editable()) { + + if (ID_IS_LINKED(&grease_pencil_)) { + UI_but_flag_enable(but, UI_BUT_DISABLED); + } + else if (!layer_.is_editable()) { UI_but_disable(but, "Layer is locked or not visible"); } } @@ -465,7 +469,10 @@ class LayerGroupViewItem : public AbstractTreeViewItem { } uiBut *but = uiItemL_ex(&row, group_.name(), icon, false, false); - if (!group_.is_editable()) { + if (ID_IS_LINKED(&grease_pencil_)) { + UI_but_flag_enable(but, UI_BUT_DISABLED); + } + else if (!group_.is_editable()) { UI_but_disable(but, "Layer Group is locked or not visible"); } }