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_view.cc
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_view.cc')
-rw-r--r--source/blender/editors/interface/interface_view.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_view.cc b/source/blender/editors/interface/interface_view.cc
index 8122b965892..fdd8eb0cc71 100644
--- a/source/blender/editors/interface/interface_view.cc
+++ b/source/blender/editors/interface/interface_view.cc
@@ -94,6 +94,16 @@ uiTreeViewItemHandle *UI_block_tree_view_find_item_at(const ARegion *region,
return tree_row_but->tree_item;
}
+uiTreeViewItemHandle *UI_block_tree_view_find_active_item(const ARegion *region)
+{
+ uiButTreeRow *tree_row_but = (uiButTreeRow *)ui_tree_row_find_active(region);
+ if (!tree_row_but) {
+ return nullptr;
+ }
+
+ return tree_row_but->tree_item;
+}
+
static StringRef ui_block_view_find_idname(const uiBlock &block, const AbstractTreeView &view)
{
/* First get the idname the of the view we're looking for. */