UI: Add title to tree view context menus #120694

Merged
Pratik Borhade merged 9 commits from PratikPB2123/blender:bcol-ctxmenu-header into main 2024-06-05 11:28:55 +02:00
1 changed files with 3 additions and 3 deletions
Showing only changes of commit 297d4decb0 - Show all commits

View File

@ -6438,11 +6438,11 @@ std::string UI_but_string_get_label(uiBut &but)
std::string UI_but_context_menu_title_from_button(uiBut &but)
Review

but can be const.

`but` can be `const`.
Review

If we do this, we will also need to change "button parameter -> const" of few other functions. Example: UI_but_string_get_label, UI_but_string_get_rna_label, UI_but_operator_ptr_ensure and possibly few more.
Maybe best to do it outside of this PR to avoid the noise? 😅

or use const_cast?

If we do this, we will also need to change "button parameter -> const" of few other functions. Example: `UI_but_string_get_label`, `UI_but_string_get_rna_label`, `UI_but_operator_ptr_ensure` and possibly few more. Maybe best to do it outside of this PR to avoid the noise? 😅 or use `const_cast`?
{
if (but.type == UI_BTYPE_VIEW_ITEM) {
const uiButViewItem *view_item_but = static_cast<uiButViewItem *>(&but);
if (view_item_but == nullptr) {
const uiButViewItem &view_item_but = static_cast<const uiButViewItem &>(but);
const uiButViewItem &view_item_but = static_cast<const uiButViewItem &>(but);
```cpp const uiButViewItem &view_item_but = static_cast<const uiButViewItem &>(but); ```
if (view_item_but.view_item == nullptr) {

view_item should be null-checked. Can return an empty string in that case I guess.

`view_item` should be null-checked. Can return an empty string in that case I guess.
return "";
}
blender::ui::AbstractView &tree_view = view_item_but->view_item->get_view();
blender::ui::AbstractView &tree_view = view_item_but.view_item->get_view();

const

`const`
return IFACE_(tree_view.get_context_menu_title().c_str());
}
return UI_but_string_get_label(but);