Outliner: Hide "data operations" context menu entries unless supported

The context menu would always show a section with "Select", "Deselect",
"Hide", "Unhide" and "Select Linked" if there were no more specific
operators to show (e.g. modifier operations). For many tree elements
they did not make sense and simply would do nothing. Only show the
section for supported types.
This commit is contained in:
Julian Eisel 2022-09-08 16:31:54 +02:00
parent 8f6a38ed7e
commit 7eda9d8dda
Notes: blender-bot 2023-07-10 10:12:37 +02:00
Referenced by commit e254d8867d, Outliner: Hide library overrdies context menu when no IDs are selected
Referenced by commit 860c3dce1b, Outliner: Don't show asset context menu when no IDs are selected
Referenced by issue #104992, Regression: Crash when pressing F3 in outliner if no object is selected and Developer Extra is enabled
1 changed files with 24 additions and 3 deletions

View File

@ -3185,6 +3185,24 @@ void OUTLINER_OT_modifier_operation(wmOperatorType *ot)
/** \name Data Menu Operator
* \{ */
static bool outliner_data_operation_poll(bContext *C)
{
if (!ED_operator_outliner_active(C)) {
return false;
}
const SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
const TreeElement *te = get_target_element(space_outliner);
int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel);
return ELEM(datalevel,
TSE_POSE_CHANNEL,
TSE_BONE,
TSE_EBONE,
TSE_SEQUENCE,
TSE_GP_LAYER,
TSE_RNA_STRUCT);
}
static int outliner_data_operation_exec(bContext *C, wmOperator *op)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
@ -3295,7 +3313,7 @@ void OUTLINER_OT_data_operation(wmOperatorType *ot)
/* callbacks */
ot->invoke = WM_menu_invoke;
ot->exec = outliner_data_operation_exec;
ot->poll = outliner_operation_tree_element_poll;
ot->poll = outliner_data_operation_poll;
ot->flag = 0;
@ -3317,9 +3335,12 @@ static int outliner_operator_menu(bContext *C, const char *opname)
/* set this so the default execution context is the same as submenus */
uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_REGION_WIN);
uiItemsEnumO(layout, ot->idname, RNA_property_identifier(ot->prop));
uiItemS(layout);
if (WM_operator_poll(C, ot)) {
uiItemsEnumO(layout, ot->idname, RNA_property_identifier(ot->prop));
uiItemS(layout);
}
uiItemMContents(layout, "OUTLINER_MT_context_menu");