From 17c928e9752372b698a1ed27e243181873aa411e Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 8 Oct 2021 19:56:24 +0200 Subject: 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. --- source/blender/editors/include/UI_interface.h | 5 +++++ source/blender/editors/include/UI_tree_view.hh | 1 + 2 files changed, 6 insertions(+) (limited to 'source/blender/editors/include') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index c536eff771d..ddd5e77cbb6 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -2783,7 +2783,12 @@ char *UI_tree_view_item_drop_tooltip(const uiTreeViewItemHandle *item, bool UI_tree_view_item_can_rename(const uiTreeViewItemHandle *item_handle); void UI_tree_view_item_begin_rename(uiTreeViewItemHandle *item_handle); +void UI_tree_view_item_context_menu_build(struct bContext *C, + const uiTreeViewItemHandle *item, + uiLayout *column); + uiTreeViewItemHandle *UI_block_tree_view_find_item_at(const struct ARegion *region, int x, int y); +uiTreeViewItemHandle *UI_block_tree_view_find_active_item(const struct ARegion *region); #ifdef __cplusplus } diff --git a/source/blender/editors/include/UI_tree_view.hh b/source/blender/editors/include/UI_tree_view.hh index 272439a2ae9..ae85375ed2f 100644 --- a/source/blender/editors/include/UI_tree_view.hh +++ b/source/blender/editors/include/UI_tree_view.hh @@ -234,6 +234,7 @@ class AbstractTreeViewItem : public TreeViewItemContainer { virtual ~AbstractTreeViewItem() = default; virtual void build_row(uiLayout &row) = 0; + virtual void build_context_menu(bContext &C, uiLayout &column) const; virtual void on_activate(); /** -- cgit v1.2.3