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/tree_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/tree_view.cc')
-rw-r--r--source/blender/editors/interface/tree_view.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc
index 3f66810b7f6..3f3a8c5bce5 100644
--- a/source/blender/editors/interface/tree_view.cc
+++ b/source/blender/editors/interface/tree_view.cc
@@ -369,6 +369,11 @@ bool AbstractTreeViewItem::rename(StringRefNull new_name)
return true;
}
+void AbstractTreeViewItem::build_context_menu(bContext & /*C*/, uiLayout & /*column*/) const
+{
+ /* No context menu by default. */
+}
+
void AbstractTreeViewItem::update_from_old(const AbstractTreeViewItem &old)
{
is_open_ = old.is_open_;
@@ -707,3 +712,11 @@ void UI_tree_view_item_begin_rename(uiTreeViewItemHandle *item_handle)
AbstractTreeViewItem &item = reinterpret_cast<AbstractTreeViewItem &>(*item_handle);
item.begin_renaming();
}
+
+void UI_tree_view_item_context_menu_build(bContext *C,
+ const uiTreeViewItemHandle *item_handle,
+ uiLayout *column)
+{
+ const AbstractTreeViewItem &item = reinterpret_cast<const AbstractTreeViewItem &>(*item_handle);
+ item.build_context_menu(*C, *column);
+}