Fix #137942: Grease Pencil: Make layer operators non-editable for linked data
For linked grease pencil data, layer operators are accessible right now. Grey out them in UI by adjusting poll functions. Also disabled the individual layer row of tree-view.` See images in PR description Pull Request: https://projects.blender.org/blender/blender/pulls/137946
This commit is contained in:
committed by
Pratik Borhade
parent
a4c91939e7
commit
afa4eaa96c
@@ -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):
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<GreasePencil *>(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();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user