From 7eda9d8dda59cd2bfebe665114447adc0a5ce778 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 8 Sep 2022 16:31:54 +0200 Subject: [PATCH] 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. --- .../editors/space_outliner/outliner_tools.cc | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc index c93622b7cfb..bab5b945d43 100644 --- a/source/blender/editors/space_outliner/outliner_tools.cc +++ b/source/blender/editors/space_outliner/outliner_tools.cc @@ -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");