Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-10-08 20:56:24 +0300
committerJulian Eisel <julian@blender.org>2021-10-08 21:08:22 +0300
commit17c928e9752372b698a1ed27e243181873aa411e (patch)
tree7a1b088c4c83af65a603b79433b003f3cf344300 /source/blender/editors/interface/interface_handlers.c
parent7bd0de924080571f4c8308dc651b83539d6d22b8 (diff)
UI: Add context menu support for tree-view items
Tree-view items can now easily define their own context menu. This works by overriding the `ui::AbstractTreeViewItem::build_context_menu()` function. See the documentation: https://wiki.blender.org/wiki/Source/Interface/Views#Context_Menus Consistently with the Outliner and File Browser, the right-clicked item also gets activated. This makes sure the correct context is set for the operators and makes it clear to the user which item is operated on. An operator to rename the active item is also added, which is something you'd typically want to put in the context menu as well.
Diffstat (limited to 'source/blender/editors/interface/interface_handlers.c')
-rw-r--r--source/blender/editors/interface/interface_handlers.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index bf9b37c00fa..e1f8d18ce35 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -7961,6 +7961,14 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
/* handle menu */
if ((event->type == RIGHTMOUSE) && !IS_EVENT_MOD(event, shift, ctrl, alt, oskey) &&
(event->val == KM_PRESS)) {
+ /* For some button types that are typically representing entire sets of data, right-clicking
+ * to spawn the context menu should also activate the item. This makes it clear which item
+ * will be operated on.
+ * Apply the button immediately, so context menu polls get the right active item. */
+ if (ELEM(but->type, UI_BTYPE_TREEROW)) {
+ ui_apply_but(C, but->block, but, but->active, true);
+ }
+
/* RMB has two options now */
if (ui_popup_context_menu_for_button(C, but, event)) {
return WM_UI_HANDLER_BREAK;